Water body and shadow classification method for remote sensing image based on double classification attention network

By introducing the U-Net architecture with a dual-classification attention network, the problems of false detection and false negative detection in water and shadow classification in polar remote sensing images are solved, achieving efficient and accurate water and shadow segmentation, improving the robustness and generalization ability of the model, and supporting long-term monitoring.

CN121033675BActive Publication Date: 2026-05-08NANJING INST OF MEASUREMENT & TESTING TECH +1
View PDF 4 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANJING INST OF MEASUREMENT & TESTING TECH
Filing Date
2025-09-10
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing automated remote sensing image water and shadow classification methods suffer from false positives and false negatives in complex polar backgrounds, especially in areas where rocks and shadows intersect, where accurate segmentation is difficult. Furthermore, the scarcity of high-quality labeled datasets limits the generalization ability of the models and their long-term monitoring applications.

Method used

A dual-classification attention network-based approach is adopted. By introducing a U-Net architecture with channel and spatial attention modules, multi-scale feature learning of water bodies and shadows is performed to generate prior labels for water bodies and shadows. A sample set containing multi-band synthetic images, water body masks, and shadow masks is constructed and optimized for training to output binary mask images of water bodies and shadows.

Benefits of technology

It improves the accuracy and robustness of water and shadow segmentation, reduces false positives and false negatives, enhances the stability and generalization ability of the model in polar environments, and supports large-scale, long-term automated batch processing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121033675B_ABST
    Figure CN121033675B_ABST
Patent Text Reader

Abstract

The application discloses a remote sensing image water body and shadow classification method based on a double classification attention network, relates to the technical field of remote sensing image analysis and geographic information processing, and comprises the following steps: preprocessing a Sentinel-2 original image to generate a multi-band composite image with a predetermined resolution; calculating a normalized water index and extracting a brightness channel to respectively generate a water body mask and a shadow mask, constructing a sample set, and dividing the sample set into a training set and a verification set; constructing a double classification attention network model based on the training set, and optimizing and training the model; using the trained double classification attention network model to perform sliding window reasoning on the multi-band composite image, fusing and splicing the predicted binary mask, and outputting a double-band water body / shadow binary mask image. The application can effectively overcome the interference of ice and snow shadow areas on the water body recognition result, and has better robustness and stability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of remote sensing image analysis and geographic information processing technology, and in particular to a method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network. Background Technology

[0002] Given the unique geographical environment of the polar regions, satellite remote sensing technology has become a key means of monitoring the dynamic changes of ice lakes. Ice lake extraction is essentially the identification of water bodies on the surface of the ice sheet, and from the perspective of remote sensing image methods, it can be divided into two categories: manual digitization and automated methods. Although manual digitization methods can achieve pixel-by-pixel fine annotation, they are time-consuming, cumbersome, and easily affected by the subjective experience of the interpreter, resulting in insufficient annotation consistency and scalability, making it difficult to meet the needs of large-scale, long-term monitoring. Automated extraction methods are more efficient than manual methods, but due to spectral confusion caused by cloud shadows and high-reflectivity areas of rocks, the false detection suppression effect is limited, and missed detections still frequently occur in areas where rocks and shadows intersect. In complex ice and snow backgrounds, the problem of false detection of rocks and shadows has not been fundamentally solved. In addition, existing automated algorithms often rely on high-precision digital elevation models (DEMs) or complex physical and statistical models, making it difficult to extend to long-term, large-scale automatic monitoring in the polar regions.

[0003] In recent years, deep convolutional neural networks (CNNs), with their multi-scale encoder-decoder architecture and skip connection characteristics, have been able to fuse shallow spatial details and deep semantic features during end-to-end training, automatically learning and distinguishing water bodies from background interference. This has significantly improved segmentation accuracy and stability in batch processing of multi-temporal, large-scale remote sensing images. However, many challenges remain in Antarctic surface water identification: the construction of high-quality, labeled deep learning datasets is still incomplete, limiting the model's generalization ability and sustainable application for long-term monitoring. To address the problem of confusion between water bodies and highly reflective shadow areas in complex polar backgrounds, the U-Net architecture based on a dual-classification attention mechanism has emerged. By introducing channel and spatial attention modules into the encoder-decoder network and explicitly separating shadows as an independent category, it can simultaneously learn multi-scale features of both water bodies and shadow targets during training, effectively suppressing false detections of highly reflective rocks and shadow areas, and outputting independent binary masks of water bodies and shadows during inference. This method not only achieves accurate water segmentation in cascaded regions of shadows and rocks, reducing false positives and false negatives, but also significantly enhances the model's robustness in the complex polar environment by explicitly distinguishing shadows through dual output branches. The introduction of an attention mechanism allows the network to adaptively weight features at different scales, enabling fine extraction of water and shadow edges. Furthermore, it can generate training sets containing prior labels for both water and shadows, alleviating the scarcity of polar labeled samples and improving the model's generalization ability. More importantly, this method supports large-scale, long-term automated batch processing, providing an efficient and scalable technical means for dynamic monitoring of Antarctic surface water. Summary of the Invention

