Computer vision for purity, phenol, and pH detection of Luwak Coffee green bean

Computer vision as a non-invasive bio-sensing method provided opportunity to detect purity, total phenol, and pH in Luwak coffee green bean. This study aimed to obtain the best Artificial Neural Network (ANN) model to detect the percentage of purity, total phenol, and pH on Luwak coffee green bean by using color features (red-green-blue, gray, hue-saturation-value, hue-saturation-lightness, L*a*b*), and Haralick textural features with color co-occurrence matrix including entropy, energy, contrast, homogeneity, sum mean, variance, correlation, maximum probability, inverse difference moment, and cluster tendency. The best ANN structure was (5 inputs; 30 nodes in hidden layer 1; 40 nodes in hidden layer 2; and 3 outputs) which had training mean square error (MSE) of 0.0085 and validation MSE of 0.0442.


Introduction
In the last two decades, global coffee consumption growth has continued to grow, as driven by coffee-based products and beverage formulations and the increasing number of coffee shops [1]. One type of coffee, known to be expensive and rare in the world is Luwak (civet) coffee [2]. As a high-priced commodity, Luwak coffee is prone to be mixed with regular coffee beans. At present, an internationally recognized method of distinguishing Luwak and regular coffee, remains unnoticed. This, therefore gives the opportunity to design a simple, fast, accurate, and non-destructive equipment, capable of detecting the percentage of mixed portion between Luwak coffee and regular coffee. The study results of Jumhawan [3] found out that the tastes of roasted Luwak coffee and regular roasted coffee are citric acid and malic acid. Research on the Luwak coffee green bean has never been conducted, albeit about 75% of Indonesian coffee exports are in the form of green bean. In addition to detecting Luwak coffee mixtures in regular coffee, this study also measures total phenol as an antioxidant and pH to measure the coffee acidity. Coffee becomes a source of antioxidants to ward off free radicals that are beneficial for health. The largest antioxidant component in coffee is phenol [4,5]. At present, consumption of green bean extract becomes a new trend due to its low calorie content [6]. Measuring total phenol in green bean, helps measure the antioxidant activity. In addition, coffee has an acidic taste that is identical to its pH content. The trend of consuming green beans extract requires a study of pH, due to consumer sensitivity of coffee acidity, especially in arabica coffee. This research is utilized as one of the stages in designing tools for coffee inspection. Computer vision technology has been widely applied in identifying and copying coffee as an example of research as conducted by Oliveira [7], applying computer vision and computational intelligence to classify green bean coffee. The results show the performance of computer vision which achieves classification accuracy of up to 100%. Nansen [8] applied computer vision by using hyperspectral imaging to identify commercial roasted coffee brands based on their quality. Caporaso [9] detect moisture content in single green bean coffee by using computer vision. The results show optimal results for moisture content detection in single green bean coffee and successfully classify the types of coffee (Arabica and Robusta). Navarro [10] employed digital imaging technology to model the quality of coffee during the roasting process. The results present good performance in using a combination of digital imaging with adaptive network based fuzzy inference systems (ANFIS) to monitor coffee color during the roasting process. The use of artificial intelligent modeling such as artificial neural network (ANN) has been successfully applied in various coffee identification studies [11,12]. However, there have been no studies that have observed light computer vision and artificial intelligent modeling performance to identify the purity of green bean coffee for Luwak coffee type.
Image analysis is identified as a fast, non-destructive and low-cost method for assessing the quality of food products [13,14]. According to Patel [15], machine vision development is based on the inspection of the food quality and agricultural products, unfortunately faced several obstacles which later requires such an accurate, fast and objective technique in determining the quality of the measured material. This technology appears in the development of automated machinery in the agriculture and food industries [16]. Several studies [17][18][19][20] depict optimal results in machine vision application when using a combination of ANN modeling with color features (RGB, grey, HSL, HSV, L*a*b*) and Haralick textural feature [21].
In this study, the green bean image data as derived from a mixture of Luwak coffee and regular coffee are identified by using color features, such as: Red(RGB), Green(RGB), Blue(RGB), grey, Hue, Saturation(HSL), Lightness(HSL), Saturation(HSV), Value(HSV), L*, a*, b*, and textural features in each type of color (including entropy, energy, contrast, homogeneity, sum mean, variance, correlation, maximum probability, inverse different moment and cluster tendency). In addition, all the color and textural features in this study to select the best feature-subset combination are classified by using the feature selection method (filter method) before being used as input in ANN modeling. The selected color and textural features are then modeled by using ANN to estimate the percentage of pH, total phenol and purity of Luwak coffee with the lowest parameter value of Mean Square Error (MSE).

