# Peeling Damage Recognition Method for Corn Ear Harvest Using RGB Image
## 2 Materials and Methods
### Recognition of Ear Damage
Similar to the corroding algorithm, the total numbers of  
Figure 5: Graphical demonstration for corroding operation based on different values of \(\lambda\) after five iterative cycles. surrounding pixels for pixels at edges and corners are 5 and 3, respectively. The parameter \(\rho\) controls the threshold of expanding. A smaller \(\rho\) can speed up expanding. In this study, we empirically set \(\rho=4\). Two termination conditions are detected after each iterative cycle, namely whether the number of iterative cycles is enough and whether the outputted image no longer changes. ```
0: Binary image \(\mathbf{C}_{2}\in\mathcal{R}^{n_{1}\times n_{2}}\), threshold \(\rho\), maximum number of iterative cycles \(t_{max}\). 1:while termination condition is not reached do
2: Initialize \(\mathbf{C}_{3}=\mathbf{0}\in\mathcal{R}^{n_{1}\times n_{2}}\);
3:for each pixel \(\mathbf{C}_{2}(i,j)\)do
4:if\(\delta(\mathbf{C}_{2}(i,j))>\rho\)then
5: Set all its surrounding pixels to 1;
6:endif
7:endfor
8:\(\mathbf{C}_{2}\gets\mathbf{C}_{3}\);
9:endwhile
0: Expanded binary image \(\mathbf{C}_{3}\). ```  
**Algorithm 4** Proposed expanding algorithm,  
The expanded result of the corroded image is presented in Figure 5(c). Comparing the corroded image, i.e., Figure 5(b), the pores and gap get apparent filling. Using the corrosion and expanding operations, we can not only accurately determine the region of kernels, but also reduce the searching scope for the following damage recognition. In previous operations, we obtain the region of corn kernels. Next, we introduce the method to recognize ear damage. The strategy is mainly based on the distinguishing reflections of kernel-dropping region in the red, green, and blue bands. We set the thresholds for upper and lower bounds of the three bands, respectively. A pixel is regarded to belong to ear damage region only when its reflections of all three bands are in the range of thresholds. The detailed steps are provided in Algorithm 5. The input matrix \(\mathbf{C}_{3}\) is just the image obtained after kernel recognizing, corroding, and expanding operations (see Figure 5(c)). All white pixels of \(\mathbf{C}_{3}\) are regarded as kernels, such that they will not be considered in the process of ear damage recognizing. The results is presented in Figure 6(b). We can note the recognized pixels are consistent with the actual damaged region. However, they are dispersed and cannot form a complete region. This is because many stubbles exist along the kernel-dropping region. These stubbles do not have the same RGB features as kernel-dropping region, and, therefore, they cannot be recognized directly by Algorithm 5. Figure 6: Corroding and expanding of recognized image. To address this problem, we propose the post-processing strategy that is summarized in Algorithm 6. The corrosion step and the expansion step are alternatively executed until the termination condition is reached. Here, the termination condition is also composed of two judgements. The first is whether the number of iterative cycles is enough. The second is whether the outputted image is the same as the inputted image in an iterative cycle. The proposed strategy can be regarded as a kind of close operation, aiming to connect spreading pixels in damage region and eliminate isolated pixels that are misidentified. We utilize Algorithm 6 for Figure 7b with \(\lambda=3\) and \(\rho=4\). The post-processed image is presented as Figure 7c. Obviously, the complete region is obtained instead of spreading pixels. The region is consistent with the damage region of the testing ear. As shown in Figure 7d, we combine the results on corn kernel recognition and ear damage recognition to obtain the final recognition result, where the black, white, and blue regions represent the background, the corn kernels, and the ear damage, respectively. The outline of complete method is summarized in Figure 8.  
Figure 7: Determination on region of ear damage.