Aflatoxins are the toxic metabolites of Aspergillus molds, especially by Aspergillus flavus and Aspergillus parasiticus. They have been studied extensively because of being associated with various chronic and acute diseases especially immunosuppression and cancer. Aflatoxin occurrence is influenced by certain environmental conditions such as drought seasons and agronomic practices. Chili pepper may also be contaminated by aflatoxins during harvesting, production and storage. Aflatoxin detection based on chemical methods is fairly accurate. However, they are time consuming, expensive and destructive. We use hyperspectral imaging as an alternative for detection of such contaminants in a rapid and nondestructive manner. In order to classify aflatoxin contaminated chili peppers from uncontaminated ones, a compact machine vision system based on hyperspectral imaging and machine learning is proposed. In this study, both UV and Halogen excitations are used. Energy values of individual spectral bands and also difference images of consecutive spectral bands were utilized as feature vectors. Another set of features were extracted from those features by applying quantization on the histogram of the images. Significant features were selected based on proposed method of hierarchical bottleneck backward elimination (HBBE), Guyon's SVM-RFE, classical Fisher discrimination power and Principal Component Analysis (PCA). Multi layer perceptrons (MLPs) and linear discriminant analysis (LDA) were used as the classifiers. It was observed that with the proposed features and selection methods, robust and higher classification performance was achieved with fewer numbers of spectral bands enabling the design of simpler machine vision systems. (C) 2012 Elsevier B.V. All rights reserved.