Research Method
This study utilizes green bean of arabica Luwak (civet) coffee and regular arabica coffee from Indonesian Plantation Company (PT Perkebunan Nusantara XII), Banyuwangi, Indonesia. Arabica Luwak coffee used in the research is Longan Luwak coffee. Regular arabica coffee is processed by using wet processing method. The tool for capturing pictures is digital camera (with specification of: Nikon Coolpix A10, 16 megapixels, Japan) placed in a black box, with the background of black surface, with constant fluorescent lighting and evenly distributed throughout the green bean coffee surface, and directly placed under a vertically mounted camera. The image data processing tool applies an Intel (R) Core (TM) i3 of 32 bit CPU computer 2.10 Ghz. Software used is by Windows 7 32 bit Operating System, with a self-built visual basic 6.0 based color and textural analysis software, equipped with Waikato Environment for Knowledge Analysis (WEKA) 3.8 [22], and with Matlab R2012a [23]. Green bean with a predetermined percentage, is placed on a platform with an area of 256 cm 2 . The image format used is a bitmap. The image acquisition design is depicted in Figure 1. This study utilizes the green bean of arabica Luwak coffee and regular arabica coffee as the research object. Each data collection is gathered by using 160 coffee beans, while calculating the percentage of the mixture is performed in unit of seeds. Mixed proportions consist of: 0%, 10%, 30%, 40%, 50%, 70%, 90%, and 100% of Luwak coffee as shown in Figure 2. Total phenol test was measured using the Folin Ciocalteu method [24]. The pH measurement was carried out on coffee extract using a pH meter.
The image is converted from RGB colour space to grey, HSL, HSV and L*a*b* colour spaces [25]. The result of feature extraction is the color co-occurrence matrix (CCM) in each color group (Red(RGB), Green(RGB), Blue(RGB), grey, Hue, Saturation(HSL), Lightness(HSL), Saturation(HSV), Value(HSV), L*, a*, and b*). AlQaisi [26] developed different methods used to extract texture features from a color image. Texture values extracted in each type of color based on Haralick's texture analysis. The results of image data acquisition produce the 120 color and textural features. Haralick's textural equations are as follows: where: P(i,j) is the (i,j) th element of a normalized co-occurrence matrix, and μ and σ are the mean and standard deviation of the pixel element given by the following relationships: where: N(i,j) is the number counts in the image with pixel intensity i followed by pixel intensity j at one pixel displacement to the left, and M is the total number of pixels.
ANN topology optimization is conducted by using Matlab R2012a software. The results of data acquisition of digital image processing methods obtaine 528 images at a predetermined percentage. Image data is divided into 66.67% as training data and 33.33% as validation data. The distribution of training data and validation data is the initial stage in ANN [27]. Training data is applied to update weights, biases and study data patterns. The accuracy of the model uses validation data to find out the ability of the network to identify new data patterns [28]. ANN modeling applies the backpropagation neural network (BPNN) algorithm, which is a popular algorithm, widely used in ANN [29,30]. Before performing ANN modeling, input and output data are normalized to range of -1 and 1.
Input layers include colors and textural features. The output layer expresses the percentage of purity, total phenol and pH in Luwak coffee. Designing the best ANN topology is accomplished through sensitivity analysis with a variety of learning functions; activation function; learning rate and momentum (0.1, 0.5, 0.9); hidden layer (1, 2); hidden layer node (10,20,30,40) with the lowest validation of MSE parameter. This study formulates the 3 activation functions i.e. purelin, tansig, and logsig [31].

Results and Analysis
The feature extraction results in 120 colors and textural features which represent information related to the image (a mixture of Luwak coffee and regular green bean in various percentages). The main problem emerges that not all color and textural features are capable of predicting dependent variable or objective function. This stage is intended to find out the features affecting either dependent variable or objective function. Feature selection is conducted by preprocessing data in data mining. Selection of features becomes an important stage to speed up the modeling process and to facilitate the design of tools. The main purpose of feature selection is to prevent overfitting, as characterized by high MSE validation; to reduce training time and to improve model accuracy [32][33][34]. The research results of the Karabulut [35] presented that feature selection might increase accuracy by 15.55% in ANN, Naive Bayes, and J48 Decision Tree modeling. This study employs 6 attribute evaluators, such as: Cfs Subset, Correlation Attribute, One R Attribute, ReliefF, Gain Ratio Attribute, and Gain Info Attribute. This 3077 study applies filter model to find out the feature selection. The filter model which is fast and simple, assesses relevant features by knowing the intrinsic nature of data. Filter method algorithms rank features based on their proximity to the class. The filter method has the advantages of being a fast and simple computing method [36,37]. The feature selection output for digital image data is in the top 10 rank for efficiency and simplification of ANN input. After obtaining the top 10 rank, the input data is then modeled by using ANN to select the input which produces the lowest MSE validation. ANN structures used are: the 40 nodes in 1 st hidden layer and 40 nodes in 2 nd hidden layer; activation function used in hidden layer and output layer was tansig; trainlm as learning function; learning rate of 0.1 and momentum of 0.9. Table 1 shows the Red(RGB) sum mean, which has a strong correlation with the percentage of regular coffee mixtures in Luwak coffee weighing of 0.23599. After obtaining the weights and ratings, the data in Table 1 are modeled by using ANN to find out features which can predict total phenol, pH, and the percentage of regular coffee mixes in Luwak coffee with the lowest MSE validation parameter. ANN output for digital image data feature selection in Table 2 shows that when the 120 color and textural features are used as ANN inputs, there is no value due to network errors. This is due to incompatibility of the trainlm learning function with the amount of input data. Thus, feature selection remains necessary to be performed.
The results of feature selection, present 5 data inputs correlating with the percentage of regular coffee mixes in Luwak coffee. The five data results from feature selection are labeled as texture features. Extraction of image features is based on CCM. The frequently applied conventional method in texture analysis is the gray level co-occurrence matrix (GLCM), which is a popular method for representing texture features as developed by Harralick. Figure 3 depicts the relationship of regular coffee mixture percentage in Luwak coffee with Red(RGB) sum mean. The results show that the Red(RGB) sum mean decreases along with the increasing percentage of Luwak coffee. The value of the textural feature Red(RGB) sum mean states the average number of red values in the image (the higher the value of Red(RGB) sum mean, the average number of reds in the textural feature will be greater). Figure 3 shows the textural feature Red(RGB) sum mean of 100% Luwak coffee was lower than 0% Luwak coffee. Figure 4 shows Value(HSV) sum mean in which the value decreases with the increase in the percentage of Luwak coffee. Textural feature Value(HSV) sum mean value states the average number of value in the image (the higher the value, the textural feature will be greater). The texture value states the amount of light received by the eye regardless of the color. This is in accordance with the color of Luwak coffee and regular coffee which can be observed visually. Luwak coffee used in the study has a darker color than in regular coffee, affecting the value sum mean to decrease along with the increase in the percentage of Luwak coffee. Figure 5 shows Saturation(HSL) sum mean in which the value decreases along with the increase in the percentage of Luwak coffee. Saturation(HSL) sum mean value states the average number of saturation value in the image (the higher the value, the greater the amount of saturation). Figure 6 shows Blue(RGB) variance which decreases with the increase in the percentage of Luwak coffee. Blue(RGB) variance shows variations in co-occurrence matrix elements. Images with small color degree transitions will have little variance. If the variance value is high, the degree of color of the image will spread. Variance is the sum of squares of differences in intensity among the neighboring pixels. Figure 6 shows that Luwak (civet) coffee green bean (100%) have a less diffused blue color, while green bean in Luwak coffee (0%) has a diffused blue color. Figure 7 shows the Hue variance which increases along with the increase in the percentage of Luwak coffee. From the graph, it is obvious that Luwak coffee (100%) has a more diffused Hue color than the Luwak coffee (0%).
ANN modeling produces predictive output, weight and bias which is optimal in estimating the percentage of purity, total phenol and pH. The most important step in designing ANN structure is the selection of optimal weights and biases among neurons with high generalizations [38]. The selected ANN struecture is presented in Figure 8. The initial stage in designing ANN structure is a training error of the learning function. Learning function plays a role in changing weights and biases during training. ANN modeling results consist of weights and biases that affect MSE validation. For this reason, a training error of the learning function is carried out. The research results of Sharma and Venugopulan [39] and Aggarwal and Rajendra [40] point out that the learning function influences ANN performance.  Figure 3. The relationship of Luwak coffee purity to red(RGB) sum mean    Table 3 presents trainlm as the selected learning function which produces the lowest MSE validation. Trainlm is a learning function that updates the weights and biases based on Lavenberg Marquadt optimization. Trainlm is categorized as the fastest algorithm and is recommended as the first supervision algorithm despite entailing more memory than other algorithms. Trainlm is proceeded by using Jacobian Matrix calculations, while network performance is measured from MSE. Trainlm is designed to have a two-level training speed, which is faster without calculating the Hessian matrix. After obtaining the best learning function that gives the lowest MSE validation, then training error is managed in the activation function as illustrated in Table 4.
The results of the training error show that the tansig function in the hidden layer and purelin in the output layer gives the lowest MSE validation. Purelin activation function is only used in the output layer. Purelin produces y=x, which cannot solve non-linear problems on hidden layer nodes. ANN model is identical to finding the relationship of non-linear data between input and output. For this reason, activation functions such as tansig and logsig are recommended in the hidden layer. Training error activation function is performed because it affects MSE validation. Research by Chang and Chung [41] shows that the results of the sensitivity analysis in the activation function, affect the performance of ANN in producing After obtaining the best activation function, ANN structure is further designed with a variety of learning rates, hidden layer nodes, and the number of hidden layers. Table 5 shows the best structure which is the 5-30-40-3 with learning rate of 0.1 and momentum of 0.5, which produces MSE validation of 0.0442. Determination of the number of hidden layer nodes and the number of hidden layers plays as the most important stage in designing ANN structure. The results show that two hidden layers can predict the output variable which is better than 1 hidden layer, due to the 2-hidden-layer ability to solve non-linear problems which is better than 1 hidden layer. However, more hidden layers hinder the computer running. Therefore, the hidden layer sensitivity analysis is needed. In this study, the maximum number of hidden layers is determined, as Karsoliya [42] stated that the 2-hidden-layers can solve non-linear problems. Sensitivity analysis of learning rate and momentum is required because both of these indicators play a role in changes of weight and bias during training.  Figure 9 shows three descriptions, which are: the blue line representing the training, the blue dashed line representing the best, and the black dashed line representing the goal. The training shows an iterative relationship to MSE during training. Figure 9 shows decreasing error along with increasing iteration due to the stable network ability to recognize data patterns. ANN is a "black box" modeling that is often used in dealing with non-linear problems. ANN has the ability to learn from iterations, which is widely used in various fields of science. The advantages of ANN are being able to adopt, study and generalize [43,44]. The advantages of ANN are also to quickly and accurately study data patterns compared to conventional  [45]. The blue dash line represents the best which shows the convergent network at iteration 9 and MSE of 0.008536. Figure 9 shows the network reaching the goal in iteration 9. The maximum number of iterations is 10,000 with a goal of 0.01, meaning that the training will stop at 10,000 iterations or when the goal has reached 0.01. MSE validation reaches 0.01 goal because the network is considered accurate in predicting the objective function or variable "y". Setting a MSE goal which is too small, results in overfitting the model. Determination of the number of iterations and goals are obligatory to avoid overfitting the model. Overfitting occurs when the model is very exclusive in recognizing training data patterns affecting the generalization to decrease, as indicated by the high MSE validation. Figure 9. Relationship of the number of iterations with MSE in the ANN training process for identification of Luwak (civet) coffee purity Figure 10 shows a regression plot which has the blue line marking a training simulation while the red line shows a validation simulation. In the regression plot, the data distribution training approaches the linear fit line which indicates the prediction is getting closer to the actual value, as notified from the training R value of 0.99052. The validation regression plot can be seen from the deviant data distribution points in linear fit, causing a low R validation. The value of R indicates the correlation between input and output variables. The closer it is to 1, the correlation becomes stronger. Based on the results of the research, the value of R approaches 1 indicating that the relationship of textural feature data, which are (Red(RGB) sum mean, Value(HSV) sum mean, Saturation(HSL) sum mean, Blue(RGB) variance, Hue variance) to the percentage of total phenol, pH, and Luwak (civet) coffee purity is very strong.

Conclusion
The detection results of the regular coffee mixes in Luwak (civet) coffee, total phenol and pH applying the digital images present that the 5 features of the image are selected as ANN inputs, which are: Red(RGB) sum mean, Value(HSV) sum mean, Saturation(HSL) sum mean, Blue(RGB) variance, and Hue variance by using the feature selection filter technique with the relief method. Image data using ANN produces selected structure of 5-30-40-3 (5 inputs, 30 nodes in 1 st hidden layer, 40 nodes in 2 nd hidden layer, 3 outputs) with a learning rate of 0.1 and momentum of 0.5 trainlm learning function, tansig activation function in hidden layer and purelin at the output layer. Selected ANN structure produces R training of 0.99502; R validation of 0.97933 and MSE training of 0.0085; and MSE validation of 0.0442. The results indicate that digital image processing and ANN model are potential to be a sensor in detecting the percentage of total phenol, pH, and Luwak coffee purity.