Agricultural image background removal method
By combining adaptive illumination condition determination and multi-vegetation index feature maps with machine learning models, along with vegetation texture region judgment and morphological processing, the problem of vegetation recognition in traditional methods that are sensitive to changes in illumination and in complex backgrounds has been solved, achieving high-precision background removal of agricultural images.
Patent Information
- Application Number
- CN202511462649.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-14
- Publication Date
- 2025-11-11
AI Technical Summary
Traditional methods for removing backgrounds from agricultural images are sensitive to changes in lighting and lack adaptability to different scenes. Single vegetation indices have limited effectiveness in complex backgrounds and are difficult to reliably distinguish between target vegetation and background.
An adaptive illumination condition determination method is adopted to calculate multiple vegetation index feature maps and learn the importance of vegetation indices through a machine learning model. Combined with vegetation texture region judgment and morphological processing, an optimized foreground mask is generated to remove the background.
It enhances the ability to distinguish vegetation in complex backgrounds, improves the extraction ability in overexposed or shadowed areas, reduces the influence of subjective factors, and improves the generalization ability and background removal accuracy of the method.
Smart Images

Figure CN120931689A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of agricultural image processing technology, and specifically relates to a method for removing background from agricultural images. Background Technology
[0002] In modern agricultural production, accurate crop image analysis is crucial for improving agricultural efficiency and quality. However, in practice, agricultural images often contain complex background information (such as soil, sky, and weeds), which can interfere with subsequent vegetation identification and analysis. Traditional background removal methods mainly rely on fixed color thresholds, which are sensitive to changes in lighting and lack adaptability to different scenes. Furthermore, while single vegetation indices (such as ExG, CIVE, and NGRDI) can enhance vegetation differentiation under certain specific conditions, their effectiveness is limited against complex backgrounds, making it difficult to reliably distinguish target vegetation from the background. Summary of the Invention
[0003] This application provides a method for removing background from agricultural images to solve one of the aforementioned technical problems.
[0004] The technical solution adopted in this application is as follows: This application provides a method for removing background from agricultural images, including: Obtain the original RGB format agricultural image and perform image preprocessing on the agricultural image; Adaptive illumination condition determination is performed on preprocessed agricultural images; Based on the light conditions determination results, the corresponding vegetation indices are calculated and selected, and multiple vegetation index feature maps are generated. Multiple vegetation index feature maps are input into a machine learning model, which learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map. Vegetation texture regions are determined from the preprocessed agricultural images to obtain the target vegetation texture region determination results; The foreground mask is determined based on the integrated vegetation feature map and the target vegetation texture region determination results; Morphological processing is performed on the foreground mask to obtain an optimized foreground mask; Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image.
[0005] According to one embodiment of this application, the image preprocessing includes denoising, contrast enhancement, and color correction of the image. According to one embodiment of this application, the plurality of vegetation indices include ExG, CIVE, and NGRDI, and the calculation of the plurality of vegetation indices is based on automatically selecting an applicable combination of vegetation indices according to the image lighting environment.
[0006] According to one embodiment of this application, the adaptive lighting condition determination is based on the brightness distribution and contrast analysis of the image. The determination result includes three states: excessive lighting, insufficient lighting or shadow, and uniform lighting. When the lighting is excessive, it is determined that the brightness is higher than a preset threshold and the color temperature is within a reasonable range.
[0007] According to one embodiment of this application, the vegetation texture region determination is based on the extracted contrast, energy, and homogeneity features of the image, wherein the contrast is used to identify the edge differences between vegetation and the background.
[0008] According to one embodiment of this application, the determination of the foreground mask is based on adaptive thresholding processing of the integrated vegetation feature map, and the threshold range is dynamically determined according to the image brightness distribution and vegetation feature density.
[0009] According to one embodiment of this application, the morphological processing includes an erosion operation to remove small-area noise and an expansion operation to process mask boundaries.
[0010] A second aspect of this application provides a computer-readable storage medium having a program stored thereon that, when executed by a processor, implements the steps described in the method.
[0011] A third aspect of this application provides an electronic device including a memory, a processor, and a program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the method as described.
[0012] Due to the adoption of the above technical solution, the beneficial effects achieved by this application are as follows: This application calculates multiple vegetation indices based on illumination conditions and fuses them to generate a comprehensive vegetation feature map, enhancing the ability to distinguish vegetation against complex backgrounds and improving the extraction of overexposed or shadowed areas. A machine learning model automatically learns the importance weights of each vegetation index, replacing the manual setting of thresholds and weights, reducing the influence of subjective factors and improving the method's generalization ability. An empirical method is used to threshold the texture features of the target vegetation, selectively removing weeds that are difficult to remove by vegetation indices, while maintaining good robustness in most field scenarios. Adaptive judgment processing based on the comprehensive vegetation feature map and the target vegetation texture region further enhances the accuracy of judgment by combining texture features, adapting to different illumination conditions and vegetation species, and further improving the background removal effect. Morphological processing of the initial foreground mask refines the mask boundaries, improving the accuracy of background removal and making the final target vegetation image more precise. Attached Figure Description
[0013] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 A schematic flowchart illustrating an agricultural image background removal method provided in this application embodiment; Figure 2 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application; Figure 3(a) is a schematic diagram of the original image provided in the embodiment of this application; Figure 3(b) is a schematic diagram of background removal of an agricultural image according to an embodiment of this application; Figure 3(c) is a schematic diagram of background removal using the threshold method provided in an embodiment of this application; Figure 3(d) is a background removal image with a single vegetation index provided in an embodiment of this application.
[0014] Figure label: 810, Processor; 820, Communication interface; 830, Memory; 840, Communication bus. Detailed Implementation
[0015] To more clearly illustrate the overall concept of this application, a detailed explanation is provided below with reference to the accompanying drawings.
[0016] Many specific details are set forth in the following description to provide a thorough understanding of this application. However, this application may also be implemented in other ways different from those described herein. Therefore, the scope of protection of this application is not limited to the specific embodiments disclosed below. It should be noted that, unless otherwise specified, the embodiments of this application and the features thereof can be combined with each other.
[0017] In this application, unless otherwise expressly specified and limited, the "above" or "below" of the second feature can mean that the first and second features are in direct contact, or that the first and second features are in indirect contact through an intermediate medium. In the description of this specification, references to terms such as "an embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described can be combined in any suitable manner in one or more embodiments or examples.
[0018] Example 1 like Figure 1 As shown, a method for removing background from agricultural images includes: Obtain the original RGB format agricultural images and perform image preprocessing on them.
[0019] As mentioned above, acquiring raw RGB format agricultural images refers to unprocessed color agricultural images collected from various sources, such as drones, satellites, or ground-based photographic equipment. These images typically contain information about crops and their surrounding environment, such as soil, sky, and other elements. Preprocessing these agricultural images, including but not limited to noise reduction, contrast enhancement, and color correction, aims to increase data diversity, thereby improving the model's generalization ability and the accuracy of background removal and vegetation extraction.
[0020] For example, when using a drone to photograph large areas of farmland, the resulting images may suffer from overexposure, occlusion, or underexposure due to varying weather conditions or limitations of the equipment. In such cases, the overall image quality is first assessed using an image illumination condition detection algorithm to determine the image type, such as overexposure, occlusion, underexposure, or uniform illumination. Then, based on the corresponding image type, a suitable vegetation index algorithm is selected. This processed image more accurately reflects the actual growth of crops, providing high-quality data support for subsequent background removal and target recognition.
[0021] As described above, adaptive thresholding based on the integrated vegetation feature map refers to dynamically determining one or more thresholds using the information contained in the generated integrated vegetation feature map, thereby segmenting the image into foreground (i.e., the vegetation region of interest) and background. This process takes into account the influence of different lighting conditions, vegetation types, and complex backgrounds on the vegetation index, enabling the selected thresholds to more accurately reflect the actual situation. The initial foreground mask generated by this method can effectively distinguish between target vegetation and non-vegetated areas, providing a precise foundation for subsequent processing steps.
[0022] For example, suppose a remote sensing image was taken in a field where various crops are intercropped, and a comprehensive vegetation feature map was generated based on the previous step. Due to the diverse vegetation types and complex background environment in this area, using a fixed thresholding method is insufficient to achieve ideal segmentation results. Therefore, an adaptive thresholding technique is employed. The system first analyzes the pixel distribution of the entire feature map, identifying different grayscale levels that may represent vegetation and background. Then, based on this information, the threshold is automatically adjusted to ensure accurate segmentation even under varying lighting conditions or significant differences in vegetation color. The resulting initial foreground mask accurately delineates all vegetation areas without mistakenly including background.
[0023] It should be noted that, in specific implementation scenarios, an intelligent algorithm can be developed based on the above solutions, allowing the system to dynamically update thresholds according to real-time acquired data to adapt to constantly changing external conditions. Research can also be conducted on how to combine time-series data (such as satellite images from several consecutive days) to improve the accuracy of adaptive thresholding, especially during seasonal changes or drastic weather conditions. The introduction of deep learning technology can be explored to enable the system to automatically learn the optimal threshold selection strategy without human intervention, enhancing the system's intelligence level. Combining adaptive thresholding with other types of image processing techniques, such as edge detection or morphological operations, can be considered to further improve the quality and detail of the foreground mask. Furthermore, the application of this adaptive thresholding technology to other fields, such as urban greening monitoring and forest fire early warning, can be explored to broaden its application scope.
[0024] It should be noted that, in specific implementation scenarios, based on the above solutions, a vegetation index calculation method adapted to different crop types and growth stages can be developed, enabling the system to automatically select the most suitable combination of vegetation indices for the current scenario; adaptive normalization technology can be introduced to improve the stability and accuracy of vegetation index calculation, especially under conditions of significant light variation; exploration can be conducted on how to combine deep learning models to directly learn the optimal vegetation index representation from the original images, rather than relying on traditional fixed formulas; and a dynamic adjustment mechanism can be established to allow continuous optimization of vegetation index calculation parameters based on real-time data, ensuring optimal performance in long-term operation. Furthermore, consideration is being given to combining vegetation index feature maps with other data sources (such as meteorological data, soil moisture information, etc.) to provide a more comprehensive crop health status assessment service.
[0025] It should be noted that, in specific implementation scenarios, artificial intelligence technology can be introduced to automatically identify lighting conditions in images and recommend the best preprocessing methods, building upon the above solutions. An image preprocessing algorithm library applicable to different climatic conditions can be developed, enabling the system to adapt to the needs of agricultural production worldwide. Furthermore, by combining with Geographic Information Systems (GIS), preprocessing parameters can be automatically adjusted based on the specific environmental characteristics of the shooting location (such as altitude and soil type), further improving image quality and background removal effectiveness. In addition, it is possible to explore how to integrate deep learning technology into the image lighting condition detection and preprocessing stages to achieve a more intelligent and efficient processing flow, ensuring that even images acquired under extreme conditions can be effectively preprocessed and analyzed.
[0026] Adaptive illumination condition determination is performed on the preprocessed agricultural images. Based on the illumination condition determination results, the corresponding vegetation index is calculated and selected, and multiple vegetation index feature maps are generated.
[0027] As described above, calculating multiple vegetation indices based on each pixel in the acquired agricultural image involves transforming each pixel value in the original RGB image using specific mathematical formulas to generate different index maps reflecting the vegetation state. These vegetation indices (such as the Green Enhancement Index (ExG), CIVE index, and NGRDI index) can highlight the vegetation in the image and suppress the influence of background elements, thereby helping to more accurately identify and analyze target vegetation. Through this process, feature maps can be created for each vegetation index. These feature maps will serve as important inputs for subsequent steps to construct a comprehensive vegetation feature map and ultimately achieve background removal.
[0028] Targeted vegetation indices can be selected based on different lighting and vegetation conditions. Each indice has different sensitivities and expressiveness for different types of vegetation or environmental conditions, which can improve background removal accuracy and reduce computational load. Among them, VARI, NGRDI, and RGBVI respond strongly to green vegetation and are suitable for scenes with sufficient light and vivid vegetation colors; CIVE, ExGR, and MExG are robust to changes in lighting and are suitable for low light or uneven lighting conditions; ExG, GLI, and TGI are sensitive to the relative changes in the green and red channels and are suitable for scenes with uniform vegetation lighting and complex backgrounds. By selecting appropriate vegetation indices, computational efficiency can be improved while ensuring the accuracy of foreground extraction, providing stable feature input for subsequent texture discrimination or model analysis.
[0029] The multiple vegetation index feature maps are input into a machine learning model, which learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map.
[0030] As mentioned above, inputting multiple vegetation index feature maps into a machine learning model refers to processing these feature maps using a model already trained on a large amount of labeled data. During this process, the model automatically evaluates the importance of each vegetation index in identifying and distinguishing target vegetation from complex backgrounds. This importance assessment is based on the contribution of each vegetation index to the final classification result, thus giving higher weights to indices that more effectively reflect vegetation characteristics. By combining these weighted vegetation indices, a comprehensive vegetation feature map can be generated. This map is a two-dimensional matrix of the same size as the original image, where the value of each pixel represents the probability or intensity of that location being foreground. It more accurately represents the presence of vegetation in the image and provides a basis for subsequent background removal.
[0031] For example, when processing a remote sensing image containing various crops and their complex background, multiple vegetation indices such as VARI, NGRDI, and RGBVI might be calculated as feature maps. When these feature maps are fed into a random forest model, the model automatically adjusts the weights of each indice based on knowledge learned from the training data. If the VARI index is particularly effective at distinguishing crops from the background in a specific image, its weight in the final composite vegetation feature map will be relatively high. Conversely, if an index performs poorly in this scenario, its weight will be reduced. This way, the generated composite vegetation feature map is better adapted to the specific application scenario, improving the accuracy of background removal.
[0032] It should be noted that, in specific implementation scenarios, based on the above solutions, different types of machine learning models (such as Support Vector Machines (SVM), Deep Neural Networks (DNN), etc.) can be explored to improve the model's generalization ability and accuracy; an adaptive weight adjustment strategy can be developed, allowing the model to dynamically update the weights of vegetation indices based on real-time acquired data, ensuring stable performance in long-term use; research can be conducted on how to combine Geographic Information System (GIS) data to further optimize the weight allocation of vegetation indices, thereby improving applicability to specific regions or crop types; and the introduction of reinforcement learning mechanisms can be considered to enable the system to continuously self-optimize without human intervention, achieving optimal adaptability to new environments or unknown conditions. Furthermore, the combination of integrated vegetation feature maps with other types of data (such as high-resolution satellite imagery, video streams captured by drones, etc.) can be explored to provide more multi-dimensional information for agricultural monitoring and management decision support.
[0033] Vegetation texture regions are determined in the preprocessed agricultural images to obtain the target vegetation texture region determination results. The foreground mask is determined based on the comprehensive vegetation feature map and the target vegetation texture region determination results.
[0034] Vegetation texture region determination in preprocessed agricultural images refers to extracting texture features such as contrast and energy from the image using methods like Gray-Level Co-occurrence Matrix (GLCM), and then using a thresholding method to identify regions with typical vegetation texture characteristics. This process generates target vegetation texture region determination results, describing which areas are most likely to contain the target vegetation. Based on this result and combined with a comprehensive vegetation feature map, the system can generate a foreground mask more accurately. Specifically, the comprehensive vegetation feature map provides preliminary vegetation distribution information obtained from the fusion of multiple vegetation indices, while the texture region determination results supplement information about the internal structure and edge details of the vegetation. Combined, the system can more accurately delineate the foreground (i.e., target vegetation) and background regions, ensuring that the generated foreground mask not only covers all vegetation areas but also has clear boundaries and is free of mis-segmentation.
[0035] For example, in a mixed cropping field, the preprocessed image might contain areas with similar colors but different textures, such as wheat fields and weed areas. Through texture analysis, the system can distinguish the unique fine texture of wheat leaves from the rough surface characteristics of weeds. Simultaneously, based on vegetation density information provided by the integrated vegetation feature map, the system further identifies the areas where wheat growth is most concentrated. Combining these two methods, the system can generate an accurate foreground mask that precisely marks the location and boundaries of wheat plants while excluding soil, weeds, and other non-vegetation elements in the background. This generated mask provides a reliable foundation for subsequent background removal and focusing on the target vegetation.
[0036] It should be noted that, in specific implementation scenarios, an adaptive texture feature selection mechanism can be developed based on the above solutions. This mechanism allows the system to automatically adjust the texture feature parameters used according to different types of vegetation, enhancing the generalization ability of the algorithm. Research should also be conducted on how to combine high-resolution satellite imagery with UAV-captured ground images to improve the accuracy of vegetation texture region judgment, especially in cases of complex vegetation types or severe background interference. Furthermore, the introduction of deep learning technology into the texture analysis process should be explored, enabling the model to autonomously learn the optimal texture feature representation without human intervention, thereby improving the system's intelligence level. Consideration should also be given to combining vegetation texture region judgment with other types of data (such as meteorological data and soil moisture information) to provide a more comprehensive crop health assessment service. Finally, a real-time monitoring and feedback mechanism should be designed to allow the system to dynamically adjust its texture analysis strategy based on the latest environmental changes, ensuring stable performance during long-term use.
[0037] The target value of the preprocessed image is determined by texture features.
[0038] Texture feature analysis can capture subtle but important differences between vegetated and non-vegetated areas, such as contrast, homogeneity, and energy, which are particularly important for accurate segmentation. First, texture features are extracted from the image, including the foreground (target vegetation) and background (such as sky, soil, and other vegetation). Then, through statistical analysis, a texture threshold is set for the target vegetation.
[0039] Vegetation texture region identification in preprocessed agricultural images refers to the process of analyzing the texture features (such as contrast, energy, directionality, and uniformity) of local image regions after preprocessing (denoising, contrast enhancement, and color correction). An empirical method is then used to determine the threshold for distinguishing target vegetation from the background (especially weeds with similar color characteristics to crops). This result is labeled at the pixel or region level, indicating which parts of the image possess vegetation-specific surface structure features, such as the regularity of leaf arrangement, surface roughness, or texture periodicity. This information is used to assist in subsequent fusion with a comprehensive vegetation feature map to generate a more accurate foreground mask.
[0040] For example, when processing a pre-processed image of a sugarcane field, the system calculates the contrast and energy characteristics of local areas of the image to identify strip-shaped regions with high contrast (distinct leaf edges) and medium energy (relatively uniform texture distribution). These regions closely match the vertical arrangement of the sugarcane plants and are thus identified as target vegetation texture regions. Soil or weed areas are excluded due to their messy texture, low contrast, or uneven energy distribution. The final output is a binary map that marks the spatial distribution of sugarcane plants, providing a basis for texture dimension decisions in subsequent mask generation.
[0041] Compared to thresholding methods, while machine learning algorithms such as random forests can also be used for texture feature classification, they have certain disadvantages in this scenario: firstly, the model requires a large number of labeled samples for training, otherwise it is prone to overfitting or insufficient generalization ability; secondly, machine learning algorithms have poor stability under different lighting conditions and different field environments, requiring frequent adjustments and retraining. In contrast, empirical thresholding methods require no additional training, have high computational efficiency, and are simple to adjust parameters, maintaining good robustness in most field scenarios. Therefore, this embodiment uses a combination of empirical thresholding and vegetation indices to achieve efficient removal of weed areas that are difficult to identify using vegetation indices.
[0042] It should be noted that, in specific implementation scenarios, based on the above solutions, a texture feature template library for different crop types can be constructed, enabling the system to automatically match the optimal texture judgment parameters according to the identified crop type (such as rice, wheat, and fruit trees); a multi-scale texture analysis mechanism can be introduced to extract texture features at different resolutions, improving adaptability to images of different plant sizes or at varying distances; by combining time-series images, the temporal stability of vegetation texture can be utilized to enhance judgment accuracy and reduce single-frame misjudgments; the combination of texture region judgment and spectral reflectance characteristics can be explored to form a "texture + color" dual-modal judgment mechanism, improving robustness against complex backgrounds; edge device deployment can be supported to achieve real-time texture region judgment in the field, accelerating the entire background removal process; and it can be extended to early disease identification scenarios.
[0043] The foreground mask is determined based on the comprehensive vegetation feature map and the target vegetation texture region determination results.
[0044] The color and texture features of vegetation index are combined to determine the foreground mask, improving the accuracy of background removal. A pixel is only considered foreground if both the combined vegetation feature map and texture feature show vegetation; otherwise, it is considered background.
[0045] As described above, determining the foreground mask based on the comprehensive vegetation feature map and the target vegetation texture region determination result involves spatially aligning and logically fusing the comprehensive feature map generated by the machine learning model by integrating multiple vegetation indices with the vegetation region determination result obtained from texture analysis. Weighted or logical operations are then used to determine whether each pixel belongs to the foreground vegetation, thereby generating an initial foreground mask. The comprehensive vegetation feature map provides the vegetation response intensity in the color and spectral dimensions, while the texture region determination result provides the credibility in the structural and surface detail dimensions. Combining the two can effectively suppress misjudgments in a single dimension, improving the accuracy and robustness of mask generation.
[0046] For example, when processing an image of a cornfield with uneven lighting, the integrated vegetation feature map might have a weak response in weed areas, causing some weeds to be misidentified as corn plants. However, the texture region determination result, because it recognizes the messy texture features of the weeds, can still accurately label these areas as background. Through a fusion mechanism, although the integrated vegetation feature map retains the weeds, the final generated foreground mask removes the weed areas by applying a texture feature threshold, thus avoiding the omission problem of traditional methods in the presence of weeds.
[0047] It should be noted that, in specific implementation scenarios, an adaptive fusion weighting mechanism can be designed based on the above scheme to dynamically adjust the fusion ratio of the comprehensive feature map and texture results according to the image lighting conditions or crop type; a spatial context awareness module can be introduced to optimize the mask boundary by combining the vegetation continuity of neighboring pixels; multi-temporal image fusion can be supported, and the temporal stability of vegetation texture can be used to correct single-frame misjudgments; a lightweight fusion algorithm for mobile devices can be developed to achieve real-time generation of foreground masks on field equipment; it can be extended to the disease and pest area recognition scenario, and the accurate delineation of diseased areas can be achieved by jointly judging texture anomalies and vegetation index anomalies; and geofencing or crop planting maps can be combined to spatially constrain the fusion results, further improving the spatial consistency and agricultural practicality of the mask in the field environment.
[0048] The foreground mask is morphologically processed to obtain an optimized foreground mask; As described above, the foreground mask is optimized by performing morphological operations (such as erosion to remove small-area noise and expansion to smooth the boundaries) to obtain an optimized foreground mask with clear boundaries, complete regions, and no interference.
[0049] For example, when processing an image of a cotton field mixed with weeds, some weeds may be identified as cotton and some cotton may be identified as background. An erosion operation is performed to remove isolated weed points in the mask, and then a dilation operation is used to fill the tiny cavities inside the cotton plants. The resulting optimized foreground mask accurately delineates the cotton area while effectively excluding the weed background, ensuring the accuracy of subsequent background removal.
[0050] It should be noted that, in specific implementation scenarios, an adaptive texture feature selection mechanism based on vegetation type can be developed on the basis of the above solution. This would enable the system to automatically optimize the analysis parameters of contrast and energy characteristics according to different crops such as cotton and rice; dynamically adjust the sensitivity of texture feature analysis by combining real-time meteorological data (such as wind speed and humidity) to improve the processing effect under adverse weather conditions; explore the combination of texture feature analysis with deep learning models to achieve automatic refinement of mask boundaries; design an adaptive parameter library for farmland environment to preset the optimal morphological processing strategy according to soil type and crop variety; and extend this technology to scenarios such as orchard disease identification and grassland vegetation coverage monitoring, achieving efficient cross-domain applications through the core texture feature optimization and morphological processing mechanism.
[0051] Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image. As described above, removing the background from the original RGB format agricultural image based on the optimized foreground mask involves using the high-quality foreground mask obtained after texture analysis and morphological processing as a spatial selection criterion to filter pixels in the original color image. Specifically, only the original image pixels corresponding to the areas marked as "foreground" in the mask are retained, while the areas marked as "background" in the mask are made transparent or have a uniform background color in the output image, thereby effectively removing complex backgrounds. This step is the final execution stage of the entire background removal process, and its result is the target vegetation image, i.e., a clean image containing only crops, plants, and other objects of interest while retaining their original color information. This image can be used for subsequent agricultural image analysis tasks such as accurate identification, area calculation, and growth status assessment.
[0052] For example, when processing an aerial image of a cornfield, after the aforementioned multi-index fusion, texture feature threshold segmentation, comprehensive judgment, and mask optimization, a clear and noise-free foreground mask is obtained, accurately delineating the distribution area of all corn plants. Based on this mask, the system completely preserves the pixels located within the foreground area of the original RGB image, faithfully restoring the color and texture of the corn leaves; while areas marked as background, such as soil, bare ground, roads, or sky, are set to transparent or black backgrounds in the output image. The final generated target vegetation image contains only complete corn plants, facilitating subsequent plant counts, canopy coverage analysis, or disease area detection, significantly improving the accuracy and efficiency of agricultural automation analysis.
[0053] It should be noted that, in specific implementation scenarios, based on the above solution, multiple output formats (such as PNG images with transparency channels or geocoded TIFF images) can be supported to adapt to different downstream application needs; a region labeling function can be introduced to automatically add numbered or classified tags to different vegetation objects while removing the background, achieving image-level semantic output; combined with time-series image processing capabilities, background removal can be performed in batches on continuously captured farmland images to generate dynamic vegetation change atlases; it can be extended to 3D or multi-view image fusion scenarios, using optimized masks from multiple angles to reconstruct the three-dimensional structure of vegetation; it supports integration with agricultural management platforms or intelligent agricultural machinery systems, allowing target vegetation images to be directly used for smart agriculture operations such as variable fertilization and precision spraying. In addition, the deployment of this background removal process on edge computing devices can be explored to achieve rapid acquisition of clean vegetation images in the field, improving the real-time performance and practicality of the overall system.
[0054] According to one embodiment of this application, the image preprocessing includes denoising, contrast enhancement, and color correction of the image. As mentioned above, in the image preprocessing stage, to improve the accuracy of subsequent vegetation identification and background removal, the original RGB image is first denoised. Denoising aims to eliminate unwanted noise components in the image, such as sensor noise or random noise introduced during transmission, to avoid these noises affecting vegetation index calculation and machine learning model judgment. Denoising methods can include, but are not limited to, mean filtering, median filtering, or more advanced directionality-based denoising algorithms.
[0055] Secondly, contrast enhancement aims to improve the differentiation between different regions in an image, making vegetation and non-vegetated areas more clearly distinguishable. For agricultural images, this step helps to strengthen the color characteristics of vegetation, allowing vegetation indices to more accurately reflect vegetation status. Contrast enhancement can be achieved through techniques such as histogram equalization and adaptive contrast enhancement, ensuring high-quality image information even under poor lighting conditions.
[0056] Finally, color correction is used to correct color deviations caused by factors such as the characteristics of the shooting equipment and changes in ambient light, ensuring consistent color representation in images acquired under different conditions. This is crucial for vegetation index calculations that rely on color information, as color consistency directly affects the effectiveness of separating vegetation from the background. The color correction process may involve steps such as white balance adjustment and reference-based color calibration, thereby ensuring the authenticity and comparability of image colors. Through this series of preprocessing operations, a foundation is laid for subsequent accurate vegetation analysis and background removal.
[0057] According to one embodiment of this application, the plurality of vegetation indices include ExG, CIVE, and NGRDI, and the calculation of the plurality of vegetation indices is based on automatically selecting an applicable combination of vegetation indices according to the image lighting environment.
[0058] As mentioned above, the multiple vegetation indices include ExG (Extreme Green Enhancement Index), CIVE (Color Index Vegetation Extraction), and NGRDI (Normalized Green-Red Difference Index). These indices utilize different mathematical combinations of the red, green, and blue channels in the image to highlight the differences between vegetation areas and the background. ExG responds strongly to green vegetation and is suitable for scenes with ample light and vivid vegetation colors; CIVE is robust to changes in light intensity and is suitable for use under low light or uneven lighting conditions; NGRDI is sensitive to relative changes in the green and red channels and is suitable for transitional scenes where vegetation is partially yellowed or has withered leaves.
[0059] In actual processing, the system first analyzes the lighting environment of the preprocessed image to determine whether it falls into categories such as "sufficient lighting," "insufficient lighting," or "uniform lighting." The criteria for this determination include the overall average brightness of the image, the proportion of highlight areas, and the density of shadow distribution. Based on the results, the system automatically selects the most suitable combination of vegetation indices for the current lighting conditions: for example, the ExG index is prioritized in bright, sunny conditions; the CIVE index is used in cloudy or low-light conditions; and the NGRDI index is used in environments with uniform lighting but complex vegetation color variations. The system can also use multiple indices simultaneously, but their contribution ratios in the subsequent fusion model will be adjusted according to environmental weights.
[0060] By automatically selecting vegetation index combinations based on the lighting environment, the problem of a single index failing under specific lighting conditions is avoided, making vegetation feature extraction more adaptable and stable, thus providing a more reliable data foundation for subsequent machine learning fusion and foreground mask generation.
[0061] According to one embodiment of this application, the adaptive lighting condition determination is based on the brightness distribution and contrast analysis of the image, and three states: excessive lighting, insufficient lighting or shadow, and uniform lighting. When the lighting is excessive, it is determined that the brightness is higher than a preset threshold and the color temperature is within a reasonable range.
[0062] As described above, the adaptive lighting condition determination refers to the system automatically analyzing the lighting characteristics of the image after image preprocessing to determine whether the current shooting environment belongs to one of the three states of "sufficient lighting", "insufficient lighting" or "uniform lighting", thereby providing a basis for the subsequent selection of vegetation index and parameter adjustment.
[0063] The judgment process is mainly based on two core indicators: first, the brightness distribution of the image, which assesses the overall brightness and illumination uniformity by calculating the average brightness, brightness standard deviation and highlight / shadow pixel ratio of the entire image or segmented areas; second, color temperature analysis, which estimates the color temperature value of the current ambient light source by extracting the RGB ratio of white or neutral areas in the image, and determines whether there is a color cast that is too warm (such as dusk) or too cool (such as cloudy).
[0064] The specific judgment rules are as follows: If the average brightness of the image is higher than the preset threshold (e.g., 120 grayscale value) and the color temperature falls within the standard daylight range (e.g., 5000K–6500K), it is judged as "sufficient lighting"; if the average brightness is lower than the preset lower limit (e.g., 60 grayscale value), or the proportion of highlight areas is extremely low and the shadow areas are dense, it is judged as "insufficient lighting"; if the image brightness distribution is uniform (small standard deviation), there are no obvious overexposed or underexposed areas, and the color temperature is stable, it is judged as "uniform lighting".
[0065] The determination result directly affects the subsequent vegetation index selection strategy. For example, under "sufficient light," the ExG index, which is sensitive to green, is prioritized; under "insufficient light," the CIVE index, which has strong anti-interference capabilities, is switched to; and under "uniform light," the NGRDI index, which is sensitive to color changes, is used. Through this adaptive determination mechanism based on the actual lighting environment, the system can dynamically optimize the feature extraction path and improve the stability and accuracy of vegetation identification under different shooting conditions.
[0066] According to one embodiment of this application, the vegetation texture region determination is based on the extracted contrast, energy, and homogeneity features of the image, wherein the contrast is used to identify the edge differences between vegetation and the background.
[0067] As described above, the vegetation texture region determination is achieved by extracting texture features through calculating the gray-level co-occurrence matrix (GLCM) of the image, mainly using two key indicators: contrast and energy, to distinguish vegetation regions from non-vegetation backgrounds.
[0068] Contrast ratio reflects the degree of difference in pixel grayscale values within a local area of an image; a higher value indicates a coarser texture and more pronounced edges. In agricultural images, vegetation leaves typically have clear vein structures and edge contours, creating a striking contrast with relatively smooth or cluttered backgrounds (such as soil, sky, or withered grass). Therefore, by calculating the contrast ratio of different regions in the image, the system can identify areas with typical vegetation edge features, thus helping to determine which areas are more likely to belong to the target vegetation.
[0069] Energy reflects the uniformity or regularity of image texture; a higher value indicates a more concentrated local grayscale distribution and a more uniform texture. Vegetated areas (such as dense foliage) often exhibit higher energy values because their surface structure is repetitive and consistent within a local area; while background areas (such as weeds, gravel, or shadows) typically have lower energy and a chaotic texture. Therefore, energy features are used to help confirm the coherence and stability of areas within vegetation.
[0070] The system integrates two features, contrast and energy, to perform region-by-region analysis on the preprocessed image, generating target vegetation texture region determination results. These results mark regions that simultaneously meet the conditions of "high contrast (clear edges)" and "high energy (uniform texture)" in pixel-level or block-level format. These regions are considered high-confidence areas of vegetation presence, providing structured texture information for subsequent fusion with the comprehensive vegetation feature map to generate a foreground mask. This improves segmentation accuracy and reduces false positives and false negatives.
[0071] According to one embodiment of this application, the determination of the foreground mask is based on adaptive thresholding processing of the integrated vegetation feature map, and the threshold range is dynamically determined according to the image brightness distribution and vegetation feature density.
[0072] As mentioned above, image brightness distribution analysis involves the following steps: First, the system performs statistical analysis on the brightness (grayscale value) distribution of the input image, which can be done by calculating a histogram. The histogram provides information about the number of pixels at different brightness levels in the image, helping to understand the overall brightness of the image.
[0073] Vegetation Feature Density Assessment: Next, the system considers the feature density of vegetation in the image. These features may include information such as color and texture. For vegetation, green hue and specific texture patterns are important features. By analyzing the distribution of these features, the relative density of vegetation in the image can be estimated.
[0074] Adaptive Threshold Determination: Based on the information obtained in the above two steps, the system will automatically select one or a series of thresholds. This process may be based on a preset algorithm or rule, such as the Otsu method, a commonly used adaptive threshold selection technique that can automatically select the optimal threshold based on the image's grayscale histogram. For vegetation segmentation tasks, the selection of the threshold also needs to take into account the differences in brightness and features between vegetation and non-vegetation areas to ensure that vegetation can be effectively separated while minimizing the possibility of missegmentation.
[0075] Generating a foreground mask: Once an appropriate threshold range is determined, it can be applied to the composite vegetation feature map to generate a foreground mask. This mask is a binary image where vegetation is marked as the foreground (usually white or highlighted), while non-vegetation areas are marked as the background (usually black or dark). Such a mask can be directly used for subsequent image processing operations, such as cropping, enhancement, or analysis.
[0076] Through this adaptive approach, the system can more flexibly and accurately identify vegetation under different lighting conditions and background environments, improving the robustness and accuracy of vegetation segmentation.
[0077] According to one embodiment of this application, the texture feature analysis includes extracting the contrast and energy GLCM features of the image, and the morphological processing includes an erosion operation to remove small-area noise and a dilation operation to process mask boundaries.
[0078] As mentioned above, in texture feature analysis, the Gray-Level Co-occurrence Matrix (GLCM) is a commonly used statistical method for describing texture. By calculating the GLCM, we can obtain various parameters describing the texture characteristics of an image, including: Contrast Contrast reflects the intensity of local gray-level changes in an image, that is, the degree of gray-level difference between a pixel and its neighboring pixels. High contrast means a large difference in gray levels, usually corresponding to edges or areas with rich detail in an image; while low contrast indicates a gentle gray-level change, suitable for describing uniform or smooth surfaces. In applications involving vegetation and background segmentation, contrast can help distinguish vegetation boundaries from the background, especially at the boundaries between vegetation and soil or other non-vegetation elements.
[0079] Calculation formula:
[0080] Where p(i,j) is the probability value at position j in row i of the GLCM matrix. It refers to the grayscale level.
[0081] Energy Energy, also known as the angular second moment, measures the concentration or consistency of the element distribution in a GLCM matrix. Higher energy values indicate more repeating patterns in the matrix, suggesting high consistency and smoothness within the image region; conversely, lower energy values indicate more random noise or complex texture structures. For vegetation segmentation, energy features help identify stable and consistent vegetation regions and aid in optimizing the boundaries of these regions.
[0082] Calculation formula:
[0083] These features help identify different types of surfaces or materials, because different textures tend to have different GLCM properties.
[0084] Morphological processing is primarily used for shape analysis and improving the quality of binary images. It includes a series of operations, the most fundamental of which are erosion and dilation: Erosion operation: Used to remove small areas of noise and refine foreground objects in an image. Simply put, erosion shrinks the foreground area (white parts), thereby eliminating small white dots, i.e., noise, that are smaller than the structuring element.
[0085] Dilation: In contrast to erosion, dilation expands the foreground area, helping to fill small holes inside objects, connect neighboring objects, and smooth the outlines of objects. For mask boundary processing, dilation can help correct edge discontinuities or breaks caused by preprocessing (such as thresholding).
[0086] Combining erosion and dilation can effectively improve the quality of binarized images. For example, opening operations (erosion followed by dilation) can be performed to denoise, or closing operations (dilation followed by erosion) can be performed to fill holes. These processing steps are crucial for subsequent image analysis tasks (such as object detection or classification) because they help improve the accuracy and reliability of the algorithm.
[0087] A second aspect of this application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the method described in any of the embodiments of the first aspect above.
[0088] Figure 2 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 2As shown, the electronic device may include: a processor 810, a communication interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communication interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 may call logical instructions in the memory 830 to execute the method in any of the embodiments of the first aspect described above, the method including: Obtain the original RGB format agricultural image, and perform image quality detection and preprocessing on the agricultural image; Multiple vegetation indices are calculated for each pixel in the agricultural image, and multiple vegetation index feature maps are generated. The multiple vegetation index feature maps are input into a machine learning model, which learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map. Based on the comprehensive vegetation feature map, adaptive thresholding is performed to generate an initial foreground mask; The initial foreground mask is subjected to texture feature analysis and morphological processing to obtain an optimized foreground mask; Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image.
[0089] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory, random access memory, magnetic disks, or optical disks.
[0090] On the other hand, the present invention also provides a computer program product, the computer program product comprising a computer program, the computer program being able to be stored on a non-transitory computer-readable storage medium, and when the computer program is executed by a processor, the computer being able to perform the methods provided by the above methods, the method comprising: Obtain the original RGB format agricultural image, and perform image quality detection and preprocessing on the agricultural image; Multiple vegetation indices are calculated for each pixel in the agricultural image, and multiple vegetation index feature maps are generated. The machine learning model inputs the multiple vegetation index feature maps and learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map. Based on the comprehensive vegetation feature map, adaptive thresholding is performed to generate an initial foreground mask; The initial foreground mask is subjected to texture feature analysis and morphological processing to obtain an optimized foreground mask; Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image.
[0091] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the methods provided by the above methods, the method comprising: Obtain the original RGB format agricultural image, and perform image quality detection and preprocessing on the agricultural image; Multiple vegetation indices are calculated for each pixel in the agricultural image, and multiple vegetation index feature maps are generated. The multiple vegetation index feature maps are input into a machine learning model, which learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map. Based on the comprehensive vegetation feature map, adaptive thresholding is performed to generate an initial foreground mask; The initial foreground mask is subjected to texture feature analysis and morphological processing to obtain an optimized foreground mask; Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image.
[0092] Example 2 As shown in Figures 3(a), 3(b), 3(c), and 3(d), Step (1): Image acquisition. Acquire images of maize plants in the field under different environments. Step (2): Image preprocessing. The cv2.xphoto function is used to adjust the white balance of all images to reduce color cast caused by color temperature differences between different cameras; the RGB channels of the images are normalized to reduce the influence of brightness on color, so that each channel maintains a stable relative proportion under different lighting conditions, providing a reliable foundation for subsequent color feature extraction and background removal.
[0093]
[0094]
[0095]
[0096] R, G, and B are the pixel values of the red, green, and blue channels, respectively, while R′, G, and B′ are normalized channel values with a range of [0, 255].
[0097] Step (3): Illumination feature extraction. First, extract the average brightness (L_mean), local contrast (Contrast_local), and shadow ratio (Shadow_ratio) of the image.
[0098] Average brightness calculation: The image is converted to grayscale, and the average grayscale value is calculated as the overall brightness index of the image.
[0099]
[0100] in, Let be the grayscale value of the i-th pixel, and N be the total number of pixels in the image. This metric is used to characterize the overall brightness and darkness of the image.
[0101] Local contrast calculation: Using a sliding window or local neighborhood method, the brightness standard deviation of each local region is calculated, and the local standard deviations of the entire image are averaged to obtain the local contrast.
[0102]
[0103] Let be the standard deviation of the brightness of the j-th local window, and M be the total number of windows. This index reflects the degree of local brightness variation in an image and helps in analyzing texture sharpness and detail saliency.
[0104] Shadow ratio calculation: The percentage of pixels with gray values below a preset threshold in the image is used as the shadow ratio indicator.
[0105]
[0106] in, This is the shadow detection threshold, with a value of 50. This metric is used to characterize the proportion of dark or shadowed areas in an image.
[0107] Step (4): Adaptive Light Condition Judgment. Based on the average brightness, local contrast, and shadow ratio characteristics of the image, the lighting category of the target image is automatically determined, thereby classifying the image into over-illuminated, under-illuminated, or uniformly lit and shadowed types. See Table 1 below for details. Table 1 Image Classification Table
[0108] Step (5): Image annotation. The annotation operation is performed in the Python programming environment by calling the `cv2.selectROI` function of the OpenCV library. Specifically, the user manually selects the target region in the displayed image window, and the software records the coordinates of the selected rectangle in real time. During the annotation process, corn plants are labeled as the first category, and background areas such as soil, sky, and weeds are labeled as the second category. For different lighting conditions, images with excessive light, insufficient light, shadow coverage, and uniform lighting are selected, with approximately 50 samples in each category. This ensures that the dataset covers a variety of typical shooting scenarios, possessing diversity and representativeness, and can be used to construct a training dataset to support the model classification task.
[0109] Step (6): Adaptive Vegetation Index Selection and Calculation. Based on the illumination classification, only three typical and optimal indices for the corresponding scene are calculated, reducing computational load while improving model accuracy and generalization. VARI, NGRDI, and RGBVI strongly respond to green vegetation and are suitable for scenes with sufficient light and vibrant vegetation colors; CIVE, ExGR, and MExG are robust to illumination changes and suitable for use in low light or uneven illumination conditions; ExG, GLI, and TGI are sensitive to relative changes in the green and red channels and are suitable for scenes with uniform vegetation illumination. See Table 2 below for details. Table 2 Vegetation Index Table
[0110] Step (7): Model Construction. Based on the category labels of the above-mentioned labeled areas and the vegetation indices of the corresponding categories, a random forest algorithm is used for supervised learning to construct a background removal model. After adaptive lighting condition judgment, the model can automatically determine whether the area belongs to the target vegetation or the background, achieving effective segmentation of the target in the image and background removal. By analyzing the importance of features, the model can make full use of the discriminative power of each vegetation index and texture feature, thereby improving the accuracy and robustness of background removal.
[0111] Step (8): Texture feature calculation.
[0112] To quantify the texture differences between the target region and the background in an image, the original color image was first converted to grayscale for texture analysis. Then, the gray-level co-occurrence matrix (GLCM) method was used to calculate local texture features within each predefined sliding window. The main extracted texture metrics included contrast, energy, and homogeneity. These measures the strength of pixel grayscale differences, reflecting the coarseness of local texture; the uniformity or repetition of grayscale distribution (higher values indicate more regular texture); and the similarity of grayscale values, reflecting the smoothness within the region.
[0113]
[0114]
[0115]
[0116] in, The elements of the normalized gray-level co-occurrence matrix represent the co-occurrence probability of gray values i and j within the sliding window.
[0117] Step (9): Target texture region determination.
[0118] Since vegetation index calculations have effectively removed most of the land and sky backgrounds with significant color differences from the image, only some weed areas remain that are difficult to distinguish. Considering the significant differences in texture features between corn plants and weeds—corn leaves have a relatively uniform overall texture and strong directionality, while weeds, due to their fine and densely distributed leaves, exhibit greater complexity and local variations in texture—this embodiment introduces a texture feature discrimination method based on empirical thresholds during the weed removal process.
[0119] Among them, the energy value of the corn leaf area is usually higher (reflecting strong uniformity), while the entropy and contrast values of the weed area are significantly larger (reflecting strong texture complexity). Therefore, based on experience, the following thresholds are set: (1) When the entropy of the candidate area is greater than 4.5 and the contrast is greater than 20, it is judged as a weed area and removed; when the contrast of the candidate area is ≥20 and the energy is ≤=0.20 or the homogeneity is ≤0.55, it is judged as a weed area and removed; if only a single indicator is triggered, but it is close to the threshold boundary, the area is marked as "to be reviewed" and handed over to morphological post-processing (opening / closing operation + area filtering) or subsequent small model fine judgment.
[0120] In comparison, while machine learning algorithms such as random forests can also be used for texture feature classification, they have certain disadvantages in this scenario: firstly, the model requires a large number of labeled samples for training, otherwise it is prone to overfitting or insufficient generalization ability; secondly, machine learning algorithms have poor stability under different lighting conditions and different field environments, requiring frequent adjustments and retraining. The empirical threshold method, on the other hand, requires no additional training, has high computational efficiency, and simple parameter adjustment, maintaining good robustness in most field scenarios. Therefore, this embodiment adopts a method combining empirical thresholds and vegetation indices to achieve efficient removal of weed areas.
[0121] Step (10): For each candidate region, firstly, vegetation indices are used to determine whether it possesses the green characteristics of corn plants. Then, texture features (contrast, energy, homogeneity, or entropy) are used to determine whether its texture conforms to the regularity of corn leaves. Based on this, only when a candidate region simultaneously meets the corn determination criteria in both vegetation indices and texture features is it marked as foreground; otherwise, it is considered background and removed. This dual-determination strategy utilizes both the strong distinguishing ability of vegetation indices against backgrounds (such as land and sky) and the further weed-removing ability of texture features, thereby generating a high-precision corn plant foreground mask, providing a reliable foundation for subsequent morphological processing or feature extraction.
[0122] Step (11): Post-processing. To further optimize the background removal effect, morphological processing is performed on the preliminary segmentation results output by the random forest model. Specifically, the opening operation is used to remove small non-plant regions in the segmentation results, thereby eliminating noise and isolated small patches; then the closing operation is used to fill small holes or gaps in the plant regions, making the segmentation results continuous and complete, improving the integrity and accuracy of the target region, and thus providing a high-quality image foundation for subsequent phenotypic analysis or feature extraction.
[0123] Thresholding background removal: Green vegetation areas are extracted using the 'a' channel of the LAB color space, and non-green backgrounds are set to white, thus generating an image that retains only the plants in the foreground. However, weeds in the area marked by the red box cannot be removed, and the silks of the corn ears are judged as background.
[0124] Single Vegetation Index: By calculating the Single Vegetation Index (NDVI, Normalized Difference Vegetation Index), and labeling it (consistent with the labeling in the example), a machine learning algorithm is used to distinguish between vegetated and non-vegetated areas, thus removing the background and retaining only the vegetation foreground. However, the highlighted corn area within the red box is judged as background.
[0125] For any parts not mentioned in this application, existing technologies may be used or referenced.
[0126] The various embodiments in this specification are described in a progressive manner. The same or similar parts between the various embodiments can be referred to each other. Each embodiment focuses on describing the differences from other embodiments.
[0127] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.
Claims
1. A method for removing background from agricultural images, characterized in that, include: The process involves acquiring raw RGB format agricultural images, performing image preprocessing on the agricultural images, and then performing adaptive illumination condition determination on the preprocessed agricultural images. Based on the light conditions determination results, the corresponding vegetation indices are calculated and selected, and multiple vegetation index feature maps are generated. Multiple vegetation index feature maps are input into a machine learning model, which learns the relative importance of each vegetation index to generate a comprehensive vegetation feature map. Vegetation texture regions are determined from the preprocessed agricultural images to obtain the target vegetation texture region determination results; The foreground mask is determined based on the integrated vegetation feature map and the target vegetation texture region determination result. The foreground mask is then morphologically processed to obtain the optimized foreground mask. Based on the optimized foreground mask, the background is removed from the original RGB format agricultural image to obtain the target vegetation image.
2. The method according to claim 1, characterized in that, The image preprocessing includes denoising, contrast enhancement, and color correction.
3. The method according to claim 1, characterized in that, The multiple vegetation indices include ExG, CIVE, and NGRDI, and the calculation of the multiple vegetation indices is based on the automatic selection of applicable vegetation index combinations according to the image lighting environment.
4. The method according to claim 1, characterized in that, The adaptive lighting condition determination is based on the brightness distribution and contrast analysis of the image. The determination results include three states: excessive strong light, insufficient light or shadow, and uniform lighting. When the light is excessive, it is determined that the brightness is higher than the preset threshold and the color temperature is within a reasonable range.
5. The method according to claim 1, characterized in that, The vegetation texture region determination is based on the extracted image's contrast, energy, and homogeneity features, where contrast is used to identify the edge differences between vegetation and the background.
6. The method according to claim 1, characterized in that, The determination of the foreground mask is based on the adaptive thresholding processing of the integrated vegetation feature map, and the threshold range is dynamically determined according to the image brightness distribution and vegetation feature density.
7. The method of claim 1, wherein the morphological processing includes an erosion operation to remove small-area noise and an dilation operation to process mask boundaries.
8. A computer-readable storage medium having a program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the method as described in any one of claims 1-7.
9. An electronic device comprising a memory, a processor, and a program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method as described in any one of claims 1-7.
Citation Information
Patent Citations
Crop classification method fusing multi-source geographic information data
CN113901966A
Cotton early planting area identification method and system, electronic equipment and medium
CN117475316A
Vegetation coverage observation method based on multiple exposure of phenological camera
CN119942338A
Remote sensing image vegetation coverage prediction method and system based on deep learning
CN120388291A
A Monitoring And Evaluation Method For Comprehensive Evaluation Index Of Machine-Harvested Cotton Defoliation Effect And System Thereof
US20240404045A1
Cited By
Noise processing method and device based on visual tactile sensor, equipment and medium
CN121640071A
Remote sensing image classification labeling method based on color space conversion
CN122473660A