Chili Classification Using Shape and Color Features Based on Image Processing

. Purpose: Chili is an agricultural product that has several varieties and is in great demand. It can be consumed directly or processed first. This study aims to classify the types of chili using color and shape features. The types of chili are divided into five classes: cayenne pepper, green chili, big green chili, big red chili, and curly chili. The chili classification method was evaluated using three parameters: precision, recall, and accuracy. Methods: This study applied the K-Nearest Neighbors (KNN) method with the Euclidean and Manhattan distance calculation algorithm and used two feature types: color and shape. The color features were extracted based on RGB color space by obtaining the mean and standard deviation values. Meanwhile, the shape features used aspect ratio, area, and boundary. Result: The evaluation results of the classification method were able to achieve the precision, recall, and accuracy values of 1.0, which means that all test data were classified correctly. The evaluation was applied with 210 training images and 90 test images based on the test results. Novelty: This study extracted two types of features: color and shape. Those features fed the KNN method by applying the Euclidean and Manhattan distance calculation algorithm; hence, the optimal results were achieved.

Subsequently, feature extraction was carried out to provide feature values differentiating between different objects. Appropriate features can result in the highest possible accuracy in recognizing an object [22]. Feature extraction has been used to identify fruit plants based on leaf shape, color, and texture [23], and apple maturity level classification [2], [20]. In the final stage, classification was used to determine the type of object that was being considered. There were several commonly classification methods employed: decision tree [1], SVM [2], [6], artificial neural networks [23], [24], and KNN [25], [26].
The KNN classification approach was successfully used to determine blueberry fruit maturity. The fruit was classified into four phases of maturity: mature, near-mature, near-young, and young. The color component analysis-based detection (CCAD) approach is a stepwise algorithm. Three color components, red, blue, and hue, were chosen using the forward feature selection algorithm (FFSA) and utilized to classify all fruit at four stages of ripeness. This technique had the highest classification accuracy (85%-98%) [25]. In addition, the blueberry's maturity was classified into three distinct growth stages: mature, intermediate, and young. A fruit training set was created by patching together 1374 color images. To exclude non-fruit regions, histogram-oriented gradients (HOG) feature vectors were constructed based on a* and b* features in the L*a*b* color space. The KNN and Template Matching with Weighted Euclidean Distance (TMWE) classifiers recognized the fruit maturity. The performance of the approach was determined using the average detection accuracy on the testing images, the missed rate, and the inaccurate detection rate of false positives. For immature, intermediate, and mature fruit, the KNN classifier achieved the highest average accuracy of 86.0%, 94.2%, and 96.0%, respectively [26].
Based on the previous studies, the chili classification method was developed using color and shape features with the KNN classifier and image processing approach in this study. This method included five classes, namely cayenne pepper, green chili, big green chili, big red chili, and curly chili. Both features were required to obtain the discriminatory and powerful features to improve the method performance because visually, the chilies can differentiate based on their color and shape. The color features were extracted in RGB color space.

METHODS
The proposed method was intended to classify chile types based on color and shape features. There were six main processes: image acquisition, region of interest (ROI) detection, pre-processing, segmentation, feature extraction, and classification. The input data was chili images classified into five classes: big red chilies, big green chilies, curly chilies, green chilies, and cayenne peppers, respectively. Fig. 1 depicts an overview of the main process of the chili classification method, which is based on shape and color features.

Image Acquisition
In this study, the image acquisition was carried out using several types of equipment: a studio minibox, a LED strip light with a power of 220 V and a distance of ±27 cm, and a Redmi 8 smartphone camera with a resolution of 48 Megapixels, also a tripod. The studio minibox has a height, length, and width of 27 × 27 × 23 cm. The chili was placed in the center of the studio minibox with a white background. The camera was on a tripod and set to face the object with a 45 o tilt. The distance between the studio minibox and the camera was ±20 cm.
The chili images obtained from the acquisition consist of five types, namely big red chilies, big green chilies, curly, green, and cayenne peppers. The resulting image was 4000 × 1844 pixels saved in JPEG format. The total number of acquired images is 300 images consisting of 50 images of large red chilies, 50 images of large green chilies, 50 images of curly chilies, 50 images of green chilies, and 100 images of cayenne pepper. Those images were captured from 150 chilies. The illustrations of image acquisition scenarios and resulting images of acquisition from five types of chili are shown in Figure 2.

ROI Detection
This process was needed to form a sub-image containing most of the chili area; therefore, the image size became smaller, reducing the computation time. This process began by resizing 0.5 of the initial image with a size of 4000 × 1844 pixels into 2000 × 922 pixels. Furthermore, thresholding with the Otsu method [7] was applied to estimate the chili area. The resulting thresholding image was used as a reference to generate the boundary chili area to form the ROI images. The resulting image of each step in the ROI detection process is shown in Figure 3.

Pre-processing
Pre-processing is intended to provide a suitable image, resulting in a more appropriate result for the subsequent processing step(s). The ROI images were used as input for this process. This study was employed in the pre-processing stage by converting the RGB to the HSV color space. In order to proceed with the following process, it was necessary to transform the HSV image to a grayscale image based on each channel in the HSV color space. Figure 4 depicts the image created as a result of each step in this process. anothercond. (2)

Segmentation
The segmentation aims to distinguish the chili area and the background. The features were extracted only from the chili area in the following process. The input of this process was a grayscale image based on the HSV color space from the prior process. Initially, the segmentation carried out thresholding using the Otsu method [7], [27]. The resulting binary image of thresholding may contain noise; therefore, the implementation of a morphological operation, namely opening, was required. The optimal segmentation result was generated based on the S channel than the H and V channels. The comparison of the segmentation results of the H, S, and V channels is shown in Figure 5.