[0004] In view of the problems existing in the classification methods of water bodies and shadows in remote sensing images based on dual-classification attention networks, this invention is proposed. Therefore, the problem to be solved by this invention is how to provide a classification method for water bodies and shadows in remote sensing images based on dual-classification attention networks.

[0005] To solve the above-mentioned technical problems, the present invention provides the following technical solution:

[0006] In a first aspect, the present invention provides a method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network, which includes preprocessing the original Sentinel-2 image using a nearest neighbor interpolation method to generate a multi-band composite image with a predetermined resolution.

[0007] Based on multi-band synthetic images, normalized water index is calculated and brightness channels are extracted. Water masks and shadow masks are generated respectively. A sample set containing multi-band synthetic images, water masks and shadow masks is constructed. The sample set is divided into training set and validation set.

[0008] A dual-classification attention network model is constructed based on the training set, and the dual-classification attention network model is optimized and trained.

[0009] A trained dual-classification attention network model is used to perform sliding window inference on multi-band synthetic images, and the predicted binary masks are fused and stitched together to output a dual-band water / shadow binary mask image.

[0010] As a preferred embodiment of the remote sensing image water and shadow classification method based on a dual-classification attention network described in this invention, the calculation of the normalized water index and extraction of the brightness channel based on multi-band composite images includes:

[0011] Ground reflectance in the green and near-infrared bands was extracted from multi-band composite images, and the normalized water index was calculated. The formula is:

[0012] ;

[0013] in: and The ground reflectance in the green light band and near-infrared band are respectively used to binarize the normalized water index using empirical thresholds to generate a water mask.

[0014] Extract the red, green, and blue bands from the multi-band composite image, convert it to the HSV color space, and extract the luminance channel. Generate a preliminary shadow mask , is represented as:

[0015] ;

[0016] in, Indicates position The area was identified as a shaded region. The shadow mask is obtained by setting the brightness threshold.

[0017] As a preferred embodiment of the remote sensing image water and shadow classification method based on a dual-classification attention network described in this invention, the construction of a sample set comprising multi-band synthetic images, water body masks, and shadow masks includes:

[0018] Multi-band composite images, water masks, and shadow masks are simultaneously slid-cropped using a fixed window of 256×256 pixels, with no overlap between rows and columns. If the edge area is less than 256×256 pixels, it is discarded without any filling.

[0019] For each cropping window, a set of three files is generated: a 256×256×3 multi-band composite image sub-block; a corresponding 256×256 water body binary mask sub-block; and a corresponding 256×256 shadow binary mask sub-block.

[0020] Iterate through all the sub-blocks. If there is at least one pixel with a value of 255 in the water mask of the sub-block, then the sub-block is recorded as a water sample. If there is at least one pixel with a value of 255 in the shadow mask of the sub-block, then the sub-block is recorded as a shadow sample. If the above conditions are met at the same time, the sub-block is simultaneously labeled as a water sample and a shadow sample, and two sets of labels, water sample and shadow sample, are retained respectively.

[0021] The selected water samples and shadow samples were randomly divided into training and validation sets at a ratio of 8:2.

[0022] As a preferred embodiment of the remote sensing image water and shadow classification method based on a dual-classification attention network described in this invention, wherein: the construction of the dual-classification attention network model based on the training set includes:

[0023] A four-layer downsampling encoder is used, with each layer consisting of: 3×3 convolution, with the number of output channels starting from 64 and doubling with each layer; ReLU activation; setting the probability of random deactivation to 0.2; 3×3 convolution, ReLU activation; 2×2 max pooling, downsampling to the next layer;

