Mycotoxins are the toxic metabolites of certain filamentous fungi and have been demonstrated to cause various health problems in humans, including immunosuppression and cancer. Among them, the aflatoxins have received greater attention because they are potent carcinogens and are responsible for many human deaths per annum, mostly in non-industrialized countries. Various regulatory agencies have enforced limits on the concentrations of these toxins in foods and feeds involved in international commerce. Hyperspectral and multispectral imaging are becoming increasingly important for rapid and non-destructive testing for the presence of such contaminants. However, the high number of spectral bands needed may render such image acquisition systems too complex, expensive and slow. Moreover, they tend to generate overwhelming amount of data, making effective processing of this information in real time difficult. In this study, a two-dimensional local discriminant bases algorithm was developed to detect the location of the discriminative features in the multispectral data space. The algorithm identifies the optimal passband width and center frequencies of optical filters to be used for a multispectral imaging system. This was applied to a multispectral imaging system used to detect aflatoxin-contaminated hazelnut kernels and red chili peppers. Classification accuracies of 92.3% and 80% were achieved for aflatoxin-contaminated and uncontaminated hazelnuts and red chili peppers, respectively. The aflatoxin concentrations were decreased from 608 to 0.84 ppb for tested hazelnuts and from 38.26 to 22.85 ppb for red chili peppers by removal of the nuts/peppers that were classified as aflatoxin-contaminated. The algorithm was also used to classify fungal contaminated and uncontaminated hazelnut kernels, and an accuracy of 95.6% was achieved for this broader classification. (C) 2011 Elsevier B.V. All rights reserved.