# Corn Plant In-Row Distance Analysis Based on Unmanned Aerial Vehicle Imagery and Row-Unit Dynamics
## Materials and Methods
### Methodology for Corn Plant Detection and Spacing Estimation Based on UAV Orthomosaic
By utilizing the visible range of the spectrum, the index serves as a quantitative measure of vegetation fraction and can be calculated using the following equation [32], where \(r,g,b\) represent channels of created RGB patches:  
\[VARI(x,y)=\frac{g(x,y)-r(x,y)}{g(x,y)+r(x,y)-b(x,y)} \tag{1}\]  
Figure 2: The pipeline of the UAV orthomosaic creation followed by its patch-based division procedure. The final positions of corn plants are identified as the centroids of connected components in the segmented mask, following binary thresholding of the map derived from Equation (1). Further obtained components whose bounding box is out of range (48-52 cm\({}^{2}\)) are filtered out since the average size of corn plants in the current growth stage is approximately 50 cm\({}^{2}\). Template matching (TM) is used as a second method for corn plant detection that involves comparing a predefined image template (a small image patch representing the target object--in this case, a corn plant) with the target image using a similarity metric and convolution operation [33]. TM detection techniques have been utilized in some studies for corn detection and can be used to identify specific structures within the plants [34; 35; 36]. Detection is conducted by sliding the template image over the entire image and calculating the similarity between the template and the covered window on the image using the following formula, where \(c(x,y)\) represents the template correlation image, \(f(x-i,y-j)\) corresponds to the pixel values of the image window being analyzed, and \(t(x,\ y)\) denotes the pixel values of the template image patch [37]:  
\[c(x,y)=\sum_{i=1}^{M}\sum_{j=1}^{N}t(i,j)\cdot f(x-i,\ y-j) \tag{2}\]  
Template matching-based detection techniques have been utilized in some studies for corn detection and can be used to identify specific structures within the plants [35; 36; 37]. With the fast normalized cross-correlation [38] as the similarity metric, and by binarizing the obtained \(c(x,y)\) from Equation (2), the plants were detected as centers of extracted connected components within the binary image. As in [PERSON] et al. [39], five templates were randomly selected from the ground truth, and, therefore, each patch image was processed five times before the final locations of detected plants were obtained. The third method for corn plant detection we used is the deep learning-based model Mask R-CNN [40], specifically designed for instance segmentation and object detection tasks. Mask R-CNN is a two-stage architecture that extends the Faster R-CNN framework, being widely adopted and consistently showing a strong performance in agricultural studies [28; 41; 42; 43; 44; 45]. This method incorporates an additional branch for generating object masks alongside bounding box predictions. In this study, we used the Mask R-CNN model with R50-FPN as the backbone deep learning network trained on Microsoft's Common Objects in Context (COCO) dataset, a large-scale dataset consisting of 200k images [46]. The selected deep learning architecture, the Mask R-CNN R50-FPN model, was trained to classify two categories: corn plants and non-corn plant objects. The non-corn plant objects encompass various scene elements that are not the primary focus of detection, including weeds, rocks, and soil disturbances caused by machinery. For a qualitative evaluation of the corn detecting and counting model, four standard metrics were used, which are presented in the following table (Table 2):  
Plant spacing estimation from detected corn plants with the used methods requires the identification of rows. This was accomplished by connecting adjacent plants within the rows represented through the centroids of the nearest detected connected components. If