## 2 Materials and Methods
### Tomato Leaf Image Segmentation Using the HSV Color Space  
HSV is more meaningfully related to the psychological perception of color than RGB. Therefore, an HSV color space can separate color information from intensity or lighting. In addition, a histogram can be constructed for choosing a thresholding rule using only saturation (\(S\)) or hue (\(H\)). In practice, it is just a nice improvement that even by singling out only the hue, it still has a very meaningful representation of the base color that is much better when compared with RGB. As a result, there is more robust color thresholding over simpler parameters using the HSV color space.  
For segmentation to extract leaf regions and the black backgrounds of all images, HSV of all leaf images can be uniformed perceptually, and all components of images can be quantized with the same precision. In particular, the HSV is a three-dimensional cartesian coordinate system, and its brightness values (\(V\)) can vary from 0 to 1. The hue (\(H\)) means that its color can range from 0 to 360 degrees, in which 0 or 360 degrees is red, 60 degrees of 60, 120, 180, 240, and 300 correspond to the colors of yellow, green, cyan, blue, and magenta, respectively. The saturation (\(S\)) defines the white color and is mixed with \(H\) to produce different colors represented by the percentage of the range from 0 to 1. The 1 means a pure color such as red, green, or blue. One image in the RGB color space can be transformed to the HSV using the following equations [46]:  
\[H(x,y)=\left\{\begin{aligned} 0^{o},\ if\ \text{$\Delta=0$}\\ 60^{o}.\Big{(}\frac{G^{\prime}(x,y)-B^{\prime}(x,y)}{\Delta} \text{mod}6\Big{)},\ if\ \text{$T_{\text{max}}=R^{\prime}(x,y)$}\\ 60^{o}.\Big{(}\frac{B^{\prime}(x,y)-B^{\prime}(x,y)}{\Delta}+2 \Big{)},\ if\ \text{$T_{\text{max}}=G^{\prime}(x,y)$}\\ 60^{o}.\Big{(}\frac{R^{\prime}(x,y)-G^{\prime}(x,y)}{\Delta}+4 \Big{)},\ if\ \text{$T_{\text{max}}=B^{\prime}(x,y)$}\end{aligned}\right. \tag{1}\]  
\[S(x,y)=\left\{\begin{aligned} 0,\ if\ \text{$T_{\text{max}}=0$}\\ \frac{\Delta}{\text{$T_{\text{max}}$}},\ if\ \text{$T_{\text{max}}\
eq 0$} \end{aligned}\right. \tag{2}\]  
\[V(x,y)=T_{\text{max}} \tag{3}\]  
in which, \(R^{\prime}(x,y)=\frac{R(x,y)}{255}\), \(G^{\prime}(x,y)=\frac{G(x,y)}{255}\), \(B^{\prime}(x,y)=\frac{B(x,y)}{255}\), \(T_{\text{max}}=\text{max}(R^{\prime}(x,y)\), \(G^{\prime}(x,y)\), \(B^{\prime}(x,y))\), \(T_{\text{min}}=\text{min}(R^{\prime}(x,y)\), \(G^{\prime}(x,y)\), \(B^{\prime}(x,y))\), and \(\Delta=T_{\text{max}}-T_{\text{min}}\).  
For the segmentation to extract leaf regions and to create the black backgrounds of all original RGB images, the algorithm is described as follows:  
* **Step 1**: The RGB image is converted into the image with the HSV color space. The HSV components (three sub-images) can easily distinguish colors related to the type of color, the shade of color, the purity of color, or the brightness of color.
* **Step 2**: Histograms for all three HSV components are plotted to choose their lower and upper threshold values.
* **Step 3**: Masking is to segment and convert the HSV images to binary images based on the histogram HSV thresholds before extracting the leaf region. Therefore, we can fill holes in one binary image to create a leaf mask using the morphological operation.  
Figure 1: Proposed model for classifying tomato leaf disease and classification accuracy evaluation.  
* **Step 4**: The white mask can map to the RGB image for collecting the original leaf region and the black background.