[0024] The following four branches are executed in parallel on the output feature map of the last layer of the encoder: as the bottleneck module of the dilated spatial pyramid pooling: one 1×1 convolution with ReLU activation; three 3×3 dilated convolutions with dilation rates of 6, 12 and 18 respectively, all with ReLU activation; after concatenating the outputs of the four branches, a fused feature map is generated by passing a 3×3 convolution and ReLU activation once.

[0025] Decoders for the water body branch and the shadow branch are constructed separately, and bilinear upsampling is performed on the output of the void space pyramid pooling bottleneck module.

[0026] The upsampled features are concatenated with the skip connection features of the encoder layer and the 2×2 upsampled skip connection features;

[0027] The stitching results are then input into the CBAM channel attention module, the CBAM spatial attention module, and the attention gating module in sequence.

[0028] The features weighted by the attention-gated module are concatenated with the upsampled features, and then two 3×3 convolutions are performed to restore the current number of decoding channels; the process is repeated until the spatial resolution is restored to the same as the input.

[0029] A single-channel water body probability map is generated at the end of the water body branch by 1×1 convolution and sigmoid activation.

[0030] A single-channel shadow probability map is generated at the end of the shadow branch using 1×1 convolution and sigmoid activation; a mutual exclusion loss is added to suppress the overlap between the water body and the shadow space, defined as:

[0031] ;

[0032] in: For mutually exclusive losses, and Pixels The probability plots output in the water body branch and the shaded branch, This is the mutual exclusion loss weighting coefficient.

[0033] As a preferred embodiment of the remote sensing image water and shadow classification method based on a dual-classification attention network described in this invention, the optimization training of the dual-classification attention network model includes:

[0034] Using a custom data loader, multi-band images from the training set, along with corresponding water bodies and shadow binary masks, are loaded into the model in batches, with the input size fixed at 256×256.

[0035] During the model compilation phase, the loaded attention U-Net network is configured with the Adam optimizer and an initial learning rate of 1×10⁻⁶. -4 The parameters were updated, and the loss functions for both the water body branch and the shadow branch were defined as the sum of the binary cross-entropy and DiceLoss. The evaluation index for both the water body branch and the shadow branch was set to classification accuracy.

[0036] The model checkpoint callback automatically saves the weights when the loss on the validation set is lowest in each round. After each training round, forward inference is performed on the complete validation set to calculate and record the accuracy, recall, F1 score and IoU index of the water branch and the shadow branch to evaluate the model's generalization performance.

[0037] When the validation set loss no longer decreases for three consecutive rounds, the training process will terminate early and the weight file with the optimal validation loss will be automatically loaded.

[0038] As a preferred embodiment of the remote sensing image water and shadow classification method based on a dual-classification attention network described in this invention, the step of using a trained dual-classification attention network model to perform sliding window inference on multi-band synthetic images includes:

[0039] The cropped multi-band composite image is divided into blocks of 512×512 pixels and scanned. For each band, the global minimum and maximum values ​​are calculated within the entire image.

[0040] Using a window size of 512×512 pixels and an overlap of 64 pixels, the entire image is traversed in both row and column directions. For any top-left corner coordinate... The window area is first read, and the raw pixel values ​​of that area in three bands are saved as a channel. Height is Width is A three-dimensional array;

[0041] Normalize all pixels within the window for each band, as shown below:

[0042] ;

[0043] in: These are the normalized pixel values. For band Pixels within the window The original value, and bands Minimum and maximum values ​​within the entire graph;

[0044] The normalized pixel values ​​are organized into a height of pixels, width Pixels, number of channels The three-dimensional tensor is used as the model input;

[0045] Using the generated 3D tensor as network input, the model simultaneously outputs the corresponding water body probability map and shadow probability map. This represents the probability that each pixel is predicted to be a body of water; Shadow probability map , which represents the probability that each pixel is predicted to be a shadow;

[0046] Binarize the water body probability map and the shadow probability map respectively to generate corresponding window-level binary masks for water bodies and shadows, as follows:

[0047] ;

[0048] ;

[0049] in: and This represents a window-level binary mask for water bodies and shadows.

[0050] Write the generated water body and shadow binary mask for each window back to the corresponding position in the output file according to the coordinates of the top left corner;