Feature Extraction
The nine features were extracted based on color and shape in this study. The color features used consisted of the mean (μ) and standard deviation (σ). These features were extracted based on each channel of the RGB color space; hence, six color features were obtained. The value of each color feature is generated using equations (4) and (5) [22]: where M and N are the image sizes, is the pixel value in column i and row j, and ̅ is the average value. Meanwhile, the shape features used are aspect ratio, area, and boundary. The explanation of each shape feature is as follows:

Aspect Ratio
This feature is the ratio of the length of the W axis (minor axis) to the L axis (major axis). The illustration of the aspect ratio calculation is presented in Figure 6(a), and the equation used is as follows:

Area
The area feature (A) is generated by counting the number of white pixels that indicate the chili area. The white pixels constituting the chili area are shown in Figure 6(b).

Boundary
The boundary features were generated by comparing the number of white pixels of the chili edge area and the total number of pixels in the image. Figure 6(c) shows the white pixel that represents the chili's edge. The examples of feature extraction results from five types of chili, namely, big red chili, big green chili, curly chili, green chili, and cayenne chili, are shown in Table 1.

Classification
The classification method is employed to determine the class of an input image. The K-Nearest Neighbor (K-NN)method is utilized in conjunction with three distance calculation algorithms, namely the Euclidean, Manhattan, and Mahalanobis distance calculation algorithms, to classify the data in this study. The K-NN technique is a classification system for objects, mainly images [27]. KNN is a popular machine learning and supervised learning algorithm due to its simplicity and ease of usage. KNN has a high level of accuracy when it comes to classification and regression. The KNN's main role is to determine the distance between new testing data and training data, followed by classification using the classifier. The following are some popular distance calculations using the Euclidean, Manhattan, and Mahalanobis distances [27]: x : training data y : testing data i : a total of neighbor n : total pixels image The stages of KNN are defined as following [27]: 1. Define the total number of K, which will be used as a reference for the nearest class. 2. Calculate the difference between the training and testing sets of data. 3. Sorting and determining the nearest-neighbor distance using the K value as a reference distance. 4. Examine the output or labels for each adjacent class. 5. Classify testing images into the majority of the nearest class.

RESULT AND DISCUSSION
The evaluation was carried out to determine the suitability of the combination between the distance calculation algorithm and the value of k in the chili type classification method developed to obtain optimal performance. This method performs a classification divided into five classes of chili species. In this study, the performance of the chili classification method was measured using four parameters, namely precision, recall, accuracy, and F1score. These parameters have a minimum value of 0 and a maximum value of 1. The proposed method indicated has high performance while the values of the evaluation parameters are close to or equal to 1. The precision, recall, accuracy, and F1score values are calculated using equations (10) -(13) [28]: The P-value is obtained based on a multi-class confusion matrix [29] which consists of five classes, namely big red chili (C1), big green chili (C2), curly chili (C3), green chili (C4), and cayenne pepper (C5). The confusion matrix in this study is shown in Table 2.
The chili classification method test was carried out using 300 chili images consisting of 50 large red chili images, 50 large green chili images, 50 curly chili images, 50 green chili images, and 100 cayenne pepper images. The image data was divided into 70% training data (210 images) and 30% testing data (90 images).
The method was carried out using three distance calculation algorithms, namely Euclidean, Manhattan, and Mahalanobis, and the variety of k values consists of 1, 3, 5, 7, and 9. The method's performance was evaluated based on four parameters, namely precision, recall, accuracy, and F1score. The evaluation results of the proposed method are summarized in Table 3.  Table 3 shows the Euclidean and Manhattan distance calculation algorithms with k values of 1 and 3 were the most appropriate distance algorithms for the chili image dataset utilized in this study. Precision, recall, accuracy, and F1score were improved with the approach of the distance algorithms and the appropriate value of k.
The chili classification result consisting of five classes achieved the value precision, recall, accuracy, and F1score of 1.0 in this study. Thus, it concluded that there was no misclassification occurred. The proposed method implemented the color and shape features, where the color features were obtained from each channel of RGB color space. The method performance was obtained, representing the adequacy in selecting classification methods, particularly concerning the distance calculation algorithm and determination of the value of k, which impacts the results (Euclidean and Manhattan algorithms, with k values of 1 and 3). The aspects such as the applicability of the features employed were also essential considerations. Color and shape were the features used in this study, and these features were capable of distinguishing five different types of chili. The more training data the algorithm is utilized to, the more it learns. Therefore, the chili classification method's high performance was capable of achieving.

CONCLUSION
This study proposed a chili classification method consisting of five classes: big red chilies, big green chilies, curly chilies, green chilies, and cayenne peppers. It consists of six main processes: image acquisition, ROI detection, pre-processing, segmentation, feature extraction, and classification. A total of 300 chili images (generated from 150 chilies) were obtained during the image acquisition. Those images were used as both training and testing data. Otsu method was used to detect and segment the chili area based on the S channel of HSV color space. Subsequently, features extraction was applied based on color and shape. The color features were produced from each channel in the RGB color space. Meanwhile, the shape features extraction were generated the aspect ratio, the area, and the boundary. Hence, a total of nine features were produced in this method. Furthermore, the KNN method was used in the classification process by applying the distance computations using the Euclidean and Manhattan algorithms, with k values of 1 and 3. This method successfully achieved a maximum F1Score value of 1.0 that indicates no misclassification occurred. Based on the experiment, the proposed method is appropriate for the dataset used in this study.