A multi-weight farmland plot extraction method, device and medium based on improved HRNet
By improving the SPHRNet algorithm of HRNet and combining feature fusion and broken line connection technology, the problems of weak edge discontinuity and broken lines in farmland plot extraction are solved, achieving efficient and accurate farmland plot identification and improving the effect of farmland plot extraction.
Patent Information
- Application Number
- CN202510436442.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-09
- Publication Date
- 2025-12-05
- Estimated Expiration
- 2045-04-09
AI Technical Summary
Existing HRNet-based farmland plot extraction algorithms suffer from discontinuous and broken edge extraction when processing high-resolution remote sensing data, making it difficult to simultaneously and accurately extract farmland surface and farmland outline features, thus affecting the accuracy and continuity of farmland plot extraction.
An improved HRNet method is adopted, which enhances the feature representation capability by constructing the SPHRNet semantic segmentation algorithm model and combining strip pooling and hybrid pooling modules. Mathematical morphology and topological constraints are used to connect broken lines of farmland contours to optimize the farmland plot extraction process.
It significantly improves the continuity and accuracy of weak edge extraction of arable land, solves the problem of broken lines in arable land outlines, enhances the integrity and recognition accuracy of arable land plot extraction, and supports precision agriculture and land management.
Smart Images

Figure CN120612585B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of farmland plot extraction technology in remote sensing image processing, and in particular to a multi-weighted farmland plot extraction method, device and medium based on an improved HRNet. Background Technology
[0002] With the advancement of agricultural modernization, the accurate, rapid, and efficient identification and extraction of arable land plots is of significant practical importance for land management and agricultural planning. Traditional methods for identifying arable land plots mainly rely on remote sensing image processing technology. However, these methods are inefficient when processing high-resolution remote sensing data and have poor adaptability to complex farmland environments (weak edge extraction). The accuracy of weak edge extraction directly affects the accuracy and reliability of arable land plot extraction.
[0003] In recent years, with the development of remote sensing and deep learning technologies, especially in the field of high-resolution remote sensing image recognition, significant technological progress has been made. Convolutional Neural Networks (CNNs) have demonstrated superior performance in tasks such as image classification and segmentation. However, existing deep learning-based methods for identifying farmland plots still have certain limitations, such as discontinuities and broken lines in weak edge contour extraction, and insufficient accuracy in extracting farmland plot edges. The HRNet algorithm is a highly efficient and accurate deep learning algorithm that performs well in multi-scale feature fusion; however, existing HRNet-based farmland plot extraction algorithms still suffer from the following technical shortcomings:
[0004] (1) When extracting weak edges of cultivated land, HRNet often leads to discontinuous edge extraction and broken lines due to its lack of ability to capture long-distance dependencies, which affects the accurate identification of cultivated land plots. (2) The cultivated land plot extraction algorithm based on single multi-class HRNet is difficult to extract cultivated land surface and cultivated land contour features accurately at the same time, and it is difficult to fit cultivated land surface and cultivated land contour efficiently at the same time during model training. (3) In the cultivated land contour extraction of the cultivated land plot extraction algorithm based on HRNet, the cultivated land contour is often discontinuous due to the limitations of model generalization and training fitting, which greatly affects the effect of cultivated land plot extraction.
[0005] For example, invention application No. 202310337060.1 discloses a multi-scale strong fusion semantic segmentation method for remote sensing image feature extraction based on HRNet. This method utilizes the HRNet network for semantic segmentation of remote sensing images, improving feature extraction capabilities and making feature extraction results more accurate. However, this method also has limitations. It does not optimize for farmland plot extraction. When extracting weak edges, HRNet often suffers from discontinuous and broken edges due to its lack of ability to capture long-distance dependencies, affecting the accurate identification of farmland plots. Furthermore, it is difficult to accurately extract farmland surface and contour features, leading to discontinuous contour extraction.
[0006] For the reasons mentioned above, a multi-weighted farmland plot extraction method based on an improved HRNet is needed. This method enhances the model's ability to extract weak farmland edges, enabling it to better identify and connect broken edges, thereby improving the continuity and accuracy of weak farmland plot edge extraction. Summary of the Invention
[0007] To address the aforementioned problems, the present invention aims to provide a multi-weighted farmland plot extraction method, device, and medium based on an improved HRNet, which enhances the ability to extract weak edges of farmland, optimizes the extraction effect of farmland plots, and improves the continuity and accuracy of weak edge extraction of farmland plots.
[0008] This invention provides a method, device, and medium for extracting multi-weighted farmland plots based on an improved HRNet.
[0009] First aspect: A multi-weighted farmland parcel extraction method based on an improved HRNet, including:
[0010] S1. Based on high-resolution farmland remote sensing images, manually label the farmland surface and farmland outline to obtain a three-class farmland surface dataset and a two-class farmland outline dataset.
[0011] S2. Construct an HRNet semantic segmentation algorithm model for farmland extraction and an SPHRNet semantic segmentation algorithm model for farmland outline extraction. Based on the farmland dataset and farmland outline dataset, perform weight training and testing on HRNet and SPHRNet respectively, and obtain the weights of HRNet and SPHRNet after training and testing.
[0012] S3. Using the weights of HRNet and SPHRNet after training and testing, extract the grayscale images of three-classified cultivated land and two-classified cultivated land outlines from the regional remote sensing images.
[0013] S4. Optimize the grayscale map of the three-category cultivated land and the grayscale map of the outline of the two-category cultivated land to obtain the optimized coarse outline of cultivated land.
[0014] S5. Refine and disconnect the optimized coarse outline of cultivated land to obtain the optimized fine outline of cultivated land, and use the optimized fine outline of cultivated land to extract the raster map of cultivated land plots.
[0015] S6. After processing the obtained farmland plot raster map, convert it into a vector map, and obtain the farmland plot vector map based on the vector boundary map.
[0016] Further, S1 includes the step of:
[0017] S11. The first three bands of the high-resolution remote sensing image of cultivated land are acquired and stretched into an 8-bit image;
[0018] S12. Manually annotate the stretched image to obtain the cultivated land vector, and convert the cultivated land vector into the cultivated land outer contour vector without subdividing weak edges.
[0019] S13. Convert the cultivated land vector to a raster and set the value to 1. Convert the cultivated land outline vector to a raster and set the value to 2. Set the background value to 0 to obtain a three-classified cultivated land raster map.
[0020] S14. Based on the outer contour vector of cultivated land, mark the inner contour dividing lines of weakly edged cultivated land plots to obtain a cultivated land contour vector map.
[0021] S15. Convert the farmland outline vector image to a raster image, set the background value to 0, expand the outline by 4 pixels and set the value to 1 to obtain a two-classified farmland line raster image.
[0022] S16. Obtain the three-category cultivated land dataset and the two-category cultivated land outline dataset based on the three-category cultivated land raster map and the two-category cultivated land line raster map.
[0023] Furthermore, the SPHRNet semantic segmentation algorithm model structure includes:
[0024] After each downsampling in HRNet, an SPM module is added to capture features at different scales and enhance the expressive power of the features.
[0025] After the hierarchical feature extraction is completed, the output features of each layer are fused together, and the final feature map fusion is performed through the MPM module.
[0026] Furthermore, the SPM module's data processing procedure includes:
[0027] S21. Input the feature map into two parallel adaptive average pooling functions respectively, so that the feature map is pooled into the form of H×1 and 1×W;
[0028] S22. Interpolate the pooled feature map using an interpolation function to restore it to the same spatial dimension as the input feature map;
[0029] S23. The interpolated feature maps are fused along the horizontal and vertical directions to obtain a feature map that integrates horizontal and vertical information.
[0030] S24. The fused feature map is passed through a 1×1 convolutional layer and a sigmoid activation function, and then element-wise multiplied with the original input feature map to obtain the output feature map.
[0031] Furthermore, the weighted testing of HRNet and SPHRNet in S2 uses the mean intersection-union ratio (mIoU), recall (R), and overall precision (OA), expressed by the following formula:
[0032]
[0033] Where TP is the number of positive classes correctly classified, FP is the number of positive classes misclassified, FN is the number of negative classes misclassified, and TN is the number of negative classes classified.
[0034] Further, in step S4, the grayscale images of the three-category cultivated land and the grayscale images of the outlines of the two-category cultivated land are optimized to obtain optimized coarse outlines of the cultivated land. The steps include:
[0035] S41. All pixels with a value of 1 in the grayscale image of the three-category cultivated land are assigned a value of 0, and the pixels with a value of 2 are expanded by 4 pixels to obtain the outer contour image of the two-category cultivated land.
[0036] S42. Add the pixel values of the outer contour map of the two-category cultivated land and the grayscale map of the two-category cultivated land contour line, and assign all values above 1 to 1 to obtain the optimized coarse contour line of cultivated land.
[0037] Further, in step S5, the optimized coarse outline of cultivated land is refined and broken to obtain the optimized fine outline of cultivated land. The optimized fine outline of cultivated land is then used to extract a raster map of cultivated land plots. This includes the following steps:
[0038] S51. Perform morphological closing operation optimization on the rough outline of cultivated land to remove holes in the rough outline of cultivated land.
[0039] S52. Skeletonize the optimized coarse outline of cultivated land to obtain the fine outline of cultivated land.
[0040] S53. Detect the breakpoints in the fine outline of cultivated land and draw straight lines to connect the breakpoints to obtain the optimized fine outline of cultivated land.
[0041] S54. Set all pixels with a value of 2 in the grayscale image of the three-category cultivated land to 0 to obtain the image of the two-category cultivated land.
[0042] S55. Convert the optimized fine outline of cultivated land into a mask and extract the cultivated land plot raster map from the binary cultivated land map.
[0043] Further, in step S6, after processing the acquired farmland plot raster map and converting it into a vector, the farmland plot vector is obtained based on the vector boundary map, including the following steps:
[0044] S61. Remove fragmented plots from the cultivated land plot raster map and optimize the cultivated land plot raster map;
[0045] S62. Perform a raster-to-vector conversion algorithm on the raster map of cultivated land plots, and delete vectors with a background value of 0 to obtain the vector surface of cultivated land plots;
[0046] S63. Simplify and thin the vector surface of cultivated land plots to obtain the thinned vector surface of cultivated land plots.
[0047] Second aspect: An electronic device including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the program, performs the steps of the method provided in the first aspect.
[0048] Third aspect: A non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method provided in the first aspect.
[0049] The beneficial effects of this invention are:
[0050] 1. This invention improves the acquisition of SPHRNet from HRNet by introducing a strip pooling module (SPM) and a hybrid pooling module (MPM), which significantly enhances SPHRNet's ability to extract weak edges in farmland. The SPM module effectively captures long-distance dependencies in the image by using long strip pooling kernels, which is crucial for identifying and connecting broken farmland edges. The MPM module further combines pooling kernels of different shapes, including SPM and traditional spatial pooling, to aggregate different types of contextual information, making the feature representation more discriminative and improving the accuracy of farmland plot identification.
[0051] 2. This invention proposes a broken line connection algorithm for farmland contours, which effectively solves the problem of broken lines in the extraction of linear features such as farmland contour skeleton lines. This algorithm is supported by mathematical morphology and topological constraints. By combining the initial skeleton line extraction and the broken point connection strategy, it not only improves the completeness and accuracy of farmland plot extraction, but also provides strong technical support for precision agriculture and land management.
[0052] 3. This invention processes the cultivated land surface and cultivated land contour separately in remote sensing images, accurately extracts the features of cultivated land surface and cultivated land contour, effectively avoids the drawbacks of using a single HRNet cultivated land plot extraction algorithm, can improve the ability to capture long-distance dependencies, efficiently fit the cultivated land surface and cultivated land contour, and improve the recognition accuracy and precision of cultivated land plots. Attached Figure Description
[0053] Figure 1 This is a flowchart illustrating the method for extracting arable land plots according to the present invention;
[0054] Figure 2 This is a flowchart illustrating the principle of the method for extracting arable land plots according to the present invention.
[0055] Figure 3 This is a diagram of the HRNet network structure in this invention;
[0056] Figure 4 This is a schematic diagram of the architecture of the strip pooling module in this invention;
[0057] Figure 5 This is a schematic diagram of the architecture of the hybrid pooling module in this invention;
[0058] Figure 6 This is a diagram of the improved SPHRNet network structure in this invention;
[0059] Figure 7 This is a flowchart of the algorithm for connecting broken lines in cultivated land in this invention;
[0060] Figure 8 This is a schematic diagram of the structure of the farmland plot extraction device of the present invention;
[0061] Figure 9 This is a schematic diagram of the structure of the electronic device of the present invention. Detailed Implementation
[0062] Embodiments of the present invention are described in detail below. Examples of these embodiments are illustrated in the accompanying drawings, wherein the same or similar symbols denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0063] Currently, when using HRNet to extract weak edges of cultivated land, the lack of ability to capture long-distance dependencies often leads to discontinuous and broken edge extraction, affecting the accurate identification of cultivated land plots. It is also difficult to extract cultivated land surface and contour features accurately at the same time, and it is difficult to fit cultivated land surface and contour efficiently at the same time during model training. Due to the limitations of model generalization and training fitting problems, cultivated land contour extraction often shows discontinuity, which greatly affects the effect of cultivated land plot extraction.
[0064] To address the above problems, this invention provides a multi-weighted farmland plot extraction method based on an improved HRNet. Figure 1 This is a flowchart illustrating the multi-weighted farmland parcel extraction method based on the improved HRNet provided in an embodiment of the present invention. Figure 2 This is a flowchart illustrating the principle of the method for extracting arable land plots according to the present invention. The method includes:
[0065] S1. Based on high-resolution farmland remote sensing images, manually annotate the farmland surface and farmland outline to create a three-class farmland surface dataset and a two-class farmland outline dataset.
[0066] Based on the acquired high-resolution remote sensing imagery of cultivated land, the cultivated land surface (without fine-grained weak edges) and the inner contour of the cultivated land (with fine-grained weak edges) were manually annotated separately, specifically including:
[0067] Based on the acquired high-resolution remote sensing images of cultivated land, the first three bands (RGB) of the images were extracted using the osgeo python library, and the images were stretched into 8-bit images.
[0068] Using geographic information processing software such as ArcGIS and QGIS, the acquired 8-bit images were used to draw farmland vectors with weak edge lines without fine subdivision based on manual visual interpretation. After backup, the farmland vectors were first converted into farmland outer contour vectors with weak edge lines without fine subdivision, and the output was a shp file.
[0069] Convert the cultivated land surface vector to a raster, convert the cultivated land outline vector to a raster, add the corresponding raster values of the two, generate the added raster, and adjust its values: set the background to 0, the cultivated land value to 1, and the cultivated land outline value to 2, to generate a three-classified cultivated land raster map in TIFF format.
[0070] Using the backed-up cultivated land vector, convert it into a line vector to generate a cultivated land outer contour vector without subdividing weak edges; based on the cultivated land outer contour vector, use manual annotation to draw single-line dividing lines inside cultivated land plots to obtain cultivated land contour vector map.
[0071] Convert the farmland outline vector image to a raster, expand the outline by 4 pixels, set the background pixel value to 0, and set the outline pixel value to 1 to generate a binary farmland outline raster image in TIFF format.
[0072] Then, using the GDALpython library, the acquired TIFF format three-category cultivated land raster map and two-category cultivated land line raster map were cropped into 512*512 pixel image files using a sliding cropping method with an overlap rate of 0.1, and named with the same number. The generated small sample image files and label files were then cleaned using the Python platform. The pixel values in the label files were iterated, and only labels with non-zero values were retained. Image files with the same name were saved as new image files to remove pure background data.
[0073] The dataset is divided into training, validation, and test datasets in an 8:1:1 ratio, thus generating a three-category cultivated land dataset and a two-category cultivated land outline dataset.
[0074] S2. Construct the HRNet semantic segmentation algorithm model for farmland extraction and the SPHRNet semantic segmentation algorithm model for farmland outline extraction. Based on the farmland dataset and the farmland outline dataset, perform weight training and testing on HRNet and SPHRNet respectively, and obtain the weights of HRNet and SPHRNet after training and testing.
[0075] Traditional HRNet semantic segmentation algorithm model construction, such as Figure 3 As shown, a convolutional layer is first used to perform preliminary feature extraction on the input farmland image, and the features are processed to a specified resolution, which is then used as the highest resolution in subsequent processing.
[0076] Subsequently, the network is divided into four stages. Each stage uses convolutional modules to repeatedly perform convolution operations on the input features. At the end of the first, second, and third stages, a downsampling step is performed to create a sub-network with lower resolution and more feature channels for low-resolution feature extraction. At the end of the second and third stages, the network performs multi-resolution fusion on the features at different resolutions in different branches, fusing information from other branches into each branch to achieve information transfer across different resolutions. After feature extraction in the fourth stage, the network finally fuses the output features of all branches together and restores the size of the initial input image through the final convolutional neural network, achieving end-to-end semantic segmentation.
[0077] This invention employs the traditional HRNet semantic segmentation algorithm model for extracting cultivated land area, and is based on the improved SPHRNet semantic segmentation algorithm model for extracting the coarse outline of cultivated land.
[0078] The SPHRNet semantic segmentation algorithm model is characterized by the addition of a strip pooling module (SPM) after each downsampling in HRNet to capture features at different scales and enhance the expressive power of the features; and after the hierarchical feature extraction is completed, the output features of each layer are fused together and the final feature map is fused by a mixed pooling module (MPM).
[0079] Specifically, the structure of the SPM module and its data processing procedures, such as... Figure 4 As shown:
[0080] First, the feature map is input into two parallel adaptive average pooling (AdaptiveAvgPool2d) functions. The parameters of the adaptive average pooling function are (1, None). (None, 1) correspond to strip pooling in the horizontal and vertical directions, respectively, to capture long-term contextual dependencies in the two directions, so that the feature map is converted into the form of H×1 and 1×W.
[0081] Then, the pooled feature map is interpolated using the interpolate function to restore it to the same spatial dimension as the input feature map.
[0082] Next, the expanded feature maps are fused along the horizontal and vertical directions, and a feature map that combines horizontal and vertical information is obtained by summing.
[0083] Finally, the fused feature map is passed through a 1×1 convolutional layer, followed by the application of the Sigmoid activation function; the weight matrix is then multiplied element-wise with the original input feature map to obtain the output feature map.
[0084] Specifically, the MPM module combines spatial pooling and stripe pooling to form a hybrid pooling module. The structure of the MPM module and its data processing procedures are as follows: Figure 5 As shown:
[0085] First, when the MPM module is initialized, it receives the number of input channels in_channels and the pooling size pool_size (for example, the parameter is set to [20, 12]). These parameters are used to define the adaptive pooling layer in the module.
[0086] Next, two adaptive average pooling layers are constructed, each corresponding to one of the two values in pool_size, for the spatial pooling part. This captures local context information, upsamples the two pooled feature maps to restore them to the input size, and then fuses the input feature map with the two output feature maps through a two-dimensional convolution.
[0087] Then, in order to perform strip pooling, two additional adaptive average pooling layer parameters are defined as (1, None) and (None, 1), corresponding to strip pooling in the horizontal and vertical directions, respectively, so that the feature map is transformed into the form of H×1 and 1×W to capture long-range dependencies in both directions.
[0088] Next, the feature map after strip pooling is interpolated using an interpolation function to restore it to the same spatial dimension as the input feature map. The feature map output by strip pooling is then fused using a two-dimensional convolution. The feature map output by spatial pooling is stacked with the feature map output by strip pooling, and a 1*1 two-dimensional convolution is used to adjust the number of channels to the number of channels of the input feature map. Finally, the feature map is added to the input feature map to achieve residual connection.
[0089] The structure and data processing of the SPHRNet semantic segmentation algorithm model, such as Figure 6 As shown,
[0090] First, the input image is subjected to preliminary feature extraction through a convolutional layer and then processed to a specified resolution, which is used as the highest resolution for subsequent processing.
[0091] The network consists of four stages, each containing a convolutional module that performs convolution operations on the input features. Downsampling steps are performed at the end of the first, second, and third stages. At the end of the second and third stages, the network performs multi-resolution fusion of features from different branches to achieve information transfer at different resolutions. After each downsampling step, SPHRNet incorporates an SPM module to capture features at different scales and enhance their expressive power. After feature extraction in the fourth stage, the network fuses the output features from each branch and performs final feature map fusion using the MPM module to restore the initial input image size, achieving end-to-end semantic segmentation.
[0092] Then, using the three-class cultivated land dataset and the two-class cultivated land outline dataset, the constructed HRNet semantic segmentation algorithm model and SPHRNet semantic segmentation algorithm model are trained respectively. The following training parameters can be set:
[0093] The number of training epochs frozen based on the pre-training parameters is set to 50, and the number of training epochs after the backbone is unfrozen is 300. The optimizer is Adam, the initial training learning rate is set to 0.0005, and the learning rate is automatically adjusted by the cosine annealing algorithm. After training is completed, the training weights of HRNet and SPHRNet are obtained.
[0094] The trained weights can then be tested on the test dataset. The training accuracy can be calculated using the mean Intersection over Union (mIoU), recall (R), and overall accuracy (OA), as expressed by the following formula:
[0095]
[0096] Wherein, TP (True Positive) is the number of correctly classified positive cells, FP (False Positive) is the number of incorrectly classified positive cells, FN (False Negative) is the number of incorrectly classified negative cells, and TN (True Negative) is the number of correctly classified negative cells.
[0097] S3. Utilize the weights of HRNet and SPHRNet after training and testing; extract the grayscale images of three-classified cultivated land and two-classified cultivated land outlines from the regional remote sensing images.
[0098] The images of the region to be extracted are input into the HRNet and SPHRNet after training and testing, respectively, and the grayscale images of the three-class cultivated land and the grayscale images of the two-class cultivated land coarse outlines are inferred.
[0099] S4. Optimize the grayscale images of the three-category cultivated land and the grayscale images of the outline of the two-category cultivated land to obtain the optimized coarse outline of the cultivated land.
[0100] First, all pixels with a value of 1 in the grayscale image of the three-category cultivated land can be set to 0, and pixels with a value of 2 can be expanded by 4 pixels to obtain the outline of the two-category cultivated land. Then, the pixel values of the outline of the two-category cultivated land are added to the grayscale image of the two-category cultivated land outline, and all values greater than 1 are set to 1 to obtain the optimized coarse outline of the cultivated land. Specifically:
[0101] First, using the Python platform, copy the grayscale image of the three-category cultivated land and assign all pixels with a value of 1 to 0.
[0102] Then, based on the OpenCV Python's dilate function, the grayscale image array of cultivated land with a value of 1 is expanded by 4 pixels, that is, the pixels with a value of 2 are expanded by 4 pixels, to obtain the outer contour map of the cultivated land in binary classification.
[0103] Finally, the pixel values of the outer contour map of the two-category cultivated land and the grayscale map of the two-category cultivated land contour are added together, and all values above 1 are assigned a value of 1 to obtain the optimized coarse contour line of the cultivated land.
[0104] S5. Refine and connect the optimized coarse outline of cultivated land to obtain the optimized fine outline of cultivated land, and use the optimized fine outline of cultivated land to extract the raster map of cultivated land plots.
[0105] like Figure 7 As shown, the skeleton algorithm based on OpenCV transforms the optimized coarse outline of farmland into a fine outline (the outline is only one pixel wide). It detects breakpoints in the fine outline and draws straight lines to connect them. These lines are then overlaid on the original fine outline, and the optimized fine outline is converted into a mask. The farmland plot raster image is then extracted from the farmland surface. Specifically:
[0106] First, based on the closing function of the scikit-image library, with the disk parameter set to 3, morphological closing operations are performed on the optimized farmland outline to remove holes in the farmland outline.
[0107] Then, based on the skeletonize function of the scikit-image library, the optimized coarse outline of cultivated land after removing holes is skeletonized to generate an array of fine outlines of cultivated land.
[0108] Then, based on the remove small objects function of the scikit-image library, small fragments are removed from the fine outline array of farmland, where the min size parameter is set to 5 and the connectivity parameter is set to 8, generating a fine outline array of farmland with fragments removed.
[0109] Then, based on the array of fine contour lines of cultivated land after removing fragmented patches, an empty list of breakpoints is created and a 3*3 array of detection operators with all values of 1 is created to traverse the pixels in the fine contour lines of cultivated land.
[0110] The traversal process is as follows: Based on the pixel position, expand by 2 pixels in both the x and y directions to form a 3*3 neighborhood. Multiply this neighborhood with the corresponding detection operator and sum the results. If the value is 2, it means that there are two connectable breakpoints in the neighborhood. Add the pixel position to an empty list and assign the value 1 to that position. If the value is any other value, assign the corresponding position in the empty array to 0. After traversing the list, the breakpoint list is obtained, thus completing the breakpoint detection of the fine contour line.
[0111] Then, create an empty array of the same shape as the contour array, an empty dictionary to record the start and end points of the connection lines, and an empty list to record the start and end points of the lines to be connected. Iterate through the breakpoint list to find the breakpoint positions. Using the breakpoint position as the center and a radius of 18 pixels, extract the image (sub-image) at the breakpoint position. Detect the breakpoints in the sub-image using a 3*3 array of detection operators with all values of 1. Take the center point of the sub-image as the start point and the detected breakpoint (excluding the center point) as the end point, and write them into the empty dictionary. Calculate the Euclidean distance between the start and end points in each sub-image. If it is less than 12 pixels, it is a set of points to be connected and appended to the corresponding list. Based on the list to be connected, draw a line from the start point to the end point in the created empty array using the `line` function of OpenCV Python. Add the empty array of the drawn line to the extracted, fragmented, fine contour of the farmland to connect the broken lines. Then, assign all 0s to 1 and all 1s to 0 in the farmland line contour after connecting the broken lines, thus generating a fine contour mask for the farmland.
[0112] Then, all pixels with a value of 2 in the grayscale image of the three-category cultivated land are assigned a value of 0 to obtain the image of the two-category cultivated land.
[0113] Finally, the fine outline mask of cultivated land is multiplied with the binary cultivated land map array to generate a raster map of subdivided cultivated land plots.
[0114] S6. After processing the obtained farmland plot raster map, convert it into a vector map, and obtain the farmland plot vector map based on the vector boundary map.
[0115] First, fragmented patches are cleaned up. Based on the obtained farmland raster map, the SieveFilter function in GDAL is used with a deletion threshold of 16 pixels and a connectivity of 8 to clean up fragmented patches and obtain an optimized farmland raster map.
[0116] Then, the raster to vector conversion is performed. Based on the FPolygonize function in GDAL, the raster to vector conversion algorithm is executed on the optimized farmland plot raster map, and vectors with a background value of 0 are deleted to obtain the shapefile file of the farmland plot vector surface.
[0117] Finally, vector thinning is performed. The shapefile of the cultivated land plot vector surface is simplified and thinned based on the Simplify function in OGR to obtain the thinned cultivated land plot vector surface shapefile.
[0118] Application Example: This application example uses a high-resolution remote sensing image of cultivated land in a rural area in northern Anhui Province in 2023 as the research area.
[0119] First, ArcMap software was used to perform manual visual interpretation of the farmland features in the area to be identified, obtaining vector data of farmland surface (without weak edge subdivision) and farmland outline (with weak edge subdivision). Both were converted into raster data, and the vector data of farmland outline (with weak edge subdivision) was dilated by 4 pixels. Then, a sliding window cropping method was used to crop the two raster images into several 512*512 blocks. Data cleaning was used to remove data that did not contain the target features. The blocks were then divided into training, validation, and test sets in an 8:1:1 ratio, thus constructing a multi-class farmland surface (without weak edge subdivision) dataset and a binary farmland outline (with weak edge subdivision) dataset.
[0120] Next, the training and validation sets of the multi-class cultivated land dataset (without subdivision of weak edges) and the binary cultivated land outline dataset (with subdivision of weak edges) were input into the constructed HRNet and SPHRNet neural networks, respectively. The following training parameters were set: the number of frozen training epochs based on the pre-training parameters was set to 50 epochs, the number of training epochs after the backbone was unfrozen was set to 300 epochs, the optimizer was Adam, the initial training learning rate was set to 0.0005, the learning rate was automatically adjusted by the cosine annealing algorithm, the loss function was the cross-entropy loss function, and the training weights were obtained after training was completed.
[0121] Subsequently, the multi-class cultivated land dataset (without subdividing weak edges) and the binary cultivated land outline dataset (with subdivided weak edges) were input into the constructed HRNet and SPHRNet neural networks, respectively, to infer the three-class grayscale image of cultivated land and the binary grayscale image of cultivated land coarse outline.
[0122] Then, the position with a value of 2 in the three-class grayscale image of cultivated land is assigned a value of 0 to obtain the two-class grayscale image of cultivated land. The position with a value of 2 in the three-class grayscale image of cultivated land is merged with the two-class grayscale image of cultivated land coarse outline, and the holes in the merged result are removed. The optimized two-class grayscale image of cultivated land coarse outline is skeletonized, and small fragments are removed to generate the fine outline of cultivated land. The breakpoints in the fine outline of cultivated land are checked and repaired, and converted into a mask to generate a fine outline mask of cultivated land with broken lines reconnected. Based on this mask, the grayscale image of cultivated land is extracted to generate the grayscale image of cultivated land plots.
[0123] Finally, the grayscale image of the cultivated land plots was post-processed. The SieveFilter function in GDAL was called to remove fragmented patches from the prediction results, and the FPolygonize function in GDAL was called to convert the raster to vector. Finally, the generated vector file was simplified and thinned to obtain the cultivated land plot extraction results of a rural area in northern Anhui Province.
[0124] This invention also provides a multi-weighted farmland plot extraction device based on an improved HRNet, such as... Figure 8 As shown, the device includes:
[0125] The HRNet module uses HRNet after training and testing to extract three-class grayscale images of cultivated land from regional remote sensing images.
[0126] The SPHRNet module uses SPHRNet after training and testing to extract binary classification grayscale images of cultivated land outlines from regional remote sensing images.
[0127] The outline generation module is used to optimize the grayscale map of the three-category cultivated land and the grayscale map of the outline of the two-category cultivated land to obtain the optimized coarse outline of the cultivated land.
[0128] The raster map generation module is used to refine and connect broken lines of the optimized coarse outline of cultivated land to extract the raster map of cultivated land plots.
[0129] The raster-to-vector module is used to process the acquired farmland raster map and convert it into a vector map, and then obtain the farmland plot vector based on the vector boundary map.
[0130] The present invention also provides an electronic device, Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, such as... Figure 9 As shown, the electronic device may include a processor, a communications interface, memory, and a communication bus, wherein the processor, communications interface, and memory communicate with each other via the communication bus. The processor can invoke logical instructions from the memory, for example, to execute the following method:
[0131] S1. Based on high-resolution farmland remote sensing images, manually label the farmland surface and farmland outline to obtain a three-class farmland surface dataset and a two-class farmland outline dataset.
[0132] S2. Construct an HRNet semantic segmentation algorithm model for farmland extraction and an SPHRNet semantic segmentation algorithm model for farmland outline extraction. Based on the farmland dataset and farmland outline dataset, perform weight training and testing on HRNet and SPHRNet respectively, and obtain the weights of HRNet and SPHRNet after training and testing.
[0133] S3. Using the weights of HRNet and SPHRNet after training and testing, extract the grayscale images of three-classified cultivated land and two-classified cultivated land outlines from the regional remote sensing images.
[0134] S4. Optimize the grayscale map of the three-category cultivated land and the grayscale map of the outline of the two-category cultivated land to obtain the optimized coarse outline of cultivated land.
[0135] S5. Refine and disconnect the optimized coarse outline of cultivated land to obtain the optimized fine outline of cultivated land, and use the optimized fine outline of cultivated land to extract the raster map of cultivated land plots.
[0136] S6. After processing the obtained farmland plot raster map, convert it into a vector map, and obtain the farmland plot vector map based on the vector boundary map.
[0137] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, 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 (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0138] This invention also provides a non-transitory computer-readable storage medium storing a computer program thereon, which, when executed by a processor, is implemented to perform the methods provided in the above embodiments, including, for example:
[0139] S1. Based on high-resolution farmland remote sensing images, manually label the farmland surface and farmland outline to obtain a three-class farmland surface dataset and a two-class farmland outline dataset.
[0140] S2. Construct an HRNet semantic segmentation algorithm model for farmland extraction and an SPHRNet semantic segmentation algorithm model for farmland outline extraction. Based on the farmland dataset and farmland outline dataset, perform weight training and testing on HRNet and SPHRNet respectively, and obtain the weights of HRNet and SPHRNet after training and testing.
[0141] S3. Using the weights of HRNet and SPHRNet after training and testing, extract the grayscale images of three-classified cultivated land and two-classified cultivated land outlines from the regional remote sensing images.
[0142] S4. Optimize the grayscale map of the three-category cultivated land and the grayscale map of the outline of the two-category cultivated land to obtain the optimized coarse outline of cultivated land.
[0143] S5. Refine and disconnect the optimized coarse outline of cultivated land to obtain the optimized fine outline of cultivated land, and use the optimized fine outline of cultivated land to extract the raster map of cultivated land plots.
[0144] S6. After processing the obtained farmland plot raster map, convert it into a vector map, and obtain the farmland plot vector map based on the vector boundary map.
[0145] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0146] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0147] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for extracting multi-weighted cultivated land parcels based on an improved HRNet, characterized in that, include: S1. Based on high-resolution farmland remote sensing images, manually label the farmland surface and farmland outline to obtain a three-class farmland surface dataset and a two-class farmland outline dataset. S2. Construct an HRNet semantic segmentation algorithm model for farmland extraction and an SPHRNet semantic segmentation algorithm model for farmland outline extraction. Based on the farmland dataset and farmland outline dataset, perform weight training and testing on HRNet and SPHRNet respectively, and obtain the weights of HRNet and SPHRNet after training and testing. S3. Using the weights of HRNet and SPHRNet after training and testing, extract the grayscale images of three-classified cultivated land and two-classified cultivated land outlines from the regional remote sensing images. S4. Optimize the grayscale map of the three-category cultivated land and the grayscale map of the outline of the two-category cultivated land to obtain the optimized coarse outline of cultivated land. S5. Refine and disconnect the optimized coarse outline of cultivated land to obtain the optimized fine outline of cultivated land, and use the optimized fine outline of cultivated land to extract the raster map of cultivated land plots. S6. After processing the obtained raster map of cultivated land plots, convert it into a vector map, and obtain the cultivated land plot vector based on the vector boundary map. S1 includes the following steps: S11. The first three bands of the high-resolution remote sensing image of cultivated land are acquired and stretched into an 8-bit image; S12. Manually annotate the stretched image to obtain the cultivated land vector, and convert the cultivated land vector into the cultivated land outer contour vector without subdividing weak edges. S13. Convert the cultivated land vector to a raster and set the value to 1. Convert the cultivated land outline vector to a raster and set the value to 2. Set the background value to 0 to obtain a three-classified cultivated land raster map. S14. Based on the outer contour vector of cultivated land, mark the inner contour dividing lines of weakly edged cultivated land plots to obtain a cultivated land contour vector map. S15. Convert the farmland outline vector image to a raster image, set the background value to 0, expand the outline by 4 pixels and set the value to 1 to obtain a two-classified farmland line raster image. S16. Obtain the three-class cultivated land dataset and the two-class cultivated land outline dataset based on the three-class cultivated land raster map and the two-class cultivated land line raster map. The SPHRNet semantic segmentation algorithm model structure includes: After each downsampling in HRNet, an SPM module is added to capture features at different scales and enhance the expressive power of the features. After the hierarchical feature extraction is completed, the output features of each layer are fused together, and the final feature map fusion is performed through the MPM module.
2. The method for extracting arable land plots according to claim 1, characterized in that, The SPM module's data processing procedure includes: S21. Input the feature map into two parallel adaptive average pooling functions respectively, so that the feature map is pooled into the form of H×1 and 1×W; S22. Interpolate the pooled feature map using an interpolation function to restore it to the same spatial dimension as the input feature map; S23. The interpolated feature maps are fused along the horizontal and vertical directions to obtain a feature map that integrates horizontal and vertical information. S24. The fused feature map is passed through a 1×1 convolutional layer and a sigmoid activation function, and then element-wise multiplied with the original input feature map to obtain the output feature map.
3. The method for extracting arable land plots according to claim 1, characterized in that, The weighted tests of HRNet and SPHRNet in S2 use the mean intersection-union ratio (mIoU), recall (R), and overall precision (OA), expressed by the following formulas: Where TP is the number of positive classes correctly classified, FP is the number of positive classes misclassified, FN is the number of negative classes misclassified, and TN is the number of negative classes classified.
4. The method for extracting arable land plots according to claim 1, characterized in that, In step S4, the grayscale images of the three-category cultivated land and the grayscale images of the two-category cultivated land outlines are optimized to obtain optimized coarse outlines of cultivated land. The steps include: S41. All pixels with a value of 1 in the grayscale image of the three-category cultivated land are assigned a value of 0, and the pixels with a value of 2 are expanded by 4 pixels to obtain the outer contour image of the two-category cultivated land. S42. Add the pixel values of the outer contour map of the two-category cultivated land and the grayscale map of the two-category cultivated land contour line, and assign all values above 1 to 1 to obtain the optimized coarse contour line of cultivated land.
5. The method for extracting arable land plots according to claim 1, characterized in that, In step S5, the optimized coarse outline of cultivated land is refined and broken to obtain the optimized fine outline of cultivated land. The optimized fine outline of cultivated land is then used to extract a raster map of cultivated land parcels, including the following steps: S51. Perform morphological closing operation optimization on the rough outline of cultivated land to remove holes in the rough outline of cultivated land. S52. Skeletonize the optimized coarse outline of cultivated land to obtain the fine outline of cultivated land. S53. Detect the breakpoints in the fine outline of cultivated land and draw straight lines to connect the breakpoints to obtain the optimized fine outline of cultivated land. S54. Set all pixels with a value of 2 in the grayscale image of the three-category cultivated land to 0 to obtain the image of the two-category cultivated land. S55. Convert the optimized fine outline of cultivated land into a mask and extract the cultivated land plot raster map from the binary cultivated land map.
6. The method for extracting arable land plots according to claim 1, characterized in that, In step S6, after processing the obtained farmland plot raster map, it is converted into a vector map. The farmland plot vector is then obtained based on the vector boundary map. This includes the following steps: S61. Remove fragmented plots from the cultivated land plot raster map and optimize the cultivated land plot raster map; S62. Perform a raster-to-vector conversion algorithm on the raster map of cultivated land plots, and delete vectors with a background value of 0 to obtain the vector surface of cultivated land plots; S63. Simplify and thin the vector surface of cultivated land plots to obtain the thinned vector surface of cultivated land plots.
7. An electronic device comprising a memory, a processor, and a computer 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 for extracting arable land plots as described in any one of claims 1 to 6.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of a method for extracting arable land plots as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Remote sensing image ground object extraction multi-scale strong fusion semantic segmentation method based on HRNet
CN116486075A
Remote sensing image building semantic segmentation method based on HRNet
CN119478400A
Remote sensing coastline extraction method, device, equipment and medium
CN119672535A