Development of Novel Autoclassifying System Based on Machine Vision

In this paper, we present a novel machine-vision-based autoclassifying system for peaberry (PB) and flat beans (FB) of coffee. The system comprises an inlet–outlet mechanism, machinevision hardware and software, and a control system for classifying coffee. The proposed method can estimate the shape features of coffee beans, provided as input neurons of neural networks, and accordingly classify coffee beans as PB and FB. Experiments yielded classification accuracy levels of 96.97 and 95.22% for PB and FB, respectively, indicating that PB and FB can be classified efficiently using the proposed system.


Introduction
Coffee is a popular crop worldwide and is cultivated all year round. On the basis of their shape, coffee beans can be classified into two types: peaberry (PB) and flat beans (FB) (Fig. 1). PB is more expensive than FB because it has a lower yield than FB. PB continues to be sorted manually worldwide, the high economic and time costs of which affect the income of coffee farmers. Image processing is a powerful and widely used method for classifying agricultural products. Xu and Zhao developed an autograding system for grading strawberries on the basis of their shape, size, and color features. (1) Wiwart et al. proposed a classification method using principal component analysis to identify wheat varieties on the basis of shape and color features. (2) Carillo et al. established a classifier using the Mahalanobis distance method for detecting defective coffee beans. (3) Faridah et al. extracted the texture features (energy, entropy, contrast, and homogeneity) and color features (red, green, and blue gray levels) for classifying seven types of coffee beans by using a backpropagation neural network (BPNN). (4) Tanabata et al. developed a software system to detect seed shapes by using a scanner to capture images of rice grains. (5) ElMasry et al. designed a fast and accurate machine-vision system for detecting potatoes. (6) Huang used Rayleigh transform and image processing for extracting the features of disease spots in Phalaenopsis seedlings and then applied a Bayes classifier for detecting and classifying the diseases. (7) Wang et al. established a neural network (NN) classifier for detecting chilling injury in apples by capturing hyperspectral images and reported a classification accuracy of 98.4%. (8) Huang presented a novel application using image processing and a detection line method for evaluating and classifying the quality of areca nuts. (9) Chen et al. used NNs and machine vision for classifying the quality of moldy peanuts on the basis of the hue, saturation, and intensity (HSI) color model and entropy. (10) Hsiao et al.
proposed the best-fit line detection, region of interest (ROI) detection conversion, and the precision measuring method to extract the irregular edge of an object. (11) No studies in the literature have yet examined the classification of PB and FB coffee. Therefore, in this study, we designed a novel autosorting system for classifying PB and FB; the technical objective was to develop an algorithm for extracting the shape features of coffee beans and to subsequently classify the beans on the basis of the aforementioned features.

Image capture system and experimental samples
The image capture system developed in this study comprises a USB charge-coupled device (CCD) camera (DFK-21BU04, Imaging Source), a lens (ML-0813 MORITEX), a DIY LED, and a computer (Intel Core i7-2600 CPU, 3.4 GHz, 2.78 GB RAM), using which RGB color images measuring 640 × 480 pixels (field of view = 40 × 40 mm 2 ) were captured and stored in bitmap format. The image processing software was developed in Visual Basic 6.0 and Matrox Imaging Library (MIL) 8.0. The coffee beans were provided by Kuoshing Coffee grounds (Kuoshing Country, NanTou, Taiwan).

Machine-vision system
The machine-vision system implemented in this study comprises a vibration device, a rotation disk, an outlet device, an image-capture system, a collection box, a programmable controller (PC), and a programmable logic controller (PLC; Fig. 2). First, the beans were sucked into the rotation disk through the vibration device by a suction device under the rotation disk. Images of the beans were captured using the CCD camera and sorted using the proposed algorithms. Second, the beans were blown into the appropriate collection box in accordance with the sorting result.

Bean-image segmentation
After the features of the beans have been extracted, the bean image must be segmented through histogram equalization, binary, erosion, dilation, and hole-filling operations (12) in order to remove noise and to fill holes in the bean image, thereby obtaining the entire binary image. Thus, the image of the entire seed can be obtained using the logic operation AND, as shown in Fig. 3.

Feature extraction
Shape-feature analyses have been employed extensively for classification. Because shape is a reliable indicator of the coffee-bean type, the following shape features were considered in this study; lengths of the principal and secondary axes, axial ratio, area, perimeter, compactness, symmetric Fourier index bounding rectangle area ratio, bounding circle area ratio, and width ratios (Fig. 4). The mathematical formulations and definitions of these shape features are as follows: (1) The principal axis (L p ) is the longest line segment on the bean contour.
(2) The secondary axis (L s ) is the perpendicular bisector of L s .  (9) Symmetric Fourier index (SFI) (13,14) is computed using the Fourier description coefficients (a n , b n , c n , and d n ) of a chain-encoded contour, where the Fourier coefficients correspond to the nth harmonic (Fig. 6).
The aforementioned shape features were employed to classify coffee beans by using BPNNs. (15) The BPNN classifier comprises three layers; an input layer, a hidden layer, and an output layer. The input layer has 11 nodes related to the 11 shape features, normalized between 0 and 1, and the output layer is composed of nodes related to two categories-PB and FB (Fig. 7). The hidden layer comprises nodes related to two categories: defect and nondefect. Initially, the number of nodes n h in the hidden layer is calculated as where n i is the number of input nodes and n o is the number of output nodes. The objective of the learning process is to detect a relationship in the patterns made by the shape features of each bean. Subsequently, the NN is trained, and the weights are changed until the error convergence criterion is 0.016.

Results and Discussion
In this study, 1486 PB and 1413 FB training samples were used to train the BPNN classifier, and the fabricated device (Fig. 8) was tested using 2972 PB and 2766 FB. The experimental results yielded a classification accuracy of 96.97 and 95.22% for PB and FB, respectively (average = 96.18%; Table 1). A few images could not be classified using the proposed algorithms, as detailed in Table 2.
Overall, the proposed system can accurately and efficiently autoclassify PB and FB. In the future, this autosorting system can be improved to detect other beans.

Conclusions
In this study, we developed a novel machine-vision-based system for classifying PB and FB of coffee. The shape features of the coffee beans were obtained to establish a BPNN classifier. The test results show that the PB and FB of coffee can be classified efficiently by this method. In a future study, we intend to further refine the classification algorithm or use other classifiers to increase the accuracy of coffee bean classification.