[0051] When writing back to the same location, the maximum value strategy is applied to the pixel values ​​of the overlapping area. If multiple windows output different values ​​at the same coordinates of the original image, the result of the target pixel is taken as the standard. All windows are written back and merged to obtain a dual-band binary mask image.

[0052] In a second aspect, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of a remote sensing image water and shadow classification method based on a dual-classification attention network.

[0053] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements the steps of a remote sensing image water and shadow classification method based on a dual-classification attention network.

[0054] The beneficial effects of this invention are as follows: The automated water body extraction method based on the U-Net dual-classification network model with attention mechanism proposed in this invention is not only more efficient and accurate, but also significantly saves a large amount of manual annotation work required by traditional methods. The extraction effect is smoother and more complete at different scales, especially for water bodies with smaller areas and complex shapes, and it effectively overcomes the interference of ice and snow shadow areas on water body identification results, exhibiting better robustness and stability overall. Attached Figure Description

[0055] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0056] Figure 1 A flowchart for creating a dataset for a remote sensing image water and shadow classification method based on a dual-classification attention network;

[0057] Figure 2 The flowchart shows the network training logic of a remote sensing image water and shadow classification method based on a dual-classification attention network.

[0058] Figure 3 This is a network structure diagram of a remote sensing image water and shadow classification method based on a dual-classification attention network;

[0059] Figure 4 This is an image testing logic diagram for a remote sensing image water and shadow classification method based on a dual-classification attention network. Detailed Implementation

[0060] To make the above-mentioned objects, features, and advantages of the present invention more readily understood, specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the protection scope of the present invention.

[0061] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.

[0062] Secondly, the term "an embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places throughout this specification does not necessarily refer to the same embodiment, nor is it a single embodiment or an embodiment selectively excluded from other embodiments.

[0063] Reference Figures 1-4 This is the first embodiment of the present invention, which provides a method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network, including:

[0064] Step 1: Preprocess the original Sentinel-2 image using the nearest neighbor interpolation method to generate a multi-band composite image with a predetermined resolution;

[0065] Specifically, image preprocessing. Necessary geometric and spectral corrections are performed on the acquired Sentinel-2 multi-band synthetic images to eliminate errors caused by different band resolutions and angles, providing consistent input for subsequent mask creation and network training. This can be further divided into the following sub-steps:

[0066] Step 1.1: Resample the data to 10m using nearest neighbor interpolation and align it with the original 10m resolution data at the pixel level to generate a geometrically consistent six-band composite image with 10m resolution.

[0067] Step 1.2: Perform detailed geometric and orthorectification corrections on the obtained synthetic image, and make fine adjustments using ground control points (GCPs) if necessary to ensure that the pixel coordinates of each band are strictly consistent.

[0068] Step 2: Calculate the normalized water index and extract the brightness channel based on the multi-band synthetic image, generate water body mask and shadow mask respectively, construct a sample set containing multi-band synthetic image, water body mask and shadow mask, and divide the sample set into training set and validation set;

[0069] Specifically, water body and shadow mask creation. Based on 10m geometrically consistent multi-band synthetic images, pixel-level water body prior labels and shadow prior labels are automatically generated, providing spectral and color prior information for training samples.

[0070] Further: Step 2.1, extract the ground reflectance of the green band (Band 3) and near-infrared band (Band 8) from the composite image cropped in Step 1, and calculate it according to the Normalized Difference Water Index (NDWI) formula:

[0071] ;

[0072] in: and The ground reflectance of Sentinel-2 green band (band 3) and near-infrared band (band 8) are respectively used to binarize NDWI to generate a water mask using empirical thresholds.

[0073] Step 2.2: Extract the red, green, and blue bands (Band4, Band3, and Band2) from the composite image in Step 1, convert them to the HSV color space, and extract the luminance channel. .make Using a brightness threshold (used to distinguish between shadow and non-shadow areas), a preliminary shadow mask is generated through the following binarization operation. :

[0074] ;

[0075] in, Indicates position The area was identified as a shadow region. The morphological opening operation (to remove isolated small noise blocks) and the morphological closing operation (to fill holes) of the 5×5 structuring element were performed successively to finally obtain a connected binary shadow mask without isolated noise.

[0076] Step 3: Construct a sample set containing multi-band synthetic images, water body masks, and shadow masks, and divide the sample set into a training set and a validation set;

