The market demand for gluten-free food is increasing due to the growing gluten sensitivity and coeliac disease (CD) in the population. The market requires grass-free cereals to produce gluten-free food. This requires sorting methods that guarantee the perfect separation of gluten contaminants from the legumes. The objective of the research was the development of an optical sorting system based on hyperspectral image processing, capable of identifying the spectral characteristics of the products under investigation to obtain a statistical classifier capable of enabling the total elimination of contaminants. The construction of the statistical classifier yielded excellent results, with a 100% correct classification rate of the contaminants. Tests conducted subsequently on an industrial optical sorter validated the result of the preliminary tests. In fact, the application of the developed classifier was able to correctly select the contaminants from the mass of legumes with a correct classification percentage of 100%. A small proportion of legumes was misclassified as contaminants, but this did not affect the scope of the work. Further studies will aim to reduce even this small share of waste with investigations into optimising the seed transport systems of the optical sorter.