# Mapping Gaps in Sugarcane Fields in Unmanned Aerial Vehicle Imagery Using YOLOv5 and ImageJ
## 3 Materials and Methods
### Generate Gaps Mapping
\begin{table}
\begin{tabular}{c c c c c c} \hline \hline
**Color** & **X** & **Y** & **Length Pixels** & **Area Pixels2** & **Length cm** \\ \hline Red & 329.00 & 213.00 & 114.54 & & 150.00 \\ Orange & 215.50 & 103.00 & 54.08 & & 70.82 \\ Brown & 190.00 & 73.00 & 48.00 & & 62.86 \\ Orange & 154.50 & 191.50 & 61.01 & & 79.90 \\ Blue & 116.50 & 218.00 & 69.00 & & 90.36 \\ Orange & 249.00 & 218.00 & 52.15 & & 68.29 \\ Green & 222.00 & 240.00 & 54.00 & 2816.10 & 70.72 \\ Orange & 404.00 & 295.50 & 53.04 & & 69.46 \\ Pink & 377.50 & 321.50 & 55.01 & 2917.73 & 72.04 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Lengths of lines in Figure 8.  
Figure 8: (**a**) Two sizes of rectangles; (**b**) Black rectangle selection; (**c**) Rectangles with width and length identification by color code, and the distance between crop rows marked in red. Once the planting failures have been selected using the ImageJ script, a report is generated detailing the location and size of each gap within the image. We utilized the freely available software ImageJ [23; 32] to execute the selection process and generate the report. Figure 9 illustrates the steps for obtaining the field gap map, followed by a description of each step in the ImageJ script. The initial step involves splitting the RGB image into three channels (Image > Color > Split Channels) [33], each containing the field gaps identified by YOLOv5, because ImageJ functions mostly work with 8 bit images. This process permits the selection of field gaps based on size, along with other operations such as field gap numbering (Figure 10). In the next step, the red channel is used to identify field gaps based on a specified size, utilizing the built-in Analyze Particles plugin of ImageJ [34]. For this instance, the size parameter was set to 4200 pixels2. This method was chosen because the neural network can sometimes identify smaller empty spaces that may not be relevant for commercial field gap analysis. This step helps to correct such potential misidentifications. Figure 11a illustrates the outcome of this procedure. Additionally, this analysis is set to generate a report in a table format, indicating the locations of the field gap map, as demonstrated in Table 2.  
Figure 10: Result of the RGB image split into three channels, which contain the field gaps map: (**a**) original image, (**b**) red channel, (**c**) green channel, and (**d**) blue channel. Figure 9: ImageJ script flowchart to print the field gap map. In Figure 11b, the gaps are counted and numbered using the Analyze Particles plugin [35] based on their position, following a horizontal arrangement from top to bottom and a vertical arrangement from left to right. These numbers correspond to the lines in the field gap map table (Table 2), where each line represents a gap with the same numbering, as seen in the image. This table serves to verify the accuracy of the identification system and can be used in sugarcane replanting operations. Table 2 displays the identified gaps, with the gap numbers in the image aligning with the \"Gap\" column, allowing for easy association of data between the table and the numbered field gaps in the image (Figure 11b). The second column in Table 2 indicates the area of each gap in pixels2. The \"X\" and \"Y\" columns represent the centroid coordinates of the field gap in the image, which will eventually be replaced with georeferenced data, enabling precise identification and replanting operations in these areas if required by farmers in a continuation of this work. The \"XM\" and \"YM\" columns denote the center of mass of each gap. The \"BX\" and \"BY\" coordinates specify the upper-left corner of the gap rectangle. The \"Width\" and \"Length\" columns provide the dimensions of each gap, respectively.