# Mapping Gaps in Sugarcane Fields in Unmanned Aerial Vehicle Imagery Using YOLOv5 and ImageJ
## 3 Materials and Methods
### Generate Gaps Mapping  
The fifth and final task in the field gap map process involves selecting the identified gaps based on a parameterized size measured in pixels2. This approach is necessary because convolutional neural networks excel at identifying objects, regardless of their size in the image. Consequently, for planting failures, only empty spaces larger than 50 cm are considered to be commercially significant. The goal is to map only these substantial failures. To address this, the mapping process is conducted in two stages. Initially, convolutional neural networks are used to identify planting failures of any size. In the second stage, commercially significant planting failures are selected. These failures will then be mapped using ImageJ digital image processing software. Since YOLO identifies objects within rectangular bounding boxes, the selection of planting failures identified by YOLO must be refined using ImageJ based on the size of the area demarcated by YOLO. Typically, gaps exceeding 50 cm in length are classified as failures. To achieve the selection based on area, the width of the bounding box is multiplied by its length. However, these dimensions are in pixels, so a conversion is necessary to determine the length in centimeters. In Figure 8, the red line represents the distance between cultivation rows, which is 150 cm for sugarcane. The red line, as shown in Table 1, measures 114.54 pixels. This pixel length was obtained from ImageJ by drawing a line and selecting Analyze > Measure. The same method was applied to the lines in orange, brown, blue, green, and pink. Using the known measurement of 150 cm and the corresponding pixel length, an index was derived to convert all pixel lengths to centimeters, as shown in Table 1.  
Figure 7: Example of field gap image identification. To differentiate between failure sizes to be recorded and those to be discarded, the area in pixels must be calculated. In Figure 8, an example using a subimage of Figure 16, where the rectangle in black marked with the number 3 is selected as a failure to be recorded, while the white-bordered rectangles should be discarded. Referring to Table 1, an area threshold of 4200 pixels2 can be used to distinguish the black rectangle from the white-bordered ones (Figure 8a,b). The index for converting pixel lengths to centimeters is calculated as follows:  
\[\text{Ind\_pixel\_cm}=\text{red line length/length in pixels}=1.3096 \tag{1}\]  
Using this index, the lengths in pixels can be converted to centimeters for the rectangles in Figure 8. In Figure 8c, the widths, highlighted in orange, are approximately the same size, ranging from 52 to 61 pixels. The following formula is used to calculate the area for a length of 50 cm in pixels:  
\[\text{length in pixels}=\text{length in cm/Ind\_pixel\_cm} \tag{2}\]  
and for a length of 50 cm:  
\[\text{length in pixels for 50 cm}=50/1.3096=38.18\text{ pixels}\]  
To estimate the area of a failure with a length of 50 cm, the following formula is used:  
\[\text{Area in pixels}^{2}=\text{avg\_width}\times\text{length\_pixel} \tag{3}\]  
The average width of the failures is denoted as avg_width, assuming avg_width = 55.07 pixels. \[\text{Area for 50 cm length}=38.18\times 55.07=2102.57\]  
Therefore, an area of 2100 pixels2 will be used as a benchmark in this study for a length of 50 cm. To illustrate the entire process, an area value of 4200 pixels2 will be used to demonstrate the exclusion of certain planting failures.