# Segmentation of Rice Seedings Using the YCrCb Color Space and an Improved Otsu Method
## 2 Materials and Methods
### Improved Otsu Method for Rice Seeding Segmentation
#### 2.5.2 Improvement to the Otsu Method  
Aiming at automatically selecting the desired threshold for both bimodal and unimodal images, the neighborhood valley-emphasis (NVE) method [26] is a modified form of the Otsu method which selects a threshold that has a small probability of occurrence by adding a weight to the between-class variance. The weight is obtained from neighborhood information around the valley point in the gray-level histogram. Figure 8A shows a rice seedling image. The rice seedling is small compared with the size of the background. The corresponding image histogram shown in Figure 8B is a near-unimodal distribution. Unlike Otsu's threshold, which is located towards the class with the largest variance, the NVE's threshold is located at the right rim of the histogram, which results in almost all rice seedlings being wrongly segmented as the background. This means that the NVE method performs well when the histogram of images has enough valley information. However, in rice seedling images, most of the rice seedling area, in which the seedlings have just been transplanted by a rice transplanter, is much smaller than the background area in paddy fields. The images do not have enough valley information in this case. Therefore, the NVE method, which uses valley neighborhood information as the weight, still cannot improve the segmentation equality of rice seedlings. In this subsection, we propose an improvement to the Otsu method by adding a weight parameter to the within-class variance. The details of the improved Otsu method are described as follows. The within-class variance of the Otsu method defined as Equation (11) contains two classes. Let the first item \(P_{1}(t)\sigma_{1}^{2}(t)\) denote the background variance and the second item \(P_{2}(t)\sigma_{2}^{2}(t)\) be the rice seedling variance. According to [25], the background class in the rice seedling image mainly determines the desired threshold. To obtain a desired threshold, the first item should contribute less to the within-class variance. In this regard, the parameter \(\alpha\), ranging from 0 to 1, is introduced to weight the first item. Now, the weighted background variance is \(\alpha\) times the original background variance, which influences the within-class variance. Using \(\alpha\), Equation (11) can be modified as:  
\[\sigma_{w}^{2}(t)=\alpha P_{1}(t)\sigma_{1}^{2}(t)+P_{2}(t)\sigma_{2}^{2}(t). \tag{13}\]  
Figure 7: Sample location in the selection of [PERSON]’s threshold for (**A**) valley and (**B**) single peak histogram. From the analysis of the Otsu algorithm in [25], the weight \(\alpha\) should be selected to be close to 0 because the rice seedling variance is close to 0 in the case of an image with small seedlings, while \(\alpha\) can be set as a larger value for the rice seedling image. It is worth noting that the random or fixed weight value for \(\alpha\) is not suitable for different rice seedling images, and the weight can vary with the probability of rice seedling occurrence. Therefore, to adaptively set the weight, the cumulative probability of rice seedling occurrence is considered as weight \(\alpha\) in the proposed method. Under \(\alpha=P_{2}(t)\), Equation (13) is rewritten as follows:  
\[\sigma_{w}^{2}(t)=P_{2}(t)P_{1}(t)\sigma_{1}^{2}(t)+P_{2}(t)\sigma_{2}^{2}(t). \tag{14}\]  
The optimal threshold \(T\) is chosen by the following function:  
\[ \begin{array}{l}T=\underset{0<t<L-1}{\operatorname{argmin}}\sigma_{w}^{2}(t) \\ =P_{2}(t)P_{1}(t)\sigma_{1}^{2}(t)+P_{2}(t)\sigma_{2}^{2}(t)\end{array}  \tag{15}\]  
Figure 9 shows the curves of five kinds of variance with different thresholds. In Figure 9, the green and red curves describe the rice seedling variance and the background variance, respectively. The corresponding within-class variance is shown by the purple curve. We can find that the minimum value of the within-class variance is \(T=22\). However, the weighted background variance (blue curve) is much smaller than the original background variance (red curve).