# Peeling Damage Recognition Method for Corn Ear Harvest Using RGB Image
## 2 Materials and Methods
### Recognition of Ear Damage  
Corroding is used to eliminate outliers, which can also be regarded as noise. In this method, corroding is executed before expanding to avoid unexpected expansion caused by outliers. Here, we should provide the definition of the operator \(\delta(\cdot)\) in advance. **Definition 1**. : _Given a binary image \(\mathbf{C}\), the operation \(\delta(\cdot)\) with respect to a pixel \(\mathbf{C}\), denoted as \(\delta(\mathbf{C}(i,j))\), is defined by_  
\[\delta(\mathbf{C}(i,j))=\left[\sum_{a=i-1}^{i+1}\sum_{b=j-1}^{j+1}\mathbf{C}(a,b) \right]-\mathbf{C}(i,j). \tag{2}\]  
Figure 4: Corn kernel recognition for the testing ear using the proposed method. _and we define \(\mathbf{C}(i,j)=0\) once \(i=0\) or \(j=0\)._  
**Remark 2**. : _In fact, the operation \(\delta(\mathbf{C}(i,j))\) returns the number of 1-value pixels, i.e., the number of white pixels, among its surrounding 8 pixels. However, when a pixel is located at the edge of an image, the total number of surrounding pixels is 5; when a pixel is located ing the corner, the total number of surrounding pixels is 3._  
```
0: Binary image \(\mathbf{C}_{1}\in\mathcal{R}^{n_{1}\times n_{2}}\), threshold \(\lambda\), maximum number of iterative cycles \(t_{max}\). 1:while termination condition is not reached do
2: Initialize \(\mathbf{C}_{2}=\mathbf{0}\in\mathcal{R}^{n_{1}\times n_{2}}\);
3:for each pixel \(\mathbf{C}_{1}(i,j)\)do
4:if\(\delta(\mathbf{C}_{1}(i,j))>\lambda\)then
5:\(\mathbf{C}_{2}(i,j)=1\);
6:endif
7:endfor
8:\(\mathbf{C}_{1}\leftarrow\mathbf{C}_{2}\);
9:endwhile
0: Corroded binary image \(\mathbf{C}_{2}\). ```  
**Algorithm 3** Proposed corroding algorithm. **Require:** Binary image \(\mathbf{C}_{1}\in\mathcal{R}^{n_{1}\times n_{2}}\), threshold \(\lambda\), maximum number of iterative cycles \(t_{max}\). 1:while termination condition is not reached do
2: Initialize \(\mathbf{C}_{2}=\mathbf{0}\in\mathcal{R}^{n_{1}\times n_{2}}\);
3:for each pixel \(\mathbf{C}_{1}(i,j)\)do
4:if\(\delta(\mathbf{C}_{1}(i,j))>\lambda\)then
5:\(\mathbf{C}_{2}(i,j)=1\);
6:endif
7:endfor
8:\(\mathbf{C}_{1}\leftarrow\mathbf{C}_{2}\);
9:endwhile
0: Corroded binary image \(\mathbf{C}_{2}\). ```
**Algorithm 4** Proposed corroding algorithm. The proposed corroding algorithm is summarized in Algorithm 3. Our strategy is setting a pixel to be 1 only when more than \(\lambda\) of its surrounding pixels are 1. The corroding process is repeated until one of the two termination conditions is reached. The first condition is the number of iterative cycles is enough. The second is the outputted image no longer changes. The parameter \(\lambda\) controls the threshold for corroding a pixel. A larger \(\lambda\) encourages radical corrosion, whereas a smaller \(\lambda\) leads conservative corrosion. A graphical demonstration for comparing corroding operations based on different values of \(\lambda\) is provided in Figure 5. We randomly selected a patch of a binarized corn kernel image as the test image. The maximum number of iterative cycles was set to 5. Obviously, the outliers still remain after corroding when \(\lambda=1\). On the other hand, too many features of kernels are corroded when \(\lambda=5\). When \(\lambda=3\), the outliers can be removed and the main features of kernels still exist. Therefore, we empirically set \(\lambda=3\) in this study. Experimental results on the test ear are provided in Figure 6. Figure 5(a) shows the binary image after the kernel recognition process, which is just the image presented in Figure 5(b). Figure 5(b) is the corroded image of Figure 5(a). It is obvious most outliers have been successfully removed, and the main features of kernel are unaffected. Next, we expand the corroded image to fill pores and gap of kernels. The proposed expanding algorithm is summarized in Algorithm 4. For each pixel, all 8 of its surrounding pixels are set to 1 if more than \(\rho\) of its surrounding pixels are 1.