Branch detection in green beans using reflection spectroscopy

Branch detection in green beans using reflection spectroscopy

Branch detection in green beans using reflection spectroscopy

Branch detection in green beans using reflection spectroscopy

Branch detection in green beans using reflection spectroscopy

We have already discussed the possibilities offered by near infrared spectroscopy (NIR) in the fruits and vegetables industry in one of our previous posts. Here, we present a practical case, where reflection spectroscopy is proposed as a method to identify branches among the green beans (Phaseolus vulgaris) and romano beans (Phaseolus coccineus).


Foreign bodies are any undesirable object found in food, from metal fragments to insects. They suppose a risk to the consumers and they can seriously damage a company’s reputation, being one of the main concerns of companies in the agrifood sector. X-ray inspection machines are a common solution for metallic foreign bodies but other methods must be used when this is not the case, and solutions based on spectroscopy or hyperspectral imaging systems are becoming increasingly popular.


In the case under study, it was desired to be able to detect branches (foreign bodies) in two different types of beans species with which the company The Real Green Food© works: round green beans (Phaseolus vulgaris) and flat romano beans (Phaseolus coccineus). Although distinguishing branches from beans can seem a trivial ask, it is not; as branches can have a similar size, shape and colour to beans, specially after being cut into pieces in the production line.


The employed method for distinguishing between branches and beans is based on direct reflection spectroscopy measurements obtained from the samples [1]. Here, the light reflected from the samples provides information about the sample surface properties and colour that can be used to discriminate between branches and beans. The optical setup, see Figure 1, consisted of an optical fiber reflectance probe, a TAKHI halogen light source from Pyroistech and two spectrometers, one in the visible range and the other in the infrared.


Optical measuring reflection setup. Branches detection in green beans
Figure 1. Optical measuring reflection setup.


Bean samples for both types of species under study were provided by The Real Green Food© from three different stages of the production line and measured using the setup shown in Figure 1. The first stage corresponds to the beans before the cleaning process, the second stage corresponds to the product after the cleaning and cutting process and the third stage corresponds to the beans after an additional scalding process.


Visible (400 – 900 nm) and near infrared (900 – 1700 nm) spectral data was collected from the samples (3778 samples) and was employed to train an artificial neural network (ANN) [2], one of the machine learning methods that is commonly used in spectroscopy, as we explained in one of our previous posts. The best results are obtained in the case of the third stage (beans after cleaning, cutting and scalding). The confusion matrices for this stage are shown below these lines, see Figure 2. The accuracy (total number of correct predictions divided by the number of predictions) is 1 for both flat and round beans using the visible spectral information. Regarding the NIR spectral information, the accuracy is 0.98 for the round beans and 0.99 for the flat beans. Concerning the other stages, the results are in general better with the visible spectral information (accuracies at least equal to 0.93) than with the NIR spectral information (accuracies at least equal to 0.92, except for the second stage and the flat beans, with an accuracy of 0.84).


Figure 2. Confusion matrices corresponding to the third stage (beans after cleaning, cutting and scalding), the one with the best results.


In conclusion, the obtained results permit to foresee the utilization of a versatile and fast sensing system to be used for branch detection in the production line and show a promising path for the employment of spectroscopy in the agrifood sector.




This work was supported in part by Gobierno de Navarra (G20001-G2100-4701-467300), the Ministry of Science, Innovation and Universities of Spain (PID2019-106231RB-I00) and the Institute of Smart Cities PhD Student grants. Also, we thank The Real Green Food© for their help.




[1] O’Farrell, M.; Lewis, E.; Flanagan, C.; Lyons, W.B.; Jackman, N. Using a Reflection-Based Optical Fibre System and Neural Networks to Evaluate the Quality of Food in a Large-Scale Industrial Oven. Sensors and Actuators A: Physical 2004, 115, 424–433, doi:10.1016/J.SNA.2004.04.051.


[2] Pan, L.; Zhang, P.; Daengngam, C.; Peng, S.; Chongcheawchamnan, M. A Review of Artificial Intelligence Methods Combined with Raman Spectroscopy to Identify the Composition of Substances. Journal of Raman Spectroscopy 2022, 53, 6–19, doi:10.1002/JRS.6225.


Subscribe To Our Newsletter

Get updates and learn from the best