A method for detecting weeds in farmland based on image recognition
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-14
- Publication Date
- 2026-08-11
AI Technical Summary
然而,目前农田杂草检测方法大多依靠人工巡查、基于简单颜色特征的传统图像处理或基于规则阈值的方法,过程复杂且识别精度较低
[0048](1)本发明通过引入改进Fast-SCNN模型,显著提高了农田复杂环境下杂草分割的精度与对光照变化的鲁棒性。传统的Fast-SCNN模型虽然在实时语义分割方面具有优势,但在处理光照条件剧烈变化及极坐标变换引入的几何畸变时,特征提取能力受限。为解决这些问题,本发明创新性地在高分辨率下采样模块中构建复数域卷积运算单元,利用相位一致性编码算法提取对光照变化鲁棒的边缘纹理特征,有效滤除了光照不均带来的干扰。同时,在全局特征提取模块中引入极坐标几何特征校正机制,基于极坐标变换的径向畸变先验计算几何畸变权重图,对特征图的采样点进行动态校正与空间对齐,从而显著提升了模型在极坐标空间下的特征表达准确性,实现了高精度的杂草分割。
Smart Images

Figure CN122551177A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of agricultural technology, and in particular to a method for detecting weeds in farmland based on image recognition. Background Technology
[0002] With the increasing demands for precision planting and intelligent management in modern agriculture, traditional methods for detecting and controlling weeds in farmland are facing growing challenges. In modern precision agriculture management, accurate identification and distribution analysis of weeds in the crop growth environment are not only crucial for ensuring healthy crop growth but also key to improving the efficiency of agricultural robots and the accuracy of pesticide application decisions. However, current methods for detecting weeds in farmland mostly rely on manual inspections, traditional image processing based on simple color features, or rule-based thresholding, resulting in complex processes and low recognition accuracy. While these traditional methods can meet the basic requirements for large-area weeding operations, they lack real-time semantic understanding and adaptive analysis capabilities for complex farmland scenarios, making them unsuitable for real-time detection in environments with drastic changes in light intensity, severe crop shading, and unstructured background interference.
[0003] The main limitations of traditional weed detection methods in farmland lie in their insufficient utilization of crop row structural features and poor environmental robustness. Existing methods typically rely on fixed color thresholds, edge detection, or preset shape rules to segment weeds, which is time-consuming and difficult to accurately and promptly distinguish highly similar crops from weeds. When farmland environments exhibit characteristics such as curved crop row distribution, drastic changes in light conditions, and complex soil backgrounds, the generalization performance and stability of traditional detection methods are severely limited. In particular, when faced with variations in crop row width and partial occlusion due to perspective effects, traditional single-feature analysis methods based on the Cartesian coordinate system struggle to efficiently and accurately extract complete crop row regions, resulting in high false detection or false negative rates for weeds, seriously affecting the safety and effectiveness of subsequent precision weeding operations.
[0004] Furthermore, traditional methods for weed detection often neglect the complementary relationship between geometric prior information and feature channels in farmland scenes, making it difficult to comprehensively utilize the advantages of polar coordinate space transformation and the feature representation capabilities of the complex domain. For example, in actual farmland scenes where crop rows are distributed in an arc or the planting ridge spacing is uneven, traditional direct detection methods based on the rectangular coordinate system cannot effectively eliminate the influence of geometric distortion on feature extraction and struggle to handle texture confusion under complex lighting conditions, resulting in low detection accuracy and robustness. Even when some methods employ general deep learning networks, they fail to fully integrate crop row structure priors for polar coordinate transformation correction and to exploit the illumination-invariant properties in the phase features of the complex domain, making it difficult to achieve efficient, accurate, and interference-resistant farmland weed segmentation and spatial distribution analysis.
[0005] Therefore, how to provide an image recognition-based method for detecting weeds in farmland is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0006] This invention proposes an image recognition-based method for farmland weed detection. By combining an improved Fast-SCNN model with a polar coordinate transformation geometric correction mechanism, it can more accurately identify and locate weed targets in complex farmland environments. This method can not only automatically extract high-frequency spatial details and semantic context information from RGB images of farmland areas, but also combine radial distortion priors from polar coordinate transformation. By constructing complex domain convolution operation units and introducing a polar coordinate geometric feature correction mechanism, it achieves effective fusion and dynamic correction of modulus and phase features, significantly improving the accuracy of weed segmentation and its robustness to illumination changes. By introducing a set of polar coordinate transformation geometric parameters, an inverse polar coordinate mapping function, and a statistical analysis strategy based on a weed target attribute table, the traditional weed detection and post-processing process is improved. This allows the model to adaptively flatten curved crop rows and effectively avoid the influence of geometric distortion and background interference on the detection results, and to analyze the spatial distribution of weeds in real time. This invention overcomes the limitations of traditional farmland weed detection methods, such as reliance on manual inspection, difficulty in identifying crop rows, and poor environmental adaptability, and provides an efficient and robust solution for accurate identification of farmland weeds and intelligent plant protection operations.
[0007] A method for detecting weeds in farmland based on image recognition according to an embodiment of the present invention includes the following steps:
[0008] S1. Collect RGB images of farmland areas, input the RGB images of farmland areas into a context-aware network based on the BiSeNet model, extract high-frequency spatial details through spatial paths, capture semantic context information using context paths, and output a binarized attention mask containing crop row regions after feature fusion.
[0009] S2. Spatially align the binarized attention mask with the RGB image of the farmland area, perform pixel-level Hadamard product operation in the channel dimension, suppress the background area and enhance the foreground features to generate a mask-weighted image.
[0010] S3. Using the bottom center of the masked weighted image as the origin of polar coordinates, establish a spatial transformation relationship from the Cartesian coordinate system to the polar coordinate system, perform polar coordinate resampling on the masked weighted image, flatten the arc-shaped crop row into a vertical strip, and generate a polar coordinate image.
[0011] S4. Input the polar coordinate image and the binarized attention mask into the improved Fast-SCNN model, extract the corresponding mask feature map and polar coordinate image feature map and perform feature-level Hadamard product fusion to output a polar coordinate weed segmentation probability map.
[0012] S5. Threshold segmentation is performed on the polar coordinate weed segmentation probability map to generate a binary mask. Effective connected components are extracted based on morphological opening and closing operations. Polar coordinate weed detection boxes are generated by calculating the bounding rectangle of the connected components.
[0013] S6. Use polar coordinate transformation parameters to perform geometric correction on the polar coordinate weed detection box. Transform the corner coordinates of the detection box back to the original image space through inverse polar coordinate mapping, reconstruct the geometric distribution of weed targets in the RGB image of farmland area, and output the original coordinate weed detection box.
[0014] S7. Based on the original coordinate weed detection box, extract the center point coordinates and pixel area of each weed target, count the weed distribution density and coverage intensity in the farmland area, and generate weed detection results that include the spatial distribution pattern of weeds.
[0015] Optionally, the context-aware network based on the BiSeNet model includes a spatial path, a context path, an attention-guided fusion module, and a mask generation module:
[0016] The spatial path is used to receive RGB images of farmland areas, perform convolution operations and downsampling mapping on the input image using spatial downsampling convolution blocks, encode pixel features in up-dimensionality along the channel dimension, maintain high-resolution tensor representation in the spatial dimension, and output high-frequency spatial detail feature maps.
[0017] The context path is used to receive RGB images of farmland areas; multi-scale feature downsampling and semantic abstraction are performed on the RGB images of farmland areas using cascaded lightweight downsampling modules to gradually eliminate spatial redundancy and extract deep semantics; the features of the whole image are aggregated and global semantics are encoded by combining global average pooling layers to construct a large-scale receptive field to capture long-range semantic dependencies between pixels and output a semantic context feature map.
[0018] The attention-guided fusion module is used to receive high-frequency spatial detail feature maps and semantic context feature maps; it concatenates the input features along the channel dimension, introduces attention weight vector calculation operations, generates a weight mask through feature mapping and nonlinear activation, uses the mask to selectively weight and reconstruct the original features, optimizes the feature expression, and outputs a fused feature map.
[0019] The mask generation module is used to receive the fused feature map; input the fused feature map into the full-continuum integral class layer, perform class probability regression on each pixel to obtain the original logits, and use the Sigmoid function to activate and generate a pixel-level probability map; perform logical judgment and binarization mapping on the probability map based on a preset segmentation threshold, and output a binarized attention mask containing the crop row region.
[0020] Optionally, S2 specifically includes:
[0021] S21. Obtain the size parameters of the binarized attention mask and the RGB image of the farmland area, perform tensor shape alignment and dimension expansion, construct pixel-level index mapping relationship, and output spatially aligned feature tensor pairs.
[0022] S22. Broadcast expansion of spatially aligned feature tensors along the channel dimension to unify the binarized attention mask with the number of channels and data dimension of the RGB image of the farmland area, and generate dimension-matched input tensors.
[0023] S23. Perform a pixel-wise Hadamard product operation on the dimension-matched input tensor, and perform weighted modulation on the image data based on the mask value to generate a mask-weighted image.
[0024] Optionally, S3 specifically includes:
[0025] S31. Extract the size parameters of the masked weighted image, define the polar coordinate origin based on the bottom center pixel of the image, and combine the preset polar radius resolution and polar angle resolution to establish a mapping function relationship from the Cartesian coordinate system of the image plane to the polar coordinate system, and output the set of polar coordinate transformation geometric parameters including the polar coordinate origin coordinates, polar radius scaling factor and polar angle scaling factor.
[0026] S32. Construct a polar coordinate grid using the mapping function relationship, traverse the sampling points in the polar coordinate grid, calculate the Cartesian coordinate position of each sampling point in the masked weighted image, and output the coordinate index mapping matrix.
[0027] S33. Based on the coordinate index mapping matrix, the bilinear interpolation algorithm is used to resample the pixel values of the masked weighted image, and the neighboring pixel values at the mapping position are weighted and aggregated to generate a polar coordinate feature mapping matrix.
[0028] S34. Perform tensor reconstruction and data formatting on the polar coordinate feature mapping matrix along the angular dimension, and output the polar coordinate image.
[0029] Optionally, the improved Fast-SCNN model includes a high-resolution downsampling module, a global feature extraction module, a feature fusion module, and a feature enhancement segmentation head:
[0030] The high-resolution downsampling module is used to receive polar coordinate images and binarized attention masks, construct complex domain convolution operation units, map input features to complex space, and extract modulus features and phase features respectively; the phase features are parsed using a phase consistency coding algorithm to generate edge texture feature tensors that are robust to illumination changes, and output complex domain polar coordinate initial feature tensors and complex domain mask initial feature tensors.
[0031] The global feature extraction module receives the initial feature tensor in polar coordinates of the complex domain, introduces a polar coordinate geometric feature correction mechanism, calculates the geometric distortion weight map based on the radial distortion prior of polar coordinate transformation, and uses the geometric distortion weight map to dynamically correct and spatially align the sampling points of the feature map; combined with dynamic channel pruning routing, it activates the optimal convolution channel subset according to the texture complexity of the input features, performs semantic abstraction using the filtered complex depthwise separable convolution, and outputs a global semantic feature tensor in the complex domain;
[0032] The feature fusion module is used to receive the initial feature tensor of polar coordinates in the complex domain and the global semantic feature tensor in the complex domain, perform conjugate operation and modulus weighted mapping in the complex domain, unify the spatial resolution through upsampling operation, perform feature splicing along the channel dimension, and output a complex domain polar coordinate fusion feature map containing rich details and semantic information.
[0033] The feature enhancement segmentation head is used to receive the initial feature tensor of the complex domain mask and the fused feature map of the complex domain polar coordinates. It then uses dynamic channel pruning routing to perform channel optimization on the fused features again, performs tensor stacking operation along the channel dimension, introduces a complex amplitude mask to perform spatial modulation on the stacked features, performs feature-level fusion using pixel-by-pixel Hadamard product operation, and outputs a polar coordinate weed segmentation probability map by taking the real part operation.
[0034] Optionally, S5 specifically includes:
[0035] S51. Based on the pixel confidence distribution of the polar coordinate weed segmentation probability map, the segmentation threshold is calculated using the local adaptive thresholding algorithm, and a binary quantization mapping is performed to generate an initial binary mask.
[0036] S52. Construct a disk-shaped structural element operator of a preset scale, perform a morphological opening operation of erosion followed by dilation on the initial binary mask to filter out isolated noise points, and perform a morphological closing operation of dilation followed by erosion to fill the internal holes of the target, thereby generating a morphological denoising mask.
[0037] S53. Based on morphological denoising mask, the connected component analysis algorithm is used to traverse the pixel adjacency relationship to extract the connected pixel set, calculate the area and aspect ratio of the pixel set, and filter based on the preset attribute threshold to generate an effective connected component set.
[0038] S54. Traverse the set of valid connected components, analyze the extreme values of the polar radius and polar angle coordinates of each connected component in the polar coordinate system, construct a boundary vector containing the minimum and maximum values of the polar radius and the minimum and maximum values of the polar angle, and output a set of polar coordinate weed detection boxes.
[0039] Optionally, S6 specifically includes:
[0040] S61. Based on the set of geometric parameters of polar coordinate transformation and the set of polar coordinate weed detection boxes, analyze the boundary vector of each detection box in the set of polar coordinate weed detection boxes, extract the minimum and maximum values of the polar radius index and polar angle index in the boundary vector, and generate the corresponding image index range as the set of polar coordinate key points.
[0041] S62. Construct an inverse polar coordinate transformation mapping function, and substitute the polar radius index and polar angle index in the polar coordinate key point set with the resolution parameter in the polar coordinate transformation geometric parameter set into the mapping equation to perform inverse coordinate calculation, solve for the corresponding horizontal and vertical coordinate values in the original image coordinate system, and generate the original coordinate key point set.
[0042] S63. Traverse the original coordinate key point set, calculate the minimum and maximum values of the horizontal coordinate and the vertical coordinate, construct the boundary parameter vector and map it to a rectangular area, and output the original coordinate weed detection box set.
[0043] Optionally, S7 specifically includes:
[0044] S71. Obtain the original coordinate weed detection box set, parse the boundary coordinate vector of each detection box, calculate the mean of the horizontal coordinate and the mean of the vertical coordinate to locate the geometric center of the weed target, count the number of pixels within the boundary coordinate range to obtain the target pixel area, and generate a weed target attribute table.
[0045] S72. Based on the weed target attribute table, accumulate the total pixel area of weeds in the farmland area, calculate the number of weed targets and the percentage of pixel area in a unit area, quantify the weed distribution density and coverage intensity index, and generate a weed statistical feature vector.
[0046] S73. The target attribute table of weeds and the statistical feature vector of weeds are fused together. Based on the spatial location mapped by the geometric center coordinates and combined with the distribution density and coverage intensity indicators, a weed detection result containing the spatial distribution pattern of weeds is constructed.
[0047] The beneficial effects of this invention are:
[0048] (1) This invention significantly improves the accuracy of weed segmentation and its robustness to changes in illumination in complex farmland environments by introducing an improved Fast-SCNN model. Although the traditional Fast-SCNN model has advantages in real-time semantic segmentation, its feature extraction capability is limited when dealing with drastic changes in illumination conditions and geometric distortions introduced by polar coordinate transformation. To solve these problems, this invention innovatively constructs a complex domain convolution operation unit in the high-resolution downsampling module and uses a phase consistency coding algorithm to extract edge texture features robust to changes in illumination, effectively filtering out interference caused by uneven illumination. At the same time, a polar coordinate geometric feature correction mechanism is introduced in the global feature extraction module. Based on the radial distortion prior of polar coordinate transformation, a geometric distortion weight map is calculated, and the sampling points of the feature map are dynamically corrected and spatially aligned, thereby significantly improving the accuracy of feature representation in polar coordinate space and achieving high-precision weed segmentation.
[0049] (2) This invention effectively solves the technical challenges of background suppression in curved crop row areas and complex geometric distribution of weeds by combining the BiSeNet context-aware network with polar coordinate transformation. Traditional detection methods often ignore prior structural information about crop rows, making it difficult to accurately distinguish between weeds and crops against a curved background, resulting in a high false detection rate. This invention extracts a binarized attention mask containing crop row areas using the BiSeNet model, and uses pixel-level Hadamard product operations to suppress background areas and enhance foreground features, effectively focusing on crop row areas. Furthermore, by resampling with polar coordinates at the bottom center of the image as the origin, the curved crop rows are flattened into vertical strips, simplifying the spatial distribution of the target; combined with the inverse polar coordinate mapping algorithm, the detection results are accurately restored to the original image space, and statistical analysis strategies are used to quantify the weed distribution density and coverage intensity. This method breaks through the limitations of feature extraction in curved areas under the traditional Cartesian coordinate system, significantly improving the accuracy and environmental adaptability of weed detection, and providing efficient and reliable technical support for precision weeding operations in farmland. Attached Figure Description
[0050] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used in conjunction with embodiments of the invention to explain the invention and do not constitute a limitation thereof. In the drawings:
[0051] Figure 1 This is an overall flowchart of an image recognition-based method for detecting weeds in farmland proposed in this invention.
[0052] Figure 2 This is a flowchart illustrating the working principle of the improved Fast-SCNN model for farmland weed detection based on image recognition proposed in this invention. Detailed Implementation
[0053] The invention will now be described in further detail with reference to the accompanying drawings. These drawings are simplified schematic diagrams, illustrating only the basic structure of the invention, and therefore only show the components relevant to the invention.
[0054] refer to Figure 1 and Figure 2 A method for detecting weeds in farmland based on image recognition includes the following steps:
[0055] S1. Collect RGB images of farmland areas, input the RGB images of farmland areas into a context-aware network based on the BiSeNet model, extract high-frequency spatial details through spatial paths, capture semantic context information using context paths, and output a binarized attention mask containing crop row regions after feature fusion.
[0056] S2. Spatially align the binarized attention mask with the RGB image of the farmland area, perform pixel-level Hadamard product operation in the channel dimension, suppress the background area and enhance the foreground features to generate a mask-weighted image.
[0057] S3. Using the bottom center of the masked weighted image as the origin of polar coordinates, establish a spatial transformation relationship from the Cartesian coordinate system to the polar coordinate system, perform polar coordinate resampling on the masked weighted image, flatten the arc-shaped crop row into a vertical strip, and generate a polar coordinate image.
[0058] S4. Input the polar coordinate image and the binarized attention mask into the improved Fast-SCNN model, extract the corresponding mask feature map and polar coordinate image feature map and perform feature-level Hadamard product fusion to output a polar coordinate weed segmentation probability map.
[0059] S5. Threshold segmentation is performed on the polar coordinate weed segmentation probability map to generate a binary mask. Effective connected components are extracted based on morphological opening and closing operations. Polar coordinate weed detection boxes are generated by calculating the bounding rectangle of the connected components.
[0060] S6. Use polar coordinate transformation parameters to perform geometric correction on the polar coordinate weed detection box. Transform the corner coordinates of the detection box back to the original image space through inverse polar coordinate mapping, reconstruct the geometric distribution of weed targets in the RGB image of farmland area, and output the original coordinate weed detection box.
[0061] S7. Based on the original coordinate weed detection box, extract the center point coordinates and pixel area of each weed target, count the weed distribution density and coverage intensity in the farmland area, and generate weed detection results that include the spatial distribution pattern of weeds.
[0062] In this embodiment, the context-aware network based on the BiSeNet model includes a spatial path, a context path, an attention-guided fusion module, and a mask generation module:
[0063] The spatial path is used to receive RGB images of farmland areas, perform convolution operations and downsampling mapping on the input image using spatial downsampling convolutional blocks, encode pixel features along the channel dimension, and maintain high-resolution tensor representation in the spatial dimension to output a high-frequency spatial detail feature map. Specifically, it includes taking the RGB image of the farmland area as input, performing convolution operations and downsampling operations on the input image using a first convolutional layer with a kernel size of 3 and a stride of 2, increasing the number of feature channels to 32 to obtain a first spatial feature map; subsequently, using a convolutional layer with a kernel size of 3 and a stride of 2... The second convolutional layer performs convolution and downsampling operations on the first spatial feature map, further increasing the number of feature channels to 64, resulting in the second spatial feature map. Finally, a third convolutional layer with a kernel size of 3 and a stride of 2 performs convolution and downsampling operations on the second spatial feature map, ultimately increasing the number of feature channels to 128, resulting in the third spatial feature map. Through three cascaded convolution and downsampling processes, the original image is downsampled to one-eighth of the resolution in the spatial dimension, and feature encoding is completed in the channel dimension, outputting a high-resolution feature tensor containing rich high-frequency details.
[0064] The context path is used to receive RGB images of farmland areas; it utilizes cascaded lightweight downsampling modules to perform multi-scale feature downsampling and semantic abstraction on the RGB images of farmland areas, gradually eliminating spatial redundancy and extracting deep semantics; it combines global average pooling layers to aggregate the features of the entire image and perform global semantic encoding, constructing a large-scale receptive field to capture long-range semantic dependencies between pixels, and outputting a semantic context feature map; the context path specifically includes using a fast downsampling module to perform a convolution operation with a stride of 4 on the input image, quickly reducing the image resolution to one-quarter of the original size, and initializing the number of feature channels to 32 to obtain an initial feature map; subsequently, it utilizes two cascaded residual bottleneck modules... The initial feature map is processed first. Each residual bottleneck module contains three depthwise separable convolutional layers. The number of feature channels is gradually expanded to 64 and 128 while maintaining the resolution in the spatial dimension to encode and extract deep semantic information. Then, the number of feature channels is further expanded to 256. The resolution of the feature map is reduced to one-eighth of the original size through a depthwise separable convolution operation with a stride of 2, resulting in a deep semantic feature map. Finally, a global average pooling layer is applied to the deep semantic feature map to compress the spatial dimension of the feature map to a size of 1 by 1 while maintaining the value of 256 in the channel dimension, generating a context feature vector containing global semantic information and outputting a semantic context feature map.
[0065] The attention-guided fusion module receives a high-frequency spatial detail feature map and a semantic context feature map; it concatenates the input features along the channel dimension, introduces an attention weight vector calculation operation, generates a weight mask through feature mapping and nonlinear activation, and uses this mask to selectively weight and reconstruct the original features, optimizing the feature representation and outputting a fused feature map; specifically, the attention-guided fusion module first concatenates a high-frequency spatial detail feature map with 128 channels and a semantic context feature map with 256 channels along the channel dimension to generate a concatenated feature map with a total of 384 channels; then, it uses a convolutional layer with a kernel size of 3 to perform feature mapping processing on the concatenated feature map, compressing the number of feature channels to 64. The compressed feature map is obtained. Then, global average pooling is performed on the compressed feature map to compress its spatial dimension to 1x1, generating a feature vector containing global information. Two fully connected layers are then used to process the feature vector sequentially. The first fully connected layer reduces the feature channel dimension to 16, and the second fully connected layer restores the feature channel dimension to 384. A non-linear activation function is introduced between the two fully connected operations to generate channel attention weight vectors. The channel attention weight vectors are then multiplied element-wise with the concatenated feature map to selectively weight the original features. Finally, the features are reconstructed using a convolutional layer with a kernel size of 1, uniformly adjusting the number of feature channels to 128, and outputting the optimized fused feature map.
[0066] The mask generation module receives the fused feature map; inputs the fused feature map into a fully convolutional integral classification layer, performs class probability regression on each pixel to obtain the original logits, and uses the Sigmoid function to activate and generate a pixel-level probability map; performs logical judgment and binarization mapping on the probability map based on a preset segmentation threshold, and outputs a binarized attention mask containing the crop row region; the fully convolutional integral classification layer specifically includes using a convolutional layer with a kernel size of 3 and a stride of 1 to extract features from the fused feature map with 128 channels, adjusting the number of feature channels to 32 to obtain an intermediate classification feature map; subsequently using... Another convolutional layer with a kernel size of 3 and a stride of 1 is used to process the intermediate classification feature map, compressing the number of feature channels to 1 to obtain the original confidence value of each pixel. The Sigmoid activation function is applied to the original confidence values to map the values to the interval between 0 and 1, generating a pixel-level probability map. The preset segmentation threshold is set to 0.5. Pixels with a probability value greater than or equal to 0.5 in the pixel-level probability map are identified as foreground and assigned a value of 1, while pixels with a probability value less than 0.5 are identified as background and assigned a value of 0. After binarization, a binarized attention mask containing the crop row region is output.
[0067] In this embodiment, S2 specifically includes:
[0068] S21. Obtain the size parameters of the binarized attention mask and the RGB image of the farmland area, perform tensor shape alignment and normalization processing, construct a pixel-level index mapping relationship, and output intermediate feature tensor pairs; specifically, this includes reading the RGB image of the farmland area with a resolution of 512x512 and the single-channel binarized attention mask with a resolution of 64x64; using bilinear interpolation algorithm to perform upsampling operation on the single-channel binarized attention mask, restoring the resolution from 64x64 to 512x512, obtaining a spatially aligned single-channel mask; converting the pixel value data type of the RGB image of the farmland area to 32-bit floating-point type, and normalizing the values to the range of 0 to 1, generating a standard image tensor; strictly pairing the spatially aligned single-channel mask and the standard image tensor in pixel space, establishing a one-to-one pixel index mapping relationship, and outputting a single-channel mask tensor with dimensions of 512x512x1 and a standard image tensor with dimensions of 512x512x3 respectively.
[0069] S22. Broadcast expansion is performed on the spatially aligned feature tensors along the channel dimension to unify the number of channels and data dimension of the binarized attention mask with that of the RGB image of the farmland area, generating dimension-matched input tensors. Specifically, this includes obtaining the single-channel mask tensor with a dimension of 512 x 512 x 1 and the RGB image feature tensor of the farmland area with a dimension of 512 x 512 x 3 output from S21; detecting the channel number parameter of the RGB image feature tensor of the farmland area to confirm that the number of channels is 3; using the broadcast mechanism, the data logic of the single-channel mask tensor is mapped to the three channels along the channel dimension, so that the dimension shape of the single-channel mask tensor is represented as 512 x 512 x 3 in the operation logic without performing actual memory data copying; the dimension of the broadcast-expanded mask tensor and the RGB image feature tensor of the farmland area are checked to confirm that their height, width and channel number parameters are completely consistent, generating two input tensors with a dimension of 512 x 512 x 3, completing the dimension matching.
[0070] S23. Perform pixel-wise Hadamard product operation on the dimension-matched input tensor, and perform weighted modulation on the image data based on the mask values to generate a mask-weighted image. Specifically, this includes obtaining two input tensors generated in S22, each with a dimension of 512 x 512 x 3, namely the broadcast-expanded mask tensor and the farmland area RGB image feature tensor; multiplying the values at corresponding spatial positions and corresponding channel positions in the two tensors; using the pixels with a value of 1 in the mask tensor to retain the original feature information in the farmland area RGB image feature tensor, and using the pixels with a value of 0 in the mask tensor to set the background area feature information in the farmland area RGB image feature tensor to zero; after the operation is completed, a mask-weighted image with a dimension of 512 x 512 x 3 is generated, and the output contains only the effective features of the crop rows.
[0071] In this embodiment, S3 specifically includes:
[0072] S31. Extract the size parameters of the masked weighted image. Define the polar coordinate origin based on the bottom center pixel of the image. Combine the preset polar radius resolution and polar angle resolution to establish a mapping function relationship from the Cartesian coordinate system of the image plane to the polar coordinate system. Output a set of polar coordinate transformation geometric parameters including the polar coordinate origin coordinates, polar radius scaling factor, and polar angle scaling factor. Specifically, this includes obtaining the width and height parameters of the masked weighted image, setting the coordinates of the bottom center pixel in the image coordinate system as the origin of the polar coordinate transformation, i.e., the Cartesian coordinate origin; obtaining the preset polar radius resolution parameters and polar angle resolution parameters to determine the number of rows and columns of the image after polar coordinate transformation; establishing a mapping function relationship from image plane pixel coordinates to polar coordinates according to the conversion formula between Cartesian coordinates and polar coordinates; calculating the pixel distance corresponding to a unit length in the polar radius direction as the polar radius scaling factor, and calculating the pixel distance corresponding to a unit radian in the polar angle direction as the polar angle scaling factor; and packaging the origin coordinates, polar radius scaling factor, and polar angle scaling factor to output a set of polar coordinate transformation geometric parameters.
[0073] S32. Construct a polar coordinate grid using mapping function relationships, traverse the sampling points in the polar coordinate grid, calculate the Cartesian coordinate position of each sampling point in the masked weighted image, and output a coordinate index mapping matrix; specifically, based on the set of polar coordinate transformation geometric parameters output in S31, construct a regularly arranged polar coordinate grid in the polar coordinate system, where each row of the grid corresponds to a specific polar radius value and each column corresponds to a specific polar angle value; traverse each sampling point in the polar coordinate grid, convert the polar radius and polar angle coordinates of each sampling point into Cartesian coordinates in the masked weighted image plane according to the mapping function relationships; record the calculated Cartesian coordinate values, and generate a coordinate index mapping matrix with the same size as the polar coordinate grid, where each element stores the horizontal and vertical coordinate positions of the corresponding polar coordinate sampling point in the original image.
[0074] S33. Based on the coordinate index mapping matrix, a bilinear interpolation algorithm is used to resample the pixel values of the masked weighted image, and the neighboring pixel values at the mapped position are weighted and aggregated to generate a polar coordinate feature mapping matrix. Specifically, this includes reading the Cartesian coordinate position stored in the coordinate index mapping matrix and determining whether the coordinate position falls on an integer pixel point of the masked weighted image; if the coordinate position is not an integer, the four neighboring integer pixel points around the coordinate in the image pixel grid are located, and the weighted average pixel value is calculated using the bilinear interpolation algorithm according to the distance weight between the coordinate point and the four neighboring pixel points; if the coordinate position exceeds the image boundary, boundary padding or zero padding is performed; the above resampling operation is performed on all sampling points in the polar coordinate grid, and the calculated pixel values are filled into the corresponding positions to generate a polar coordinate feature mapping matrix.
[0075] S34. Perform tensor reconstruction and data formatting on the polar coordinate feature mapping matrix along the angular dimension to output a polar coordinate image. Specifically, this includes obtaining the polar coordinate feature mapping matrix, where the row index corresponds to the polar radius dimension and the column index corresponds to the polar angle dimension; scanning and arranging the data along the polar angle dimension to ensure that the data format conforms to the row-major order of image storage; performing tensor reconstruction on the matrix to adjust the data dimensions and types, converting it into a standard image tensor format; quantizing or normalizing the pixel values according to the preset image bit depth to generate the final polar coordinate image and output it, completing the transformation from the Cartesian coordinate system perspective to the polar coordinate perspective.
[0076] In this embodiment, the improved Fast-SCNN model includes a high-resolution downsampling module, a global feature extraction module, a feature fusion module, and a feature enhancement segmentation head:
[0077] The high-resolution downsampling module receives polar coordinate images and binarized attention masks, constructs a complex-domain convolution operation unit, receives polar coordinate images and binarized attention masks, maps input features to complex space, and extracts modulus features and phase features respectively; it uses a phase consistency coding algorithm to parse the phase features, generates an edge texture feature tensor robust to illumination changes, and outputs an initial feature tensor in complex-domain polar coordinates and an initial feature tensor in complex-domain mask; the complex-domain convolution operation unit includes taking the input polar coordinate image and binarized attention mask as real and imaginary inputs respectively, and processing them through a convolutional layer containing 64 complex convolutional kernels, each complex convolutional kernel consisting of a real part weight matrix and an imaginary part weight matrix. The imaginary part weight matrix is used to map the data to a 64-dimensional complex feature space. The magnitude and phase of each complex number in the complex feature are calculated to obtain a 64-dimensional magnitude feature map and a 64-dimensional phase feature map. The phase consistency coding algorithm includes using Log-Gabor filters of four different scales to perform frequency domain filtering on the 64-dimensional phase feature map and calculating the phase consistency metric value at each pixel position. The calculated phase consistency metric value is used as a weight coefficient and subjected to element-wise weighted multiplication with the 64-dimensional magnitude feature map. The weighted magnitude feature and the corresponding phase feature are recombined in the complex domain to generate a complex domain polar coordinate initial feature tensor and a complex domain mask initial feature tensor containing 64 channels.
[0078] The global feature extraction module receives the initial feature tensor in polar coordinates of the complex domain, introduces a polar coordinate geometric feature correction mechanism, calculates the geometric distortion offset based on the radial distortion prior of the polar coordinate transformation, and uses the geometric distortion offset to dynamically correct and spatially align the sampling points of the feature map. Combined with dynamic channel pruning routing, it activates the optimal subset of convolutional channels based on the texture complexity of the input features, performs semantic abstraction using the filtered complex depthwise separable convolution, and outputs a global semantic feature tensor in the complex domain. Specifically, the polar coordinate geometric feature correction mechanism includes calculating the Euclidean distance from the center point of the feature map to each pixel as a radial distance parameter, calculating the radial distortion offset of each pixel using a cubic polynomial function based on the radial distance parameter, and using the radial distortion offset to correct the real part feature map in the initial feature tensor in polar coordinates of the complex domain. The sampling grid coordinates of the imaginary part feature map are offset and corrected, and bilinear interpolation sampling is performed to achieve dynamic correction and spatial alignment of the sampling point positions. The dynamic channel pruning routing specifically includes calculating the L2 norm of the real and imaginary parts of the input complex feature tensor and summing them to obtain the texture complexity index of 64 channels. The texture complexity index is input into a lightweight routing network to output the importance scores of 64 channels. The importance scores are normalized using the Sigmoid function, and the importance scores corresponding to channels with values less than 0.1 are set to 0, and the rest are set to 1, generating a binary gate mask. The binary gate mask is used to extract the feature map subsets corresponding to non-zero channels. The feature map subsets are input into a complex depthwise separable convolutional layer for downsampling with a stride of 2 and semantic abstraction to output a complex domain global semantic feature tensor.
[0079] The feature fusion module receives the initial feature tensor in complex domain polar coordinates and the global semantic feature tensor in complex domain. It performs conjugation operations and modulus-weighted mapping in the complex domain, unifies the spatial resolution through upsampling, performs channel alignment and feature fusion, and outputs a complex domain polar coordinate fused feature map containing rich details and semantic information. The complex domain feature interaction and spatial alignment specifically include performing nearest-neighbor interpolation upsampling on the global semantic feature tensor in complex domain to make its spatial resolution consistent with the initial feature tensor in complex domain polar coordinates; extracting the effective channel subset of the upsampled features based on the index of the dynamic pruning route; and then... The set undergoes complex conjugation processing, and element-wise multiplication is performed with the channel corresponding to the initial feature tensor in complex polar coordinates, mapping the calculation result back to the original feature channel dimension; the modulus map of the initial feature tensor in complex polar coordinates is calculated, and a modulus weight matrix is generated by nonlinear mapping of the modulus map using an S-shaped growth curve; the result of the element-wise multiplication in complex domain is modulated using the modulus weight matrix; the feature fusion specifically includes element-wise addition of the modulated feature map and the initial feature tensor in complex polar coordinates along the channel dimension to generate a complex polar coordinate fused feature map containing rich details and semantic information.
[0080] The feature enhancement segmentation head receives the initial feature tensor of the complex domain mask and the fused feature map of complex domain polar coordinates. It then performs channel optimization on the fused features again using dynamic channel pruning routing, introduces a complex magnitude mask to spatially modulate the optimized features, performs feature-level fusion through channel concatenation and convolution operations, and outputs a polar coordinate weed segmentation probability map through real part extraction. Specifically, the channel optimization and spatial modulation include calculating the channel importance score of the fused feature map of complex domain polar coordinates using a lightweight routing network; calculating the complex modulus of each pixel in the fused feature map of complex domain polar coordinates, normalizing it using the Sigmoid activation function to generate a complex magnitude mask; and using the complex magnitude mask to perform spatial modulation on the complex domain polar coordinates. The real and imaginary parts of the coordinate fusion feature map are multiplied pixel by pixel to achieve adaptive enhancement of the spatial region. Then, the top 75% of preferred channels are selected based on the channel importance score, and the unselected channels are set to zero to keep the number of feature map channels unchanged. The feature-level fusion and output specifically includes concatenating the spatially modulated and selected complex domain polar coordinate fusion feature map with the initial feature tensor of the complex domain mask along the channel dimension, inputting it into a complex 1x1 convolutional layer for channel shuffling and semantic fusion, and outputting a fusion feature tensor. The real part of the fusion feature tensor is extracted to obtain a single-channel real feature map, which is then processed using the Sigmoid activation function to output a polar coordinate weed segmentation probability map.
[0081] In this embodiment, S5 specifically includes:
[0082] S51. Based on the pixel confidence distribution of the polar coordinate weed segmentation probability map, a local adaptive threshold algorithm is used to calculate the segmentation threshold, and a binary quantization mapping is performed to generate an initial binary mask. Specifically, this includes obtaining the predicted probability value of each pixel in the polar coordinate weed segmentation probability map; using a sliding window to traverse the probability map, calculating the mean and standard deviation of the pixel probability within the local window; using a weighted average formula combined with neighboring pixel information to dynamically calculate the adaptive threshold of each center pixel; comparing the predicted probability value of the pixel with the corresponding adaptive threshold; if the predicted probability value is greater than or equal to the threshold, the pixel is set as a foreground pixel and assigned a value of 1; otherwise, it is set as a background pixel and assigned a value of 0, thereby generating the initial binary mask.
[0083] S52. Construct a disk-shaped structuring element operator of a preset scale. Perform a morphological opening operation (erosion followed by dilation) on the initial binary mask to filter out isolated noise points. Perform a morphological closing operation (dilation followed by erosion) to fill the holes inside the target, generating a morphological denoising mask. Specifically, this includes constructing a disk-shaped structuring element operator with a radius of a preset number of pixels; using the disk-shaped structuring element operator to erode the initial binary mask, removing small connection points and isolated noise on the target boundary; performing a dilation operation on the eroded image to restore the foreground target area that has shrunk due to the erosion operation, completing the morphological opening operation; performing a dilation operation on the opened image to connect the broken pixel gaps within the target area; performing an erosion operation on the dilated image to eliminate the background area that has increased due to the dilation operation, smoothing the target boundary, completing the morphological closing operation, and finally outputting the morphological denoising mask.
[0084] S53. Based on morphological denoising masks, a connected component analysis algorithm is used to traverse pixel adjacency relationships to extract connected pixel sets. The area and aspect ratio of the pixel sets are calculated, and filtering is performed based on preset attribute thresholds to generate a valid connected component set. Specifically, this includes using a connected component labeling algorithm based on pixel adjacency relationships to scan the morphological denoising mask and extract all independent connected regions composed of non-zero pixels; counting the total number of pixels contained in each connected region as the area attribute; calculating the length and width of the minimum bounding rectangle of the connected component and obtaining the ratio as the aspect ratio attribute; comparing the calculated area and aspect ratio with preset minimum area threshold, maximum area threshold, and maximum aspect ratio threshold respectively; removing connected components with an area smaller than the minimum area threshold or greater than the maximum area threshold, and simultaneously removing elongated connected components with an aspect ratio greater than the maximum aspect ratio threshold, retaining connected components that conform to the morphological characteristics of weeds, and generating a valid connected component set.
[0085] S54. Traverse the set of effective connected components, analyze the extreme values of the polar radius and polar angle coordinates of each connected component in the polar coordinate system, construct a boundary vector containing the minimum and maximum values of the polar radius and the minimum and maximum values of the polar angle, and output a set of polar coordinate weed detection boxes. Specifically, this includes traversing each target region in the set of effective connected components, obtaining the coordinate indices of all pixels in the region in the polar coordinate image; analyzing the vertical component in the coordinate index to determine the polar radius parameter, and finding the maximum and minimum values; analyzing the horizontal component in the coordinate index to determine the polar angle parameter, and finding the maximum and minimum values; constructing a four-dimensional boundary vector based on the minimum and maximum values of the polar radius and the minimum and maximum values of the polar angle, which defines the fan-shaped detection range of weeds in the polar coordinate system; summing up the boundary vectors corresponding to all effective connected components, and outputting a set of polar coordinate weed detection boxes.
[0086] In this embodiment, S6 specifically includes:
[0087] S61. Based on the set of geometric parameters of polar coordinate transformation and the set of polar coordinate weed detection boxes, the boundary vector of each detection box in the set of polar coordinate weed detection boxes is analyzed, and the minimum and maximum values of the polar radius index and polar angle index in the boundary vector are extracted to generate the corresponding image index range as the set of polar coordinate key points. The specific implementation process is as follows: Obtain the boundary vector of each detection box in the set of polar coordinate weed detection boxes. The boundary vector contains the minimum and maximum values of the polar radius index and the minimum and maximum values of the polar angle index; extract the minimum and maximum values of the polar radius index as the image index range in the polar radius direction, and extract the minimum and maximum values of the polar angle index as the image index range in the polar angle direction; combine the extreme values of the polar radius index and the polar angle index to construct a corner point set containing four combinations of polar angle and polar radius index, and define the corner point set as the set of polar coordinate key points.
[0088] S62. Construct an inverse polar coordinate transformation mapping function. Substitute the polar radius index and polar angle index from the polar coordinate keypoint set into the resolution parameter from the polar coordinate transformation geometric parameter set and use them to perform coordinate inverse calculation to solve for the corresponding horizontal and vertical coordinate values in the original image coordinate system. The specific implementation process for generating the original coordinate keypoint set is as follows: Read the polar radius resolution and polar angle resolution parameters from the polar coordinate transformation geometric parameter set; Multiply each polar radius index in the polar coordinate keypoint set by the polar radius resolution to calculate the corresponding actual physical distance value; Multiply each polar angle index by the polar angle resolution to calculate the corresponding actual angle value; Construct an inverse polar coordinate transformation equation and use the actual physical distance value and actual angle value to calculate the corresponding horizontal and vertical coordinate values. The calculation formula is: the horizontal coordinate is equal to the horizontal coordinate of the center point plus the cosine of the actual physical distance value multiplied by the actual angle value, and the vertical coordinate is equal to the vertical coordinate of the center point plus the sine of the actual physical distance value multiplied by the actual angle value; Combine all the calculated horizontal and vertical coordinate values to generate the original coordinate keypoint set.
[0089] S63. The specific implementation process of traversing the original coordinate key point set, calculating the minimum and maximum values of the horizontal and vertical coordinates, constructing a boundary parameter vector and mapping it to a rectangular region, and outputting the original coordinate weed detection box set is as follows: Traverse all coordinate points in the original coordinate key point set, extract the horizontal and vertical coordinate values of all points respectively; calculate the minimum value among all horizontal coordinate values as the left boundary of the target region, and calculate the maximum value as the right boundary of the target region; calculate the minimum value among all vertical coordinate values as the upper boundary of the target region, and calculate the maximum value as the lower boundary of the target region; construct a four-dimensional boundary parameter vector based on the left, right, upper, and lower boundaries, map the boundary parameter vector to an axis-aligned rectangle, and generate the original coordinate weed detection box set.
[0090] In this embodiment, S7 specifically includes:
[0091] S71. Obtain the original coordinate weed detection box set, parse the boundary coordinate vector of each detection box, calculate the mean of the horizontal and vertical coordinates to locate the geometric center of the weed target, count the number of pixels within the boundary coordinate range to obtain the target pixel area, and generate a weed target attribute table; specifically, this includes extracting the boundary coordinate vector of each detection box in the original coordinate weed detection box set, the boundary coordinate vector containing the minimum, maximum, minimum, and maximum values of the horizontal and vertical coordinates; calculating the arithmetic mean of the minimum and maximum values of the horizontal and vertical coordinates to obtain the horizontal coordinate of the geometric center, and calculating the arithmetic mean of the minimum and maximum values of the vertical coordinates to obtain the vertical coordinate of the geometric center, thereby locating the position of the weed target in the image; calculating the difference between the maximum and minimum values of the horizontal coordinates to obtain the detection box width, calculating the difference between the maximum and minimum values of the vertical coordinates to obtain the detection box height, multiplying the detection box width and detection box height to calculate the total number of pixels within the boundary coordinate range, and using this total number as the target pixel area; summarizing and recording the geometric center coordinates and target pixel area of each detection box to generate a weed target attribute table.
[0092] S72. Based on the weed target attribute table, the total pixel area of weeds in the farmland area is accumulated. Combined with the image resolution parameters, the total pixel area is converted into the actual physical area. The number of weed targets per unit physical area is calculated to determine the weed distribution density. The ratio of the total pixel area of weeds to the total pixel area of the farmland image is calculated to determine the weed coverage intensity. A weed statistical feature vector is generated. Specifically, this includes traversing the weed target attribute table, accumulating and summing the target pixel areas of all records to obtain the total pixel area of weeds in the farmland area; counting the total number of records in the weed target attribute table as the number of weed targets; obtaining the resolution parameters of the image acquisition device and calculating the actual physical area corresponding to the farmland image; dividing the number of weed targets by the actual physical area to calculate the number of weeds per unit physical area as the weed distribution density index; dividing the total pixel area of weeds by the total pixel area of the farmland image to calculate the proportion of weeds in the image as the weed coverage intensity index; and combining the weed distribution density index and the weed coverage intensity index to generate a weed statistical feature vector.
[0093] S73. The weed target attribute table and weed statistical feature vectors are fused together. Based on the geometric center coordinates, spatial locations are mapped, and distribution density and coverage intensity indices are combined to construct a weed detection result that includes the spatial distribution pattern of weeds. Specifically, the geometric center coordinates of each target in the weed target attribute table are combined with polar coordinate transformation center parameters and mapped to the farmland geographic coordinate system to determine the actual physical location of the weeds in the field. The distribution density and coverage intensity indices in the weed statistical feature vectors are associated with the corresponding geographic locations for feature-level data fusion. Combining the mapped physical locations, distribution density, and coverage intensity indices, a multi-dimensional weed spatial distribution pattern map is constructed, which reflects the spatial aggregation degree and damage level of weeds in the farmland. Based on this pattern map, the final weed detection result is output, which includes the specific location and range of the weeds, as well as the overall weed damage distribution in the farmland.
[0094] Example 1:
[0095] To verify the feasibility of this invention in precision agriculture weed control, the method was applied to the intelligent precision weeding system of a large agricultural cooperative in a certain province (hereinafter referred to as "Farm A"). Traditional farmland weed monitoring systems typically employ whole-field spraying based on visible light images or detection algorithms based on rule segmentation. These methods not only struggle to accurately identify weed targets in complex backgrounds where crops and weeds have similar morphologies and are heavily obscured, but also fail to accurately obtain the spatial distribution density and coverage intensity of weeds, easily leading to excessive herbicide use and environmental pollution. To solve these problems, Farm A decided to adopt the weed detection and statistical method based on polar coordinate transformation and multi-feature fusion proposed in this invention.
[0096] During implementation, Farm A first used a high-definition panoramic camera mounted on a smart agricultural tractor to collect raw RGB image streams of the farmland canopy. After preprocessing operations such as image denoising, brightness equalization, and geometric distortion correction, a high-quality input image dataset was constructed. At the same time, agronomic experts at Farm A accurately labeled the location and hazard level of weeds in the collected image data, which served as the benchmark for model training and statistical evaluation.
[0097] Farm A uses a polar coordinate transformation network to map the image from the original Cartesian coordinate system to the polar coordinate system, constructing a polar coordinate image tensor. This effectively solves the geometric redundancy problem of traditional rectangular boxes when describing radially or linearly distributed weeds. Next, a deep feature extraction backbone network is used to extract radial features containing texture and color, and angular features containing spatial distribution information. These are then fused using an attention mechanism to generate polar coordinate weed detection boxes. Subsequently, based on the set of polar coordinate transformation geometric parameters, the boundary vectors of the detection boxes are analyzed, the extreme values of the polar radius and polar angle indices are extracted, and the inverse polar coordinate transformation mapping function combined with resolution parameters is used to perform coordinate inverse calculation, solving for the horizontal and vertical coordinate values in the original image coordinate system, generating a precise set of original coordinate weed detection boxes.
[0098] In the core statistical and analysis phase, this invention parses the original coordinate detection box set, calculates the mean of the horizontal and vertical coordinates to locate the geometric center of the weeds, and counts the number of pixels within the boundary range to obtain the target pixel area, generating a weed target attribute table. Subsequently, based on the attribute table, the total pixel area of the weeds is accumulated, and combined with image resolution parameters, the total pixel area is converted into the actual physical area. The number of weeds per unit physical area is calculated as the distribution density, and the pixel area ratio is calculated as the coverage intensity, generating a weed statistical feature vector. Finally, the system fuses the attribute table and the statistical feature vector, and combines the geometric center coordinates to map the spatial location, constructing a detection result containing the spatial distribution pattern of the weeds.
[0099] During implementation, Farm A's technical team discovered that, compared to traditional manual inspections and routine testing methods, the method of this invention significantly improves the accuracy of weed detection in farmland and the reliability of statistical characteristics. Traditional methods have a high rate of missed detection under crop shading and cannot quantify the actual density of weeds, while the method of this invention, through polar coordinate transformation geometric optimization, inverse coordinate accurate restoration, and multi-dimensional index quantification, effectively achieves accurate identification and damage assessment of weeds in complex field environments.
[0100] To further verify the actual performance of the method of the present invention, Farm A conducted a detailed comparative test between the method of the present invention and the traditional method. The specific performance data is shown in Table 1:
[0101] Table 1 Comparison of Weed Detection and Statistical Performance in Farm A
[0102]
[0103] As shown in Table 1, the performance of the farmland weed detection and statistics system was comprehensively improved after applying the method of this invention. The accuracy of weed target identification increased from 85.2% with traditional methods to 96.5%, and the weed location deviation decreased from 5.8 cm to 0.9 cm, significantly improving the accuracy of variable spraying control. The weed distribution density estimation error decreased from 18.5% to 3.2%, providing reliable data support for precision pesticide application. Herbicide usage decreased from 2.5 liters / ha to 1.4 liters / ha, significantly reducing agricultural non-point source pollution. In addition, the crop damage rate decreased from 8.5% to 1.2%, the comprehensive cost of weed control decreased from 45 yuan / mu to 28 yuan / mu, and the satisfaction rate with agronomic operations also significantly improved, from 82.0% to 95.0%.
[0104] Through the method of this invention, Farm A has successfully achieved accurate identification and spatial distribution awareness of weeds in complex farmland environments, effectively improving the targeting and efficiency of weeding operations, significantly reducing the cost of herbicide use and the risk of environmental pollution, ensuring the green growth of crops, and significantly improving the level of intelligence and digitalization of farmland management, providing strong technical support for the construction of modern smart agriculture.
[0105] The above description is only a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any equivalent substitutions or modifications made by those skilled in the art within the scope of the technology disclosed in the present invention, based on the technical solution and inventive concept of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. An image recognition-based weed detection method for a farmland, characterized by, Includes the following steps: S1. Collect RGB images of farmland areas, input the RGB images of farmland areas into a context-aware network based on the BiSeNet model, extract high-frequency spatial details through spatial paths, capture semantic context information using context paths, and output a binarized attention mask containing crop row regions after feature fusion. S2. Spatially align the binarized attention mask with the RGB image of the farmland area, perform pixel-level Hadamard product operation in the channel dimension, suppress the background area and enhance the foreground features to generate a mask-weighted image. S3. Using the bottom center of the masked weighted image as the origin of polar coordinates, establish a spatial transformation relationship from the Cartesian coordinate system to the polar coordinate system, perform polar coordinate resampling on the masked weighted image, flatten the arc-shaped crop row into a vertical strip, and generate a polar coordinate image. S4. Input the polar coordinate image and the binarized attention mask into the improved Fast-SCNN model, extract the corresponding mask feature map and polar coordinate image feature map and perform feature-level Hadamard product fusion to output a polar coordinate weed segmentation probability map. S5. Threshold segmentation is performed on the polar coordinate weed segmentation probability map to generate a binary mask. Effective connected components are extracted based on morphological opening and closing operations. Polar coordinate weed detection boxes are generated by calculating the bounding rectangle of the connected components. S6. Use polar coordinate transformation parameters to perform geometric correction on the polar coordinate weed detection box. Transform the corner coordinates of the detection box back to the original image space through inverse polar coordinate mapping, reconstruct the geometric distribution of weed targets in the RGB image of farmland area, and output the original coordinate weed detection box. S7. Based on the original coordinate weed detection box, extract the center point coordinates and pixel area of each weed target, count the weed distribution density and coverage intensity in the farmland area, and generate weed detection results that include the spatial distribution pattern of weeds.
2. The method according to claim 1, wherein, The context-aware network based on the BiSeNet model includes a spatial path, a context path, an attention-guided fusion module, and a mask generation module: The spatial path is used to receive RGB images of farmland areas, perform convolution operations and downsampling mapping on the input image using spatial downsampling convolution blocks, encode pixel features in up-dimensionality along the channel dimension, maintain high-resolution tensor representation in the spatial dimension, and output high-frequency spatial detail feature maps. The context path is used to receive RGB images of farmland areas; multi-scale feature downsampling and semantic abstraction are performed on the RGB images of farmland areas using cascaded lightweight downsampling modules to gradually eliminate spatial redundancy and extract deep semantics; the features of the whole image are aggregated and global semantics are encoded by combining global average pooling layers to construct a large-scale receptive field to capture long-range semantic dependencies between pixels and output a semantic context feature map. The attention-guided fusion module is used to receive high-frequency spatial detail feature maps and semantic context feature maps; it concatenates the input features along the channel dimension, introduces attention weight vector calculation operations, generates a weight mask through feature mapping and nonlinear activation, uses the mask to selectively weight and reconstruct the original features, optimizes the feature expression, and outputs a fused feature map. The mask generation module is used to receive the fused feature map; input the fused feature map into the full-continuum integral class layer, perform class probability regression on each pixel to obtain the original logits, and use the Sigmoid function to activate and generate a pixel-level probability map. Based on a preset segmentation threshold, the probability map is logically determined and binarized, and a binarized attention mask containing crop row regions is output.
3. The method for detecting farmland weeds based on image recognition according to claim 1, characterized in that, S2 specifically includes: S21. Obtain the size parameters of the binarized attention mask and the RGB image of the farmland area, perform tensor shape alignment and dimension expansion, construct pixel-level index mapping relationship, and output spatially aligned feature tensor pairs. S22. Broadcast expansion of spatially aligned feature tensors along the channel dimension to unify the binarized attention mask with the number of channels and data dimension of the RGB image of the farmland area, and generate dimension-matched input tensors. S23. Perform a pixel-wise Hadamard product operation on the dimension-matched input tensor, and perform weighted modulation on the image data based on the mask value to generate a mask-weighted image. 4.The method of claim 1, wherein, S3 specifically includes: S31. Extract the size parameters of the masked weighted image, define the polar coordinate origin based on the bottom center pixel of the image, and combine the preset polar radius resolution and polar angle resolution to establish a mapping function relationship from the Cartesian coordinate system of the image plane to the polar coordinate system, and output the set of polar coordinate transformation geometric parameters including the polar coordinate origin coordinates, polar radius scaling factor and polar angle scaling factor. S32. Construct a polar coordinate grid using the mapping function relationship, traverse the sampling points in the polar coordinate grid, calculate the Cartesian coordinate position of each sampling point in the masked weighted image, and output the coordinate index mapping matrix. S33. Based on the coordinate index mapping matrix, the bilinear interpolation algorithm is used to resample the pixel values of the masked weighted image, and the neighboring pixel values at the mapping position are weighted and aggregated to generate a polar coordinate feature mapping matrix. S34. Perform tensor reconstruction and data formatting on the polar coordinate feature mapping matrix along the angular dimension, and output the polar coordinate image. 5.The method of claim 1, wherein, The improved Fast-SCNN model includes a high-resolution downsampling module, a global feature extraction module, a feature fusion module, and a feature enhancement segmentation head. The high-resolution downsampling module is used to receive polar coordinate images and binarized attention masks, construct complex domain convolution operation units, map input features to complex space, and extract modulus features and phase features respectively; the phase features are parsed using a phase consistency coding algorithm to generate edge texture feature tensors that are robust to illumination changes, and output complex domain polar coordinate initial feature tensors and complex domain mask initial feature tensors. The global feature extraction module is used to receive the initial feature tensor of polar coordinates in the complex domain, introduce a polar coordinate geometric feature correction mechanism, calculate the geometric distortion weight map based on the radial distortion prior of polar coordinate transformation, and use the geometric distortion weight map to dynamically correct and spatially align the sampling points of the feature map. By combining dynamic channel pruning routing, the optimal subset of convolutional channels is activated based on the texture complexity of the input features. Semantic abstraction is performed using the filtered complex depth separable convolutions, and the output is a complex domain global semantic feature tensor. The feature fusion module is used to receive the initial feature tensor of polar coordinates in the complex domain and the global semantic feature tensor in the complex domain, perform conjugate operation and modulus weighted mapping in the complex domain, unify the spatial resolution through upsampling operation, perform feature splicing along the channel dimension, and output a complex domain polar coordinate fusion feature map containing rich details and semantic information. The feature enhancement segmentation head is used to receive the initial feature tensor of the complex domain mask and the fused feature map of the complex domain polar coordinates. It then uses dynamic channel pruning routing to perform channel optimization on the fused features again, performs tensor stacking operation along the channel dimension, introduces a complex amplitude mask to perform spatial modulation on the stacked features, performs feature-level fusion using pixel-by-pixel Hadamard product operation, and outputs a polar coordinate weed segmentation probability map by taking the real part operation.
6. The method of claim 1, wherein the method further comprises: S5 specifically includes: S51. Based on the pixel confidence distribution of the polar coordinate weed segmentation probability map, the segmentation threshold is calculated using the local adaptive thresholding algorithm, and a binary quantization mapping is performed to generate an initial binary mask. S52. Construct a disk-shaped structural element operator of a preset scale, perform a morphological opening operation of erosion followed by dilation on the initial binary mask to filter out isolated noise points, and perform a morphological closing operation of dilation followed by erosion to fill the internal holes of the target, thereby generating a morphological denoising mask. S53. Based on morphological denoising mask, the connected component analysis algorithm is used to traverse the pixel adjacency relationship to extract the connected pixel set, calculate the area and aspect ratio of the pixel set, and filter based on the preset attribute threshold to generate an effective connected component set. S54. Traverse the set of valid connected components, analyze the extreme values of the polar radius and polar angle coordinates of each connected component in the polar coordinate system, construct a boundary vector containing the minimum and maximum values of the polar radius and the minimum and maximum values of the polar angle, and output a set of polar coordinate weed detection boxes.
7. The method of claim 1, wherein the method further comprises: S6 includes the following steps: S61. Based on the set of geometric parameters of polar coordinate transformation and the set of polar coordinate weed detection boxes, analyze the boundary vector of each detection box in the set of polar coordinate weed detection boxes, extract the minimum and maximum values of the polar radius index and polar angle index in the boundary vector, and generate the corresponding image index range as the set of polar coordinate key points. S62. Construct an inverse polar coordinate transformation mapping function, and substitute the polar radius index and polar angle index in the polar coordinate key point set with the resolution parameter in the polar coordinate transformation geometric parameter set into the mapping equation to perform inverse coordinate calculation, solve for the corresponding horizontal and vertical coordinate values in the original image coordinate system, and generate the original coordinate key point set. S63. Traverse the original coordinate key point set, calculate the minimum and maximum values of the horizontal coordinate and the vertical coordinate, construct the boundary parameter vector and map it to a rectangular area, and output the original coordinate weed detection box set. 8.The method of claim 1, wherein, S7 includes the following steps: S71. Obtain the original coordinate weed detection box set, parse the boundary coordinate vector of each detection box, calculate the mean of the horizontal coordinate and the mean of the vertical coordinate to locate the geometric center of the weed target, count the number of pixels within the boundary coordinate range to obtain the target pixel area, and generate a weed target attribute table. S72. Based on the weed target attribute table, accumulate the total pixel area of weeds in the farmland area, calculate the number of weed targets and the percentage of pixel area in a unit area, quantify the weed distribution density and coverage intensity index, and generate a weed statistical feature vector. S73. The target attribute table of weeds and the statistical feature vector of weeds are fused together. Based on the spatial location mapped by the geometric center coordinates and combined with the distribution density and coverage intensity indicators, a weed detection result containing the spatial distribution pattern of weeds is constructed.