[0077] Specifically, the sliding window cropping and sample construction process involves uniformly cropping the geometrically consistent synthesized image and the generated water and shadow masks into fixed-size sub-blocks, and constructing training and validation sets based on the mask pixel information. This step can be further subdivided into the following sub-steps:

[0078] Step 3.1: Simultaneously slide and crop the six-band composite image from Step 1, the water body binary mask and the shadow binary mask from Step 2 with a fixed window of size 256×256 pixels. The rows and columns do not overlap. If the edge area is less than 256×256, it is directly discarded without any filling.

[0079] Step 3.2: For each cropping window, generate a set of three files: a 256×256×3 multi-band original image sub-block; a corresponding 256×256 water body binary mask sub-block; and a corresponding 256×256 shadow binary mask sub-block.

[0080] Step 3.3: Traverse all sub-blocks obtained in Step 3.2: If there is at least one pixel with a value of 255 in the water mask of a sub-block, then the sub-block is recorded as a water sample; if there is at least one pixel with a value of 255 in the shadow mask of a sub-block, then the sub-block is recorded as a shadow sample; if both of the above conditions are met, then the sub-block is simultaneously labeled as a water sample and a shadow sample, and the two sets of labels for water and shadow are retained respectively.

[0081] Step 3.4: The selected water samples and shadow samples are randomly divided into training set and validation set at a ratio of 8:2, respectively, to ensure that sub-blocks with different scenes and different shadow distributions are distributed in both training set and validation set.

[0082] Step 4: Construct a dual-classification attention network model based on the training set, and optimize and train the dual-classification attention network model;

[0083] Specifically, the dual-classification attention U-Net network is constructed by building a dual-output attention U-Net deep learning network based on the training set samples obtained in step 3, and defining the corresponding loss and metric. This step can be further subdivided into the following sub-steps:

[0084] Step 4.1: Use a four-layer downsampling encoder. Each layer consists of the following operations in sequence: 3×3 convolution, with the number of output channels starting from 64 and doubling layer by layer; ReLU activation function; set the probability of random deactivation of the layer to 0.2; 3×3 convolution, ReLU activation; 2×2 max pooling, downsampling to the next layer.

[0085] Step 4.2: On the output feature map of the last layer of the encoder, the following four branches are executed in parallel: as the bottleneck module of ASPP: one 1×1 convolution with ReLU activation; three 3×3 dilated convolutions with dilation rates of 6, 12 and 18 respectively, all with ReLU activation; after concatenating the outputs of the four branches, a fused feature map is generated by passing a 3×3 convolution and ReLU activation once.

[0086] Step 4.3: Construct the water branch and shadow branch decoders respectively. The process is as follows: Perform bilinear upsampling (doubling the size) on the ASPP output; concatenate the upsampled features with the skip connection features of the corresponding encoder layer and their 2×2 upsampled skip connection features; input the concatenation result into the CBAM channel attention module, CBAM spatial attention module, and attention gating module in sequence; concatenate the weighted features of the attention gating module with the upsampled features, and then perform two 3×3 convolutions (ReLU) to restore the current number of decoding channels; repeat the above process until the spatial resolution is restored to the same as the input.

[0087] Step 4.4: At the end of the water body branch, generate a single-channel water body probability map using 1×1 convolution + sigmoid activation; at the end of the shadow branch, generate a single-channel shadow probability map using 1×1 convolution + sigmoid activation; add a mutual exclusion loss to suppress the overlap between the water body and shadow spaces, defined as:

[0088] ;

[0089] in: For mutually exclusive losses, and These are the probability plots for the water body and shadow branches, respectively. This is the mutual exclusion loss weighting coefficient.

[0090] The constructed bi-classification attention U-Net model is optimized and trained, and its performance is monitored using a validation set. This can be broken down into the following sub-steps:

[0091] A custom data loader is used to batch load multi-band images from the training set along with corresponding water bodies and shadow binary masks into the model, with a fixed input size of 256×256. The validation set is not randomly shuffled to ensure consistent evaluation.

[0092] During the model compilation phase, the loaded attention U-Net network is set to use the Adam optimizer (initial learning rate 1×10⁻⁶). -4 The parameters are updated, and the loss function for both the water and shadow branches is defined as the sum of binary cross-entropy and DiceLoss to balance pixel classification accuracy and consistency of overlapping regions. Simultaneously, the evaluation metric for both output branches is set to classification accuracy, allowing for real-time monitoring of the model's ability to distinguish between water and shadow pixels during training.

[0093] Multiple callback functions are configured during training to ensure optimal model preservation and performance monitoring: Firstly, model checkpoint callbacks automatically save the weights with the lowest validation set loss in each epoch. Secondly, TensorBoard callbacks record and visualize the training and validation loss curves and accuracy curves in real time. Simultaneously, a custom MetricsCallback callback performs forward inference on the complete validation set after each epoch, calculating and recording metrics such as accuracy, recall, F1 score, and IoU for the water and shadow branches to evaluate the model's generalization performance. When the validation set loss no longer decreases for three consecutive epochs, the training process terminates early, and the weight file with the optimal validation loss is automatically loaded. The entire training process operates under these callback mechanisms to ensure timely feedback and optimization of the model's performance on the validation set.

[0094] Step 5: The trained dual-classification attention network model is used to perform sliding window inference on the multi-band synthetic image, and the predicted binary masks are fused and stitched together to output a dual-band water / shadow binary mask image.

[0095] Specifically, the sliding window inference and dual-band mask generation are performed. This step uses a trained model to perform sliding window inference on the entire cropped multi-band image to generate a dual-band water / shadow binary mask covering the entire image. This step can be further divided into the following sub-steps:

[0096] Step 5.1: Divide the cropped multi-band composite image into blocks of 512×512 pixels and scan them. For each band, calculate the global minimum and maximum values ​​across the entire image to ensure that subsequent window-level normalization is performed uniformly based on the global pixel range, thus maintaining consistency with the normalization method used in the training phase. This is represented as follows:

[0097] ;

[0098] in: It is a band In position The original pixel value at that location, and These are the minimum and maximum values ​​for that band across the entire map, respectively.

[0099] Step 5.2 involves traversing the entire image in both row and column directions using a window size of 512×512 pixels and an overlap of 64 pixels (step size 448 pixels). For any top-left corner coordinate... Window area: First, read the raw data of this area to obtain a shape of an array, in which Secondly, all pixels within the window are normalized in each band using the following formula, expressed as:

[0100] ;

[0101] in: These are the normalized pixel values. It is a band Pixels within the window The original value, and These are the minimum and maximum values ​​for that band across the entire map, plus... To prevent division by zero, the normalized tensor scale obtained at this point is... .

[0102] Fill the above normalization results into the shape of In the tensor, any insufficient parts are padded with zeros, and then used as the input tensor of the model for subsequent inference.

[0103] Step 5.3, generate After a tensor is input into the dual-classification attention U-Net model, the network will simultaneously output two probability maps: one for water bodies. The first image, measuring 512×512, represents the probability that each pixel is predicted to be a body of water; the second image is a shadow probability map. The dimensions are both 512×512, representing the probability that each pixel is predicted as a shadow.

[0104] Step 5.4: Apply thresholds to the water body probability map and the shadow probability map respectively. Perform binarization to generate and The corresponding window-level binary mask for water bodies and shadows is represented as follows:

[0105] ;

[0106] ;

[0107] in: and This represents a window-level binary mask for water bodies and shadows.

[0108] This binarization operation maps the probability to grayscale 0 (background) or 255 (target).

[0109] Step 5.5: The generated water body and shadow binary mask for each window are compared based on their top-left corner coordinates. The data is written back to the corresponding positions in the output GeoTIFF file: the water mask is written to band 1, and the shadow mask is written to band 2. Since there is a 64-pixel overlap between adjacent windows, a "maximum value" strategy is applied to the pixel values ​​in the overlapping area when writing back to the same position. That is, if multiple windows output different values ​​at the same original image coordinates, the result with a value of 255 (target pixel) is used to ensure that the stitched mask image is continuous and seamless at the overlap. By writing back and fusing all windows separately, a dual-band binary mask image covering the entire study area is finally obtained.

[0110] Step 5.6: After writing back the masks for all windows, call GDAL's Flush operation to persistently store the output GeoTIFF data as a file. This file contains two layers: the first band records the global water body binary mask (grayscale 0 / 255); the second band records the global shadow binary mask (grayscale 0 / 255). Simultaneously, the geographic transformation parameters and projection information of the original study area image are fully preserved for subsequent visualization, overlay analysis, and spatial quantitative assessment on GIS platforms or other analysis tools.

[0111] This embodiment also provides a computer device applicable to the case of a remote sensing image water and shadow classification method based on a dual-classification attention network, comprising: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement all or part of the steps of the method described in the above embodiments of the present invention.

[0112] This embodiment also provides a storage medium storing a computer program thereon. When the computer program is executed by a processor, it performs the method in any optional implementation of the above embodiments. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read-Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0113] The storage medium proposed in this embodiment and the data storage method proposed in the above embodiments belong to the same inventive concept. Technical details not described in detail in this embodiment can be found in the above embodiments, and this embodiment has the same beneficial effects as the above embodiments.

[0114] In summary, the automated water body extraction method based on the U-Net dual-classification network model with attention mechanism proposed in this invention is not only more efficient and accurate, but also significantly reduces the amount of manual annotation work required by traditional methods. It achieves smoother and more complete extraction results at different scales, especially for smaller and more complex water bodies, and effectively overcomes the interference of ice and snow shadow regions on water body identification results, demonstrating better robustness and stability overall.

[0115] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. A method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network, characterized in that: include, The Sentinel-2 original image is preprocessed using the nearest neighbor interpolation method to generate a multi-band composite image with a predetermined resolution. Based on multi-band synthetic images, normalized water index is calculated and brightness channels are extracted to generate water mask and shadow mask respectively; The calculation of the normalized water index and extraction of the brightness channel based on multi-band synthetic images includes: Ground reflectance in the green and near-infrared bands was extracted from multi-band composite images, and the normalized water index was calculated. The formula is: in: and The ground reflectance in the green light band and near-infrared band are respectively used to binarize the normalized water index using empirical thresholds to generate a water mask. Extract the red, green, and blue bands from the multi-band composite image, convert it to the HSV color space, and extract the luminance channel. Generate a preliminary shadow mask , is represented as: in, Indicates position The area was identified as a shaded region. Using the brightness threshold, a shadow mask is obtained; Construct a sample set containing multi-band synthetic images, water body masks, and shadow masks, and divide the sample set into a training set and a validation set; A dual-classification attention network model is constructed based on the training set, and the dual-classification attention network model is optimized and trained. A trained dual-classification attention network model is used to perform sliding window inference on multi-band synthetic images, and the predicted binary masks are fused and stitched together to output a dual-band water / shadow binary mask image. The step of using a trained dual-classification attention network model to perform sliding window inference on multi-band synthetic images includes: The cropped multi-band composite image is divided into blocks of 512×512 pixels and scanned. For each band, the global minimum and maximum values ​​are calculated in the entire image. Using a window size of 512×512 pixels and an overlap of 64 pixels, the entire image is traversed in both row and column directions. For any top-left corner coordinate... The window area is used to read the raw data of the area. First, the raw pixel values ​​of the area in the three bands are read and saved as a window with 3 channels and a height of [missing information]. Width is A three-dimensional array; Normalize all pixels within the window for each band, as shown below: in: These are the normalized pixel values. For band Pixels within the window The original value, and bands Minimum and maximum values ​​within the entire graph; The normalized pixel values ​​are organized into a height of pixels, width Pixels, number of channels The three-dimensional tensor is used as the model input; Using the generated 3D tensor as network input, the model simultaneously outputs a water body probability map and a shadow probability map. This represents the probability that each pixel is predicted to be a body of water; Shadow probability map , which represents the probability that each pixel is predicted to be a shadow; Binarize the water body probability map and the shadow probability map respectively to generate corresponding window-level binary masks for water bodies and shadows, as follows: in: and This represents a window-level binary mask for water bodies and shadows. Write the generated water body and shadow binary mask for each window back to the corresponding position in the output file according to the coordinates of the top left corner; When writing back to the same location, the maximum value strategy is applied to the pixel values ​​of the overlapping area. If multiple windows output different values ​​at the same coordinates of the original image, the result of the target pixel is taken as the standard. All windows are written back and merged to obtain a dual-band binary mask image.

2. The method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network as described in claim 1, characterized in that: The constructed sample set, comprising multi-band synthetic images, water masks, and shadow masks, includes: Multi-band composite images, water masks, and shadow masks are simultaneously slid-cropped using a fixed window of 256×256 pixels, with no overlap between rows and columns. If the edge area is less than 256×256 pixels, it is discarded without any filling. For each cropping window, a set of three files is generated: a 256×256×3 multi-band composite image sub-block; a corresponding 256×256 water body binary mask sub-block; and a corresponding 256×256 shadow binary mask sub-block. Iterate through all the sub-blocks. If there is at least one pixel with a value of 255 in the water mask of the sub-block, then the sub-block is recorded as a water sample. If there is at least one pixel with a value of 255 in the shadow mask of the sub-block, then the sub-block is recorded as a shadow sample. If the above conditions are met at the same time, the sub-block is simultaneously labeled as a water sample and a shadow sample, and two sets of labels, water sample and shadow sample, are retained respectively. The selected water samples and shadow samples were randomly divided into training and validation sets at a ratio of 8:

2.

3. The method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network as described in claim 2, characterized in that: The dual-classification attention network model constructed based on the training set includes: A four-layer downsampling encoder is used, with each layer consisting of: a 3×3 convolution, with the number of output channels starting from 64 and doubling with each layer; a ReLU activation function; a probability of randomly deactivating the layer is set to 0.2; a 3×3 convolution with a ReLU activation function; and 2×2 max pooling, downsampling to the next layer. The following four branches are executed in parallel on the output feature map of the last layer of the encoder: as the bottleneck module of the dilated spatial pyramid pooling: one 1×1 convolution with ReLU activation; three 3×3 dilated convolutions with dilation rates of 6, 12 and 18 respectively, all with ReLU activation; after concatenating the outputs of the four branches, a fused feature map is generated by passing a 3×3 convolution and ReLU activation once. Decoders for the water body branch and the shadow branch are constructed separately, and bilinear upsampling is performed on the output of the void space pyramid pooling bottleneck module. The upsampled features are concatenated with the skip connection features of the encoder layer and the 2×2 upsampled skip connection features; The stitching results are then input into the CBAM channel attention module, the CBAM spatial attention module, and the attention gating module in sequence. The features weighted by the attention-gated module are concatenated with the upsampled features, and then two 3×3 convolutions are performed to restore the current number of decoding channels; the process is repeated until the spatial resolution is restored to the same as the input. A single-channel water body probability map is generated at the end of the water body branch by 1×1 convolution and sigmoid activation. A single-channel shadow probability map is generated at the end of the shadow branch using 1×1 convolution and sigmoid activation; a mutual exclusion loss is added to suppress the overlap between the water body and the shadow space, defined as: in: For mutually exclusive losses, and pixels The probability plots output in the water body branch and the shaded branch, This is the mutual exclusion loss weighting coefficient.

4. The method for classifying water bodies and shadows in remote sensing images based on a dual-classification attention network as described in claim 3, characterized in that: The optimization training of the dual-classification attention network model includes: Using a custom data loader, multi-band images from the training set, along with corresponding water bodies and shadow binary masks, are loaded into the model in batches, with the input size fixed at 256×256. During the model compilation phase, the loaded attention U-Net network is configured with the Adam optimizer and an initial learning rate of 1×10⁻⁶. -4 The parameters were updated, and the loss functions for both the water body branch and the shadow branch were defined as the sum of the binary cross-entropy and DiceLoss. The evaluation index for both the water body branch and the shadow branch was set to classification accuracy. The model checkpoint callback automatically saves the weights when the loss on the validation set is lowest in each round. After each training round, forward inference is performed on the complete validation set to calculate and record the accuracy, recall, F1 score and IoU index of the water branch and the shadow branch to evaluate the model's generalization performance. When the validation set loss no longer decreases for three consecutive rounds, the training process will terminate early and the weight file with the optimal validation loss will be automatically loaded.

5. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, it implements the steps of the remote sensing image water and shadow classification method based on a dual-classification attention network as described in any one of claims 1 to 4.

6. A 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 the remote sensing image water and shadow classification method based on a dual-classification attention network as described in any one of claims 1 to 4.

Citation Information

Patent Citations

  • Remote sensing image city building extraction method based on shadow compensation and U-net

    CN114005042A

  • Method and device for repairing shadow area of remote sensing image and electronic equipment

    CN118446938A

  • Satellite remote sensing image block classification water body identification method based on supervised learning algorithm

    CN119785234A

  • Aquatic vegetation classification method and device based on remote sensing image and storage medium

    CN120259889A