Tree image semantic matting method based on multi-scale dynamic attention
By employing a multi-scale dynamic attention-based semantic matting method for tree images, combined with the U-Net backbone network and an adaptive edge enhancement module, the problem of handling complex boundaries and multi-scale details in tree image matting is solved, achieving accurate matting of tree structures.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-01-08
- Publication Date
- 2026-04-07
AI Technical Summary
Existing tree image matting techniques face challenges such as complex jagged outlines of leaf edges, light transmission effects of semi-transparent leaves, and interactive occlusion between dense branches and the background. Traditional methods struggle to handle irregular boundaries and multi-scale details of trees and lack adaptive capabilities.
A semantic matting method for tree images using multi-scale dynamic attention is adopted. By combining the U-Net backbone network with a multi-scale dynamic spatial attention module and an adaptive edge enhancement module, the method adaptively processes the multi-scale characteristics of trees and generates transparency masks.
It accurately captures the full-scale structural features of trees, from microscopic leaf vein texture to macroscopic contours, improving the adaptability and accuracy of tree matting and overcoming the limitations of traditional methods in tree image processing.
Smart Images

Figure CN121458986B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method for semantic matting of tree images based on multi-scale dynamic attention. Background Technology
[0002] Tree image matting, an important branch of computer vision, is specifically used to extract plant foregrounds from complex natural scenes. Unlike general image matting, tree matting faces unique technical challenges: the complex jagged outlines of leaf edges, the light transmission effects produced by translucent leaves, and the interactive occlusion between dense branches and the background. This technology has significant application value in fields such as smart forestry, ecological monitoring, landscape design, virtual reality, and film and television post-production.
[0003] Currently, the mathematical model for tree matting still follows the traditional matting formula.
[0004] ;
[0005] In the above formula , These represent the observed pixel value, transparency value, foreground value, and background value, respectively. For tree images, Solving this problem presents a more severe challenge because the irregularity of the plant boundary and the semi-transparent nature of the leaves make this underconstrained problem more complex.
[0006] While traditional triangulation-based methods offer better constraints, they have significant limitations in tree image processing. First, manually drawing accurate triangulations for complex tree outlines is extremely difficult and time-consuming. Second, traditional methods lack targeted modeling of plant-specific visual features, leading to blurred boundaries or loss of detail when processing dense foliage.
[0007] With the rise of large-scale pre-trained models such as SAM and ViTMatte, significant progress has been made in general image segmentation tasks, but shortcomings remain in fine-grained matting of tree and other plant images. SAM models are primarily designed for instance segmentation, and their output binary masks cannot effectively handle the semi-transparent regions and complex boundaries of leaves. While methods like ViTMatte support matting tasks, their fixed attention mechanisms lack adaptability to different input samples, resulting in limited generalization performance when dealing with trees of varying shapes. Existing matting datasets such as AIM500 and P3M-10K mainly contain objects like people and animals, with a scarcity of high-quality labeled data specifically for tree and other plant images, leading to poor model performance on plant images. Furthermore, existing methods generally employ static network architectures, failing to dynamically adjust processing strategies based on input image features, thus limiting their effectiveness in handling complex tree boundaries and multi-scale details. Summary of the Invention
[0008] To overcome the technical deficiencies of existing technologies, this invention provides a method for semantic matting of tree images based on multi-scale dynamic attention.
[0009] The technical solution adopted in this invention is a method for semantic matting of tree images based on multi-scale dynamic attention, comprising the following steps:
[0010] The original tree image and the target bounding box information provided by the user are preprocessed, and the target bounding box information is encoded into spatial location embedding features;
[0011] The preprocessed image is input into the semantic awareness coding module to extract multi-level semantic features, and the spatial location embedding features are fused with the multi-level semantic features to obtain an enhanced multi-scale semantic feature set.
[0012] The multi-scale semantic feature set is input into the dynamic enhancement matting module, and features are extracted and restored through the U-Net backbone network. The multi-scale dynamic spatial attention module is embedded in the bottleneck layer of the U-Net backbone network to perform adaptive feature enhancement, and an adaptive edge enhancement module is integrated in the decoding path to refine the boundary.
[0013] The features processed by the dynamic enhancement matting module are fused to generate the final transparency mask.
[0014] Preferably, preprocessing the original tree image includes: scaling the image to a predetermined resolution and performing pixel normalization.
[0015] Preferably, the semantic-aware encoding module includes:
[0016] The patch embedding layer is configured to divide the preprocessed image into image patches and linearly map them into feature vectors to form an initial feature sequence;
[0017] The encoder, which consists of multiple multi-head self-attention layers connected to the patch embedding layer, is used to process the initial feature sequence to extract multi-scale semantic information and generate a deep semantic feature sequence.
[0018] The feature fusion layer is configured to fuse the spatial location embedding features with the deep semantic feature sequence, and output the enhanced multi-scale semantic feature set after reconstruction.
[0019] Preferably, the multi-layer multi-head self-attention layer has at least four layers, with each layer using eight attention heads.
[0020] Preferably, all hierarchical features obtained in the multi-layer multi-head self-attention layer are subjected to layer normalization processing.
[0021] Preferably, the multi-scale dynamic spatial attention module performs the following operations: receiving feature maps from the bottleneck layer of the U-Net backbone network as input; performing global average pooling on the input feature maps along the channel dimension to obtain global features for each channel;
[0022] The global features are processed sequentially through a first convolutional layer, a ReLU activation function, and a second convolutional layer to generate a one-dimensional weight vector, and then the one-dimensional weight vector is rearranged into a two-dimensional convolutional kernel.
[0023] Simultaneously, the input feature map is averaged along the channel dimension to generate a single-channel spatial feature map;
[0024] The two-dimensional convolution kernel is used to perform a two-dimensional convolution operation with the single-channel spatial feature map, and the convolution result is normalized by the Sigmoid function to generate a spatial attention map.
[0025] The spatial attention map is multiplied element-wise with the input feature map to output a weighted feature map.
[0026] Preferably, the adaptive edge enhancement module performs the following operations: receiving feature maps from the decoding path of the U-Net backbone network as input; performing multi-scale edge detection on the input feature maps in parallel, extracting edge features using first, second, and third convolutional kernels respectively, wherein the first, second, and third convolutional kernels have different receptive fields; concatenating the obtained multi-scale edge feature maps and generating a unified edge feature map through a fusion convolutional layer; simultaneously performing global average pooling on the input feature maps and predicting adaptive enhancement intensity coefficients through a fully connected layer; multiplying the unified edge feature map with the obtained enhancement intensity coefficients to obtain an adaptive weighted edge weight map; concatenating the edge weight map with the input feature map and performing feature transformation through at least one convolutional layer and activation function to obtain primary enhancement features; concatenating the primary enhancement features with the input feature map a second time, and finally outputting the result after channel fusion through a 1×1 convolutional layer.
[0027] Preferably, during the training process, a cross-domain training strategy is adopted, and the training dataset used includes a general matting dataset of people, animals, and everyday objects, as well as a specially constructed tree matting dataset.
[0028] Preferably, the feature fusion output module integrates the attention-enhancing and edge-refining features through convolutional layers and upsampling layers to generate the final transparency mask.
[0029] The beneficial effects of this invention are: 1. This invention uses an adaptive edge enhancement module to specifically fuse the multi-level features output by the encoder with the high-level semantic features of the decoder. Targeting the multi-scale hierarchical characteristics of tree structures, it innovatively employs small-sized convolutional kernels to detect microscopic texture details of leaves, medium-sized convolutional kernels to process branching structures, and large-sized convolutional kernels to capture the macroscopic edge contours of the trunk. This three-layer parallel hierarchical processing strategy can simultaneously and accurately capture the full-scale structural features of trees, from microscopic leaf vein textures to macroscopic overall contours. Compared to portrait matting techniques, which mainly focus on optimizing local details at a single scale such as hair edges, tree matting scenarios need to simultaneously consider three structural levels with distinctly different thicknesses: leaves, branches, and trunks.
[0030] 2. The dynamic spatial attention module in this invention enhances the network's adaptability to different tree species and complex background environments by generating unique convolutional kernel parameters for each sample. In tree matting scenarios, different tree species exhibit significant differences in leaf density, transparency, and texture, making it difficult for traditional fixed convolutional kernels to adapt to this diversity. This module can dynamically adjust the attention weights based on the specific features of the input sample, demonstrating excellent performance in handling complex scenes such as dense forests, backlit shots, and seasonal changes. Compared to the relatively standardized scenes of portrait matting, tree matting demands a higher level of adaptability due to the complexity of the environment.
[0031] 3. In this invention, the multi-scale adaptive feature fusion for tree detail processing utilizes an adaptive edge enhancement module to specifically fuse the multi-level features of the encoder with the semantic features of the decoder. Addressing the multi-scale characteristics of tree structures, a 3×3 convolution is used to detect leaf texture details, a 5×5 convolution to process medium-scale structures in branches, and a 7×7 convolution to capture rough edges in the trunk. This layered processing strategy accurately captures full-scale features of trees, from microscopic leaf veins to macroscopic contours. Compared to portrait matting, which primarily focuses on single-scale details such as hair strands, tree matting requires simultaneous processing of three structural levels of varying thickness: leaves, branches, and trunk. This module's multi-scale parallel processing effectively addresses this challenge. Attached Figure Description
[0032] One or more embodiments are illustrated by way of example with reference numerals in the accompanying drawings. These illustrations do not constitute a limitation on the embodiments. Elements with the same reference numerals in the drawings are denoted as similar elements. Unless otherwise stated, the figures in the drawings are not to be limited by scale.
[0033] Figure 1 This is a flowchart of the steps of the present invention. Detailed Implementation
[0034] To make the objectives, technical solutions, and advantages of this invention clearer, the various embodiments of this invention will be described in detail below with reference to the accompanying drawings. However, those skilled in the art will understand that many technical details have been provided in the various embodiments of this invention to facilitate a better understanding of this application. However, the technical solutions claimed in the claims of this application can be implemented even without these technical details and with various variations and modifications based on the following embodiments.
[0035] like Figure 1 As shown, this embodiment provides a method for semantic matting of tree images based on multi-scale dynamic attention, including the following steps:
[0036] The original tree image and the target bounding box information provided by the user are preprocessed, and the target bounding box information is encoded into spatial location embedding features;
[0037] The preprocessed image is input into the semantic awareness coding module to extract multi-level semantic features, and the spatial location embedding features are fused with the multi-level semantic features to obtain an enhanced multi-scale semantic feature set.
[0038] The multi-scale semantic feature set is input into the dynamic enhancement matting module, and feature extraction and restoration are performed through the U-Net backbone network. A multi-scale dynamic spatial attention module is embedded in the bottleneck layer of the U-Net backbone network for adaptive feature enhancement, while an adaptive edge enhancement module is integrated into the decoding path for boundary refinement. For the dynamic enhancement matting module, a progressive training strategy is adopted: pre-training is performed on the basic U-Net architecture, and then the dynamic spatial attention module and the adaptive edge enhancement module are gradually enabled for joint optimization. Training uses the AdamW optimizer with a batch size of 1 and a cosine annealing learning rate scheduler for 25,000 training epochs. The loss function includes L1 loss for known regions, L1 loss for unknown regions, Laplacian boundary constraint loss, and gradient penalty loss. Finally, prediction and evaluation are performed on the test set.
[0039] The features processed by the dynamic enhancement matting module are fused to generate the final transparency mask. The feature fusion output module integrates the attention-enhanced and edge-refined features through convolutional layers and upsampling layers to generate the final transparency mask.
[0040] During training, a cross-domain training strategy was employed. The training datasets used included general matting datasets for people, animals, and everyday objects, as well as a specially constructed tree matting dataset. The model was built based on this method, and a diverse dataset combination strategy was used for constructing the training datasets, including classic matting benchmark datasets such as RW100, AIM500, AM2K, and RW636, as well as a self-constructed tree-specific dataset. Specifically, the RW100 dataset provides rich matting samples from real-world scenes, the AIM500 dataset covers a large number of high-resolution automatic matting samples, the AM2K dataset contains fine matting annotations in complex backgrounds, and the RW636 dataset focuses on real-world portrait matting tasks. These datasets cover various types of foreground objects, including images of people, animals, everyday objects, and our self-constructed tree images. To further improve the model's generalization ability and robustness, a cross-domain training strategy was adopted, using image types different from trees (such as portraits and animals) for joint training, enabling the model to learn more general boundary recognition and transparency prediction capabilities. We independently constructed a tree dataset containing carefully selected tree images, covering samples from different seasons, lighting conditions, tree species, and complexity levels. Each image is professionally labeled to ensure the accuracy of boundaries and transparency. This multi-domain data fusion training strategy not only enhances the model's ability to handle complex tree textures and irregular boundaries but also significantly improves the model's adaptability and accuracy in various real-world application scenarios.
[0041] Preprocessing of the original tree images includes: scaling the images to a predetermined resolution and performing pixel standardization. To ensure input consistency and feature distribution stability, the original tree images are standardized in size and numerical values. First, the input images are uniformly adjusted to 1024×1024 pixels. Then, standardization is performed by subtracting the mean and dividing by the standard deviation for each pixel channel to remove illumination and color biases. Simultaneously, user-provided bounding box cues guide the model to focus on the target tree region, thereby improving the accuracy and generalization performance of target localization. The preprocessed original tree images are then fed into a semantic-aware encoding module to extract multi-level semantic features.
[0042] The mathematical expression of the input data is as follows:
[0043] ;
[0044] Where i is the original input image tensor with a size of B×3×H×W, where B represents the batch size, 3 represents the three RGB channels, and H and W represent the height and width of the original image.
[0045] The image standardization operation is as follows:
[0046] ;
[0047] in This is a pixel mean vector, corresponding to the average brightness value of the three channels. The pixel standard deviation vector corresponds to the brightness distribution scale of the three channels.
[0048] The final dimensions were adjusted to:
[0049] ;
[0050] Where I_norm represents the standardized image tensor, which is normalized by removing the mean and dividing the variance. Resize() represents the image resizing function, which scales the input image to a fixed size. I represents the adjusted and standardized image input, with a size of B×3×1024×1024. The final standardized and size-aligned image I is used as the input for the subsequent encoder.
[0051] The semantic-aware encoding module employs a visual transformer, which consists of five levels, labeled as follows: , among them The first layer is the patch embedding layer, followed by multi-head self-attention layers from the second to the fifth layer. For the image encoder of the semantically aware encoding module, the pre-trained model weights are first loaded for initialization, and then adaptive training is performed on the tree matting dataset using efficient parameter fine-tuning techniques. The training uses an adaptive moment estimation optimizer, with a batch size of 1, a learning rate of 0.000008, a rank of 16 for fine-tuning parameters, and a scaling factor of 16, to obtain encoder parameters optimized for tree images.
[0052] The patch embedding layer is configured to divide the preprocessed image into image patches and linearly map them into feature vectors to form an initial feature sequence;
[0053] The encoder, which consists of multiple multi-head self-attention layers connected to the patch embedding layer, is used to process the initial feature sequence to extract multi-scale semantic information and generate a deep semantic feature sequence.
[0054] A feature fusion layer is configured to fuse the spatial location embedding features with the deep semantic feature sequence, and output the enhanced multi-scale semantic feature set after reconstruction. The multi-layer, multi-head self-attention layer has at least four layers, each using eight attention heads.
[0055] First, the input image I undergoes a patch embedding operation, dividing the 2D image into multiple local patches and mapping them to a high-dimensional feature space. A 16×16 convolutional kernel and a stride of 16 are used to divide the input image into blocks, resulting in 64×64 patches. Each patch is encoded as a 1024-dimensional maintenance vector. To preserve spatial information, absolute position encoding is added after embedding, with the specific formula as follows:
[0056] ;
[0057] in This represents the initial patch embedding features, with dimensions B×4096×1024. There are a total of 64×64=4096 patches, and each patch is mapped to a 1024-dimensional feature vector. This indicates a patch embedding operation, which uses a 16×16 convolution kernel and a stride of 16 to perform patching and linear projection on the input image. This represents absolute position encoding, used to preserve the location information of each patch in space. This indicates the addition of features, fusing embedded features with positional encoding.
[0058] Second to fifth floors ( – (Multi-head self-attention layer): Starting from the second layer, global and local features are extracted layer by layer through multi-head self-attention and a feedforward network. Each layer includes an attention mechanism, residual connections, and layer normalization. The calculation formula for layers two to five is as follows:
[0059] ;
[0060] ;
[0061] ;
[0062] ;
[0063] in , , These are the query, key, and value vector matrices for the i-th layer, respectively. This represents the input feature sequence of the previous layer (the (i-1)th layer). This indicates the output of the multi-head self-attention layer. This means splicing all attention along the channel dimension. This represents the attention output features, which represent the contextual information that is attended to in different subspaces. This represents the feature sequence output by the i-th layer, which serves as the input to the next layer. The representation layer normalization operation stabilizes the feature distribution.
[0064] Bounding box cue encoding enhances the model's ability to locate target tree regions by encoding the bounding box coordinates. The input prompt encoder maps to location embedding features:
[0065] ;
[0066] Then, it is boosted to a dense embedding corresponding to the spatial dimension through two-dimensional convolution:
[0067] ;
[0068] The formula above: The sparse location embedding of the bounding box is a low-dimensional feature vector generated from the bounding box coordinates. Representing dense spatial features for alignment with semantic feature maps. This represents a location encoding function that maps numerical coordinates to continuous spatial features. This represents a two-dimensional convolution operation used to increase feature dimensions and expand spatial resolution, enabling the model to explicitly perceive the spatial location and extent of trees.
[0069] Feature reconstruction and fusion, after – After multi-layer attention calculation, the sequence features are... The data is reconstructed into a spatial feature map. Simultaneously, to incorporate location information, the dense cue features are fused with semantic features after undergoing a 1×1 convolution mapping.
[0070] ;
[0071] ;
[0072] in This represents the spatial feature map of the i-th layer. This refers to the reshaping operation, which rearranges a linear sequence into a spatial structure. This represents the highest-level semantic feature map. This refers to the enhanced semantic feature, which integrates image semantics and location information after fusing the prompt information.
[0073] Feature standardization and output: In order to ensure the numerical stability of features in the subsequent dynamic matting module, layer normalization is performed on all levels of features to obtain the final multi-scale semantic enhancement feature set.
[0074] The multi-scale dynamic spatial attention module adaptively generates spatial attention convolution kernels for each input sample, dynamically adjusts the shape and size of the convolution kernels according to the input features, and finally outputs a weighted feature map. This enhances the attention and processing capability for input features. It performs the following operations: receives feature maps from the bottleneck layer of the U-Net backbone network as input; and performs global average pooling on the input feature maps along the channel dimension to obtain the global features for each channel.
[0075] The global features are processed sequentially through a first convolutional layer, a ReLU activation function, and a second convolutional layer to generate a one-dimensional weight vector, and then the one-dimensional weight vector is rearranged into a two-dimensional convolutional kernel.
[0076] Simultaneously, the input feature map is averaged along the channel dimension to generate a single-channel spatial feature map;
[0077] The two-dimensional convolution kernel is used to perform a two-dimensional convolution operation with the single-channel spatial feature map, and the convolution result is normalized by the Sigmoid function to generate a spatial attention map.
[0078] The spatial attention map is multiplied element-wise with the input feature map to output a weighted feature map.
[0079] The specific calculation formula is as follows:
[0080] ;
[0081] ;
[0082] ;
[0083] ;
[0084] ;
[0085] ;
[0086] ;
[0087] ;
[0088] in, For input features, Let B represent the b-th sample, B be the batch size, C be the number of channels, H be the height of the feature map, and W be the width of the feature map. This represents the global average pooling feature of each channel of the b-th sample. These are learnable parameters. This refers to the dynamically generated convolution kernel for sample b. This represents the spatial characteristics of a single channel of a sample. This indicates the result of zero-filling in the spatial dimension as needed. , Indicates using right The original response map obtained by performing convolution. This represents the spatial attention weights after Sigmoid normalization. This represents the weighted output feature map of sample b, where ReLU is the activation function.
[0089] The adaptive edge enhancement module, through multi-scale edge detection and adaptive enhancement mechanisms, specifically optimizes complex edge structures (such as thin edges of leaves, medium edges of branches, and thick edges of trunks) in tree matting, improving the feature extraction capability for semi-transparent areas and fine structures of trees. It performs the following operations:
[0090] The system receives feature maps from the decoding path of the U-Net backbone network as input; performs multi-scale edge detection on the input feature maps in parallel, extracting edge features using first, second, and third convolutional kernels, where the first, second, and third convolutional kernels have different receptive fields; concatenates the obtained multi-scale edge feature maps and generates a unified edge feature map through a fusion convolutional layer; simultaneously, performs global average pooling on the input feature maps and predicts adaptive enhancement intensity coefficients through a fully connected layer; multiplies the unified edge feature map with the obtained enhancement intensity coefficients to obtain an adaptively weighted edge weight map; concatenates the edge weight map with the input feature map and performs feature transformation through at least one convolutional layer and activation function to obtain primary enhancement features; concatenates the primary enhancement features with the input feature map a second time, and finally outputs the result after channel fusion through a 1×1 convolutional layer.
[0091] The specific calculation formula is as follows:
[0092] ;
[0093] ;
[0094] ;
[0095] ;
[0096] ;
[0097] ;
[0098] ;
[0099] ;
[0100] ;
[0101] ;
[0102] ;
[0103] ;
[0104] in, For input features, For batch size, For the number of channels, For feature map height, This represents the width of the feature map. These represent the edge maps extracted by 3×3, 5×5, and 7×7 convolutions, respectively. The edge map after fusion. This is a global average pooling feature. To adaptively enhance strength, The basic enhancement strength hyperparameter (default 0.3) is used. To enhance the edge weights, For feature-edge stitching results, To enhance features, For the final splicing features, For output features. For learnable parameters, For the Sigmoid function, For batch normalization operations, This is the activation function.
[0105] The combined loss function L = is used during model training. + + The network is trained under supervision, in which Supervised matting decoder module, Supervise the ternary graph prediction branch module. Supervise the SAM feature enhancement module. The loss function used is a composite loss function consisting of an unknown region loss function, a known region loss function, a Laplacian pyramid loss function, and a gradient penalty loss function. The standardized focus loss function is used. An auxiliary loss function is used, consisting of a token-based loss function and a bounding box cueing loss function.
[0106] The specific process is as follows: First, multiple publicly available datasets in the field of image matting are used for training, including classic matting benchmark datasets such as RW100, AIM500, AM2K, and RW636, as well as a self-constructed tree-specific dataset. When inputting images into the model, the images are uniformly sized to 1024×1024, and data augmentation operations are performed followed by random cropping to increase the diversity and generalization ability of the training set. In addition, the system automatically generates bounding box information, extracts the boundary coordinates of the foreground region from the alpha mask, and inputs them into the encoding module after normalization.
[0107] In the feature encoding stage, the pre-trained visual transformer encoder network from SAM is used as the backbone feature extractor, leveraging its powerful semantic understanding capabilities. The encoder contains multiple levels of transformer blocks, and low-rank adaptive fine-tuning techniques are used to adapt the image segmentation model, optimizing for the image matting task while preserving pre-trained features. These levels are labeled as multi-scale features: shallow features, mid-level features, deep features, and top-level features. First, low-level texture features of the image are extracted at the shallow level, and then sequentially passed through the deep transformer blocks. Through excellent long-range dependency information processing capabilities, semantic features at different scales are further extracted, resulting in a feature dimension of 1024.
[0108] The SAM encoder features at different scales are fed into the semantic perception branch and the detail capture branch, respectively. In the semantic perception branch, a dynamic spatial attention module enhances the network's ability to perceive spatial details. This module adaptively generates dynamic convolutional kernels based on the input, allowing the network to focus more on the spatial relationships of the target subject. In the detail capture branch, an adaptive edge enhancement module helps the network capture local detail features. This module employs a multi-scale edge detector and adaptively predicts enhancement intensity, specifically optimizing for the fine details of tree branches or leaf veins and the fineness of detail textures. Finally, the final transparency mask map is obtained through the branch fusion module of the U-Net decoder.
[0109] Those skilled in the art will understand that the above embodiments are specific examples of implementing the present invention, and in practical applications, various changes in form and detail may be made without departing from the spirit and scope of the present invention.
Claims
1. A method for semantic matting of tree images based on multi-scale dynamic attention, characterized in that: Includes the following steps, The original tree image and the target bounding box information provided by the user are preprocessed, and the target bounding box information is encoded into spatial location embedding features; The preprocessed image is input into the semantic awareness coding module to extract multi-level semantic features, and the spatial location embedding features are fused with the multi-level semantic features to obtain an enhanced multi-scale semantic feature set. The multi-scale semantic feature set is input into the dynamic enhancement matting module, and features are extracted and restored through the U-Net backbone network. The multi-scale dynamic spatial attention module is embedded in the bottleneck layer of the U-Net backbone network to perform adaptive feature enhancement, and an adaptive edge enhancement module is integrated in the decoding path to refine the boundary. The features processed by the dynamic enhancement matting module are fused to generate the final transparency mask; The multi-scale dynamic spatial attention module performs the following operations: receives feature maps from the bottleneck layer of the U-Net backbone network as input; performs global average pooling on the input feature maps along the channel dimension to obtain global features for each channel; The global features are processed sequentially through a first convolutional layer, a ReLU activation function, and a second convolutional layer to generate a one-dimensional weight vector, and then the one-dimensional weight vector is rearranged into a two-dimensional convolutional kernel. Simultaneously, the input feature map is averaged along the channel dimension to generate a single-channel spatial feature map; The two-dimensional convolution kernel is used to perform a two-dimensional convolution operation with the single-channel spatial feature map, and the convolution result is normalized by the Sigmoid function to generate a spatial attention map. The spatial attention map is multiplied element-wise with the input feature map to output a weighted feature map; The adaptive edge enhancement module performs the following operations: receiving feature maps from the decoding path of the U-Net backbone network as input; performing multi-scale edge detection on the input feature maps in parallel, extracting edge features using first, second, and third convolutional kernels respectively, wherein the first, second, and third convolutional kernels have different receptive fields; concatenating the obtained multi-scale edge feature maps and generating a unified edge feature map through a fusion convolutional layer; simultaneously performing global average pooling on the input feature maps and predicting adaptive enhancement intensity coefficients through a fully connected layer; multiplying the unified edge feature map with the obtained enhancement intensity coefficients to obtain an adaptive weighted edge weight map; concatenating the edge weight map with the input feature map and performing feature transformation through at least one convolutional layer and activation function to obtain primary enhancement features; concatenating the primary enhancement features with the input feature map a second time, and finally outputting the result after channel fusion through a 1×1 convolutional layer.
2. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 1, characterized in that: Preprocessing the original tree images includes scaling the images to a predetermined resolution and performing pixel normalization.
3. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 1, characterized in that: The semantic-aware encoding module includes: a patch embedding layer, which is configured to divide the preprocessed image into image patches and linearly map them into feature vectors to form an initial feature sequence; The encoder, which consists of multiple multi-head self-attention layers connected to the patch embedding layer, is used to process the initial feature sequence to extract multi-scale semantic information and generate a deep semantic feature sequence. The feature fusion layer is configured to fuse the spatial location embedding features with the deep semantic feature sequence, and output the enhanced multi-scale semantic feature set after reconstruction.
4. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 3, characterized in that: The multi-layered multi-head self-attention layer has at least four layers, with each layer using eight attention heads.
5. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 4, characterized in that: All hierarchical features obtained from the multi-layer multi-head self-attention layer are subjected to layer normalization.
6. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 1, characterized in that: During training, a cross-domain training strategy was adopted, and the training datasets used included general matting datasets of people, animals, and everyday objects, as well as a specially constructed tree matting dataset.
7. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 1, characterized in that: The feature fusion output module integrates attention-enhancing and edge-refining features through convolutional and upsampling layers to generate the final transparency mask.
8. The method for semantic matting of tree images based on multi-scale dynamic attention according to claim 1, characterized in that: The spatial location embedding feature encodes the target bounding box information into a feature vector and then concatenates and fuses it with the multi-level semantic features extracted by the semantic awareness encoding module.
Citation Information
Patent Citations
Natural image matting method
CN118822830A
Automatic matting method for adaptive feature extraction and semantic guidance
CN119832253A