Specialty coffee beans and standard coffee beans can be selected using multispectral imaging and artificial intelligence

Multispectral images based on reflectance and autofluorescence are processed using mathematical models. Credit: Winston Pinheiro Claro Gomes

The selection of specialty coffee beans involves three types of inspections. Two are physical and involve raw and roasted coffee samples. The third is sensory and involves tasting the drink. The certification is provided by the Specialty Coffee Association of America (SCAA).

According to SCAA guidelines, coffee quality is measured on a decimal scale from zero to 100. A specialty coffee must score 80 or more. The grower sends a sample of raw beans to three cuppers (tasters), who roast and brew coffee from each lot, always in accordance with SCAA standards, before issuing a report.

However, Brazilian researchers from the Center for Nuclear Energy in Agriculture at the University of Sao Paulo (CENA-USP), in collaboration with colleagues from the Luiz de Queiroz College of Agriculture (ESALQ-USP) and the University Computer Center Federal of Pernambuco (UFPE), have developed a method for selecting coffee beans based on multispectral imaging and machine learning. The method does not require roasting and can be performed in real time during the production process. It avoids possible human error, although it relies on expensive equipment. An article about the new method was recently published Computers and electronics in agriculture.

“Specialty coffee is often harvested selectively, which means that only ripe red cherries are harvested. They are picked individually by hand. If a specialty coffee farmer harvests green beans or at any time uses strips, manual and/or mechanized harvesting, this procedure can result in a regular commercial crop, says Winston Pinheiro Claro Gomes, first author of the paper. Gomes is a PhD student in chemistry at CENA-USP, supervised by Wanessa Melchert Mattos and Clíssia Barboza da Silva.

“In our method, we separate the considered special and commercial standard beans using a combination of multispectral image processing and mathematical algorithms that process the data from the images,” explained Gomes. “Specialty coffees must score between 80 and 100, but our model cannot tell whether the beans are 80 or 90. This would require machine learning with samples for each score to specify these categories in the mathematical model.”

Multispectral methodology

The team used a reflectance and autofluorescence-based multispectral imaging (MSI) technique, where images of the same object are acquired at different wavelengths, followed by a machine learning model to classify the beans based on the information gathered from the images.

“The use of MSI in the coffee industry is very new. It is mainly used to map nitrogen in coffee plantations, detect necrosis in beans and detect pests and diseases in plants, as shown in the literature on the subject,” says Gomes.

The researchers analyzed 16 green bean samples from standard specialty and commercial crops grown in the states of Minas Gerais and São Paulo. Ten of the specialty coffee beans (Coffea arabica) came from the 2016/17 harvest grown in the Alta Mogiana region. They had been evaluated in the Alta Mogiana Coffee Contest 2017 and were provided by the regional association of specialty coffee producers. The other six samples were taken from commercial standard crops purchased in bulk from the local market.

For each sample, 64 untreated beans were randomly separated, for a total of 1,024 beans (384 standard, 640 special) and used for calibration, validation, and machine learning testing.

Gomes summarized the procedure as follows: “We put the beans in a petri dish and inserted it into the device, which is a sphere containing LEDs, optical filters and a camera. The camera descended on the samples until they were completely covered and captured the images after homogeneous and diffuse illumination at different wavelengths, first taking monochrome images in reflectance and then images in autofluorescence, after which the related information as the regions of interest were extracted from on-board software and used to building the algorithms that classified the samples and gave us the results.”

Principal component analysis (PCA) was then performed to study the variables influencing the differences between specialty coffee and standard coffee. The researchers ran four machine learning algorithms, with the support vector machine (SVM) being the best and used to calculate coefficients to estimate key variables.


Specialty beans were more uniform in shape in visible spectrum (RGB) images, whereas standard beans were more intense in autofluorescence images.

“Our mathematical model and algorithms use information about signal strength from the fluorescence images. It may happen that some compounds present in beans are more excited at a certain wavelength. A more or less intense fluorescence signal can also be related to the change in the concentration of a compound in beans, for example, says Gomes.

“The model we chose was the one that performed best in differentiating between specialty coffee and standard beans. In this model, the most important information for the construction of the separation limits came from green fluorescence. We therefore decided to analyze the individual compounds that naturally show a green fluorescence and I tried to associate some fluorescent compounds that could affect the separation process of the coffee grading”.

Green fluorescence, a biological marker represented by green light in the visible spectrum, was analyzed for 10 phenolic compounds and the data showed that catechin, caffeine and some acids (4-hydroxybenzoic acid, sinapinic acid and chlorogenic acid) responded strongly after being excited with blue light at 405 nanometers (nm), emits energy at 500 nm. This autofluorescence data (excitation/emission at 405/500 nm) was most helpful in distinguishing special green beans from common green beans.

“These are chemical species associated with aromatic groups that absorb energy relative to a specific wavelength. In autofluorescence-based methods, variations in the levels of these chemical species in specialty and standard coffee grades can be used to distinguish between the two groups,” says Gomes.

Differences in the levels of these compounds are commonly used to differentiate between specialty coffee beans and standard coffee beans. “For my master’s research, I studied the chemical composition of these samples, and although there were no differences in chemical species, we found variations in their concentrations, particularly the levels of chlorogenic acid and caffeine,” he said.

The next steps, according to Gomes, will involve taking samples from each of the SCAA-defined specialty coffee score levels (not an easy task) and grading the beans based on their score. “In Brazil, coffee has the highest rating of 90-92. It’s hard to find more. Only imported coffee, from, for example, Ethiopia, gets a score of 100. In my doctoral research, I am trying to classify beans based on X-ray images, and I have decided to increase the number of samples and the breadth of the analysis including imported beans, he said.

Leave a Comment