## 2 Materials and Methods
### Detection Algorithm of Grape Clusters
#### 2.2.2 Construct Linear Classification Models Based on the Extracted Color Components  
To separate the grape clusters from background, four linear classification models were firstly established based on the extracted color components (H, Cb, b* and G&R). Among the four classification models, the H, Cb and b* classification models only relied on single channel, and the B&G classification models was related to two channels. These models could be thought as a simple threshold or linear operation on the color components value. To get the linear equations of these classification models more easily, we set \((x_{1},x_{2},\ldots x_{N})\) as the training sample sets, in which \(x_{i}\) denoted the \(i\)th training sample and \(N\) is the total number of samples. Then, the distribution of 1200 samples of pixel value on H, Cb, b*, B&G components were plotted to look for the ideal linear classification  
Figure 4: Several effective color components of images which can distinguish well the grape clusters from the background. (**a**) Original image; (**b**) H component image; (**c**) Cb component image; (**d**) b* component image; and (**e**) R-B component image.  
models, which was shown in Figure 5, the red dots represents grape and the blue dots represents background. The dividing lines equations of these classification models are uniformly defined by the euqation \(L_{c}(x_{i},p)=0\), in which \(c\) was the candidate color components, \(p\) were the threshold or equation parameters. By combining the threshold and linear classification principles, these dividing lines could be described by Equation (4):  
\[\left\{\begin{array}{c}L_{\text{H}}(x_{i},\ H_{th})=H(x_{i})-H_{th}\\ L_{\text{Cb}}(x_{i},Cp_{th})=Cb(x_{i})-Cp_{th}\\ L_{\text{b*}}(x_{i},Lab_{thth})=Lab_{pth}-Lab_{b(x_{i})}\\ L_{\text{B\&Rc}}(x_{i},a,b,c)=a*B(x_{i})+b*R(x_{i})+c\end{array}\right. \tag{4}\]  
In which the parameters of \(H_{th}\), \(Cb_{th}\), and \(Lab\_{th}\) indicated the optimal classification threshold of H, Cb and b*, respectively. \(H(x_{i})\), \(Cb(x_{i})\), \(Lab\_{b}(x_{i})\), \(B(x_{i})\) and \(G(x_{i})\) were the specialized color component values of the sample \(x_{i}\). \(a\), \(b\) and \(c\) were the parameters of the line equation of the \(B\&R\) classifier.  
Training the parameters in the Equation (4) was a very critical step for the linear classification models to separate the grape from background. To get the optimal parameters, the lowest classification error (\(LCE\)) method was employed in this study. The optimal parameters were searched by iterating the parameters among the range of the predefined value, which could minimize the error rate of the classification models. The \(LCE\) method could be described by Equation (5):  
\[LCE=arg\ min\left\{\sum_{i=1}^{N}T(x_{i})\right\}/N \tag{5}\]  
in which \(T(x_{i})\) was the sign function. When the \(x_{i}\) was misclassified by the specialized linear classification model, its value was 1, otherwise was 0.  
Figure 5: The distribution of average pixel value of 1200 samples on H, Cb, b*, B&R components and the corresponding dividing lines between grape and background (**a**) the dividing line H = 0.5736 and its \(LCE\) is 6.75%; **(b)** the dividing line Cb = 0.8405 and its \(LCE\) is 8.5%; **(c)** the dividing line b* = 0.1889 and its \(LCE\) is 12.08%; and **(d)** the dividing line B = 1.2 \(\times\) G \(-\) 0.05 and its \(LCE\) is 10.83%.  
Figure 5a-d show the distribution of average pixel value of 1200 samples on H, Cb, b*, B&R components and the corresponding dividing lines between grape and background were obtained by the \(LCE\) method.