Image-sensitive text desensitization method, device, equipment and medium
Through the multi-scale fusion of residual convolution network and feature pyramid network, combined with spatial attention and self-attention mechanism, the problem of accurate detection and natural repair of sensitive subtitles in the image is solved, efficient recognition and natural desensitization of small-sized sensitive texts is achieved, and the security and usability of image content is improved.
Patent Information
- Application Number
- CN202510673103.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2045-05-23
AI Technical Summary
When processing sensitive subtitles embedded in images, the prior art has problems such as inaccurate detection and unnatural image repair after desensitization. Especially when adapting complex backgrounds, small-size text and multi-scene adaptation, the detection accuracy is not high, the repair effect is stiff, and the semantic understanding ability is weak.
Multiple feature maps are extracted using residual convolution network, multi-scale fusion is performed through feature pyramid networks, optimized attention feature maps are generated in combination with spatial attention mechanisms, candidate area coordinates are generated using regional candidate networks, text sequences are extracted based on the self-attention mechanism, and sensitive word detection is performed through semantic classification models, and local texture repair is finally performed.
It improves the detection ability of sensitive text in small sizes in the image, realizes accurate identification and natural desensitization of sensitive areas, and enhances the security and usability of image content.
Smart Images

Figure CN120198925B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to a method, device, equipment and storage medium for desensitizing image-sensitive text. Background Art
[0002] With the acceleration of digitalization, images, as a vital carrier of information dissemination, are widely used in a variety of industries, including healthcare, fintech, government services, and media communications. Large amounts of image data often contain critical textual information, particularly sensitive content embedded in images in the form of captions, such as user identities, diagnostic information, transaction details, addresses, and phone numbers. If these contents are made public without processing, they can easily lead to personal privacy breaches, data security incidents, and compliance risks.
[0003] In the healthcare business, electronic medical records, imaging reports, prescriptions and other image information often contain text information such as patient identity information, medical numbers, and treatment details. Due to the high privacy of medical images, hospitals need to accurately detect and remove sensitive subtitle areas during data sharing and research data publishing. However, existing methods are easily disturbed by the characteristics of medical images with high-density typesetting, small font presentation and complex background textures. In particular, solutions based on traditional target detection or edge detection have significantly reduced performance on images with irregular structures or partial occlusions. In addition, during the image desensitization process, existing subtitle removal methods are still mainly based on fuzzy filling, occlusion frame covering and other methods. Although the operation is simple, it is very easy to leave obvious traces, affecting the integrity of the image, which is particularly detrimental to the subsequent clinical diagnosis or teaching research of medical images.
[0004] In the fintech business sector, processes such as credit approval, insurance claims, and risk management analysis often involve the collection and processing of image data including screenshots of bills, photos of contracts, and receipts for on-site photography. These images may contain sensitive information such as customer names, bank card numbers, and loan amounts embedded in the images via captions. Currently, widely used caption detection methods primarily rely on convolutional neural network image segmentation models (such as FCN) or object detection frameworks (such as YOLO and Faster RCNN) to locate text areas within images. However, these methods exhibit poor robustness when processing small-sized captions, images embedded in complex backgrounds, or images with compression distortion, often leading to missed or incorrect detection of caption areas. This is particularly true for financial images containing multi-scale, small-object captions, where the accuracy is insufficient to meet actual desensitization requirements.
[0005] In the field of raw image processing such as content review and intelligent editing, the accurate detection and seamless restoration of subtitles also face similar challenges. Although current deep learning detection methods have made progress in general text detection, they still lack targeted mechanism support for the detection of sensitive subtitles that are unevenly distributed and have large scale variations in images. In terms of image restoration, although generative adversarial networks (GANs) can improve the naturalness of the restored area, the restoration effect on areas occluded by small target text is unstable, and they lack the ability to model the semantic relevance of subtitles. In addition, most existing methods fail to effectively integrate semantic information and image texture information, and cannot achieve accurate recognition of sensitive content and context-consistent image reconstruction, which makes it easy to misunderstand content or incomplete desensitization coverage.
[0006] In summary, existing image sensitive subtitle detection and removal technologies still have problems such as low detection accuracy, rough restoration effects, and weak semantic understanding when facing application requirements such as complex backgrounds, small-size text, and multi-scene adaptation. It is still necessary to propose a sensitive subtitle desensitization solution that can integrate image features, attention mechanisms, and semantic information to better meet the actual needs of industries such as finance and healthcare in image privacy protection and information security. Summary of the Invention
[0007] The main purpose of the present invention is to provide a method, device, equipment and storage medium for desensitizing sensitive text in images, aiming to solve the technical problems of the existing technology in processing sensitive subtitles embedded in images, such as inaccurate detection of sensitive text and unnatural image restoration after desensitization.
[0008] To achieve the above object, the present invention provides a method for desensitizing image-sensitive text, comprising:
[0009] Extract multiple feature maps from the image to be processed through the residual convolutional network;
[0010] Inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0011] Integrating the spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0012] Based on the optimized attention feature map, generating candidate region coordinates through a region proposal network;
[0013] Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region;
[0014] Segmenting the local image into pixel blocks, and inputting the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract text sequences;
[0015] Inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0016] According to the sensitive word detection result, local texture restoration is performed on the sensitive area of the image to be processed to generate a desensitized image.
[0017] Furthermore, to achieve the above-mentioned purpose, the present invention provides an image-sensitive text desensitization device, comprising:
[0018] A residual feature extraction module is used to extract multiple feature maps from the image to be processed through a residual convolutional network;
[0019] A multi-scale fusion module is used to input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0020] A spatial attention enhancement module is used to integrate the spatial attention mechanism into the feature maps of each level of the pyramid feature, generate a spatial weight map corresponding to the feature map of each level, and perform element-by-element multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0021] A candidate region generation module, configured to generate candidate region coordinates through a region candidate network based on the optimized attention feature map;
[0022] A coordinate mapping and cropping module, configured to map the coordinates of the candidate region to the image to be processed and determine a local image of the corresponding region;
[0023] A self-attention text extraction module is used to divide the local image into pixel blocks, and input the pixel blocks into a codec based on the self-attention mechanism after linear projection and position encoding to extract text sequences;
[0024] A sensitive word recognition module is used to input the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0025] The local image restoration module is used to perform local texture restoration on the sensitive area of the image to be processed according to the sensitive word detection result to generate a desensitized image.
[0026] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer device, which includes a memory, a processor, and an image-sensitive text desensitization program stored in the memory and runnable on the processor. When the image-sensitive text desensitization program is executed by the processor, the steps of the image-sensitive text desensitization method described above are implemented.
[0027] Furthermore, to achieve the above-mentioned purpose, the present invention also provides a computer-readable storage medium, on which a program for desensitizing image-sensitive text is stored. When the program for desensitizing image-sensitive text is executed by a processor, the steps of the method for desensitizing image-sensitive text are implemented.
[0028] Beneficial effects: The present invention relates to the field of image processing technology and can be applied to business scenarios such as medical health and financial technology. A method for desensitizing sensitive text in images is disclosed, comprising: extracting multiple feature maps from an image to be processed, inputting the multiple feature maps into a feature pyramid network to generate multi-level semantically fused pyramid features, fusing a spatial attention mechanism to enhance the response of sensitive areas in feature maps at each level, generating candidate area coordinates through a region candidate network, mapping the candidate area coordinates to the image to be processed to obtain a local image, extracting text semantic information from the local image using a codec based on a self-attention mechanism, performing sensitive word detection in combination with a semantic classification model, and performing a local texture repair operation on the sensitive area based on the detection results to generate a desensitized image. The present invention improves the detection capability of small-sized sensitive text in images by introducing a spatial attention mechanism and a semantic understanding module based on multi-scale feature fusion, and realizes accurate identification and natural desensitization of sensitive areas through candidate area positioning and a semantically driven repair strategy, thereby enhancing the security and availability of image content. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0030] Figure 1 A schematic diagram of an application environment of a method for desensitizing image-sensitive text in one embodiment of the present invention;
[0031] Figure 2 This is a flow chart of an embodiment of a method for desensitizing image-sensitive text according to the present invention;
[0032] Figure 3 This is a functional module diagram of a preferred embodiment of the image-sensitive text desensitization device of the present invention;
[0033] Figure 4 A schematic diagram of the structure of a computer device according to an embodiment of the present invention;
[0034] Figure 5FIG. 2 is another structural diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0035] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0036] The method for desensitizing image-sensitive text provided by the embodiment of the present invention can be applied in the following situations: Figure 1 In an application environment, the user terminal communicates with the server terminal through a network. The server terminal can extract multiple feature maps from the image to be processed through the user terminal, input the multiple feature maps into the feature pyramid network to generate multi-level semantic fusion pyramid features, integrate the spatial attention mechanism to enhance the response of sensitive areas in the feature maps of each level, generate candidate region coordinates through the region candidate network, map the candidate region coordinates to the image to be processed to obtain a local image, use a codec based on the self-attention mechanism to extract text semantic information in the local image, combine with the semantic classification model to detect sensitive words, and perform a local texture restoration operation on the sensitive area based on the detection results to generate a desensitized image. The present invention improves the detection capability of small-sized sensitive text in the image by introducing a spatial attention mechanism and a semantic understanding module based on multi-scale feature fusion, and realizes accurate identification and natural desensitization of sensitive areas through candidate region positioning and semantic-driven restoration strategies, thereby enhancing the security and usability of image content. The user terminal can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The server terminal can be implemented as an independent server or a server cluster consisting of multiple servers. The present invention is described in detail below through specific embodiments.
[0037] See also Figure 2 , Figure 2 This is a flow chart of an embodiment of the method for desensitizing sensitive text in an image provided by the present invention. It should be noted that although a logical order is shown in the flow chart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0038] like Figure 2 As shown, the image sensitive text desensitization method proposed by the present invention includes the following steps:
[0039] S10, extracting multiple feature maps from the image to be processed through a residual convolutional network;
[0040] In this embodiment, during the desensitization of sensitive information, image preprocessing is a prerequisite for the entire process. Its purpose is to perform preliminary structuring and standardization on the input image, and to provide more discriminative and stable input data for subsequent feature extraction and recognition tasks. Input images usually come from diverse sources and have varying quality. They may have problems such as noise interference, complex colors, low contrast, or blurred fonts. If directly used in subsequent deep learning models, it is easy to cause unstable feature expression, decreased detection accuracy, and even misjudgment and missed detection. Therefore, it is necessary to perform preprocessing operations on the input image to generate an image to be processed with a clearer semantic structure and clearer visual boundaries.
[0041] During preprocessing, the input image is first grayscale converted, transforming the original multi-channel color image into a single-channel grayscale image. This conversion removes color interference and retains only brightness information, simplifying the image content and reducing model computational complexity. Grayscale images can be obtained using weighted averaging, maximum value selection, or brightness distribution-based methods, with different strategies suitable for different application scenarios.
[0042] The grayscale image is then binarized to further enhance the contrast between the target area and the background, making it easier to distinguish subtitles, characters, or other edge structures. Binarization can be achieved using a fixed threshold, a global adaptive algorithm (such as Otsu), or a local adaptive method (such as local window averaging). This process effectively highlights structured areas and suppresses background complexity, making it a key step in extracting text objects.
[0043] To remove low-level noise interference such as isolated points, edge burrs, and scanning artifacts that may exist in the image, a noise removal operation is introduced after binarization. This operation is usually performed based on median filtering, morphological processing (such as erosion and dilation), and small connected domain elimination. The purpose is to optimize the continuity of the image structure and enhance the clarity of regional boundaries.
[0044] Finally, to further improve the structural distinction and detail perceptibility of the image, contrast enhancement is performed. This step can be accomplished using methods such as histogram equalization, gamma correction, or contrast stretching, which are used to expand the dynamic range of image brightness values and enhance the grayscale gradient difference between edges and fonts, thereby improving the recognition of character boundaries and model extraction capabilities. After the above-mentioned grayscale conversion, binarization, noise removal, and contrast enhancement processing, an optimized image to be processed can be obtained. This image has better structural clarity and texture stability, and serves as the input of the subsequent residual network, helping to improve the accuracy and robustness of sensitive area detection.
[0045] The essential goal of image caption desensitization is to achieve high-precision detection and natural, seamless reconstruction of sensitive information areas in an image. Therefore, in the initial processing stage, it is necessary to extract as comprehensive and discriminative deep semantic features from the image to be processed as possible. To achieve this goal, a residual convolutional network is used as the backbone structure for feature extraction. Through multi-level feature mapping, a multi-scale information representation of the image is obtained, laying the foundation for subsequent semantic understanding, region localization, and image restoration. The residual convolutional network is an architecture that explicitly constructs the information transmission path in a deep convolutional neural network. In this structure, each basic unit not only includes multiple convolutional layers, normalization layers, and activation function layers, but also has a skip connection structure that directly adds the input to the features after subsequent convolution processing. This effectively avoids the gradient vanishing and degradation problems in deep network training, preserves the original information flow, and facilitates the fusion of shallow and deep features.
[0046] At different stages of the residual network, convolution operations with a stride greater than 1 are introduced as a downsampling method to obtain feature maps with reduced resolution but enhanced semantics. This operation replaces the traditional pooling structure and has the advantage of learnable parameters. It compresses the spatial size while maintaining semantic integrity, which is conducive to constructing the multi-level feature maps required by the feature pyramid network. These feature maps contain information such as local edges, structural patterns, texture combinations, and global semantics, and provide the necessary input basis for subsequent spatial attention mechanisms, region candidate box generation, and sensitive information identification. By stacking multiple residual block structures layer by layer, the network can not only capture multi-scale semantics, but also explicitly encode contextual dependencies in the deep representation, so that even subtitles located in complex backgrounds can be effectively distinguished and subsequently desensitized.
[0047] In order to adapt to different image complexities and target subtitle sizes, the depth and width of the residual network can be dynamically adjusted. For example, when faced with high-resolution images or small font subtitles, you can choose to deepen the number of network layers and increase the number of convolution channels per layer to enhance the model's responsiveness to weak features. When processing low-contrast or blurred images, you can give priority to a shallower network structure and introduce a larger receptive field in the convolution kernel design (such as using large 3×3 or 5×5 convolution kernels) to obtain stronger global perception capabilities. In addition, in specific scenarios, the standard residual network can be replaced with a residual variant network with a cross-layer attention mechanism, such as introducing an SE module or a CBAM attention module, to further improve feature expression capabilities at the channel and spatial levels.
[0048] Example: In the healthcare field, a four-stage residual convolutional network (RCN) is used for panoramic images of pathology slides (resolution approximately 200,000 × 100,000 pixels), with each stage consisting of four residual blocks. The first-stage residual block uses a large 7×7 convolution kernel with a stride of 4 to quickly compress the image size to 1 / 16th, increasing the number of channels to 64. Subsequent stages gradually increase the number of channels to 512, while simultaneously reducing the resolution to 1 / 256th of the original size through convolutions with a stride of 2. The channel attention module is enabled in the third and fourth stages to enhance the characteristic response of cell nucleus edges and vascular structures. This design enables the network to process megapixel images on a GPU with 10GB of video memory, accurately extracting tumor region features, and supporting subsequent automatic labeling and quantitative analysis.
[0049] In the financial sector, a three-stage residual convolutional network is used to process scanned loan contract images (typically at 300dpi resolution). The input image undergoes a 3×3 convolution (stride 1) in the first stage to extract the underlying texture, maintaining the number of channels at 32 to reduce computational complexity. In the second stage, the residual block introduces a 3×3 convolution with a dilation rate of 2 to expand the receptive field to cover the entire line of text. In the third stage, 1×1 convolutions compress the number of channels to 16, generating a lightweight feature map. The channel attention module is only enabled in the second stage, focusing on channel enhancement of the signature area and the amount digits. This configuration enables real-time processing on embedded devices (such as smart banking terminals), extracting features from a single frame in less than 50ms and accurately isolating sensitive information areas for desensitization.
[0050] In satellite remote sensing monitoring scenarios, for land cover classification, a residual convolutional network (RCN) employs a five-stage architecture. The first two stages use standard convolution to capture road and building outlines, while the final three stages incorporate hybrid dilated convolutions (alternating dilation rates of 2 and 4) to effectively identify river flows and forest boundaries. In the fourth stage, a channel attention module enhances channels related to vegetation indices and suppresses noise in cloud-obscured areas. This network achieves a 12% improvement in feature extraction accuracy compared to traditional U-Nets for 4K resolution satellite imagery, while also increasing inference speed by three times, meeting the timeliness requirements of dynamic land and resources monitoring.
[0051] By adopting the residual convolutional network as the initial feature extraction structure, it can fully integrate shallow texture and edge information with deep semantic and structural information, and alleviate the problem of information flow loss through jump connections, so that the feature map extracted from the image has a good gradient propagation path while maintaining high expressiveness, providing rich underlying information expression for subsequent multi-scale fusion and semantic recognition, and effectively improving the detection accuracy and positioning stability of sensitive subtitle areas.
[0052] S20, inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0053] In this embodiment, multiple feature maps are input into the feature pyramid network for multi-scale fusion. The core is to build a cross-level semantic information transmission path to overcome the limitations of single-scale feature maps in spatial resolution or semantic abstraction. Figure 1 These features are generally derived from the feature representations output by the previous residual convolutional network at different stages. For example, when using ResNet as the base network, the feature maps may correspond to layers of different depths, such as C2, C3, C4, and C5. The feature maps at each layer have different spatial dimensions and semantic expression capabilities. High-resolution layers typically focus more on detailed information such as edges, textures, and local contours, while low-resolution layers are more focused on object-level semantic understanding.
[0054] To achieve multi-scale semantic fusion, the input feature maps must first be ordered according to their hierarchical level and each feature map must be normalized to avoid information mismatches due to differences in channel count during the fusion process. Channel alignment is typically achieved through convolution operations with a uniform number of output channels. Common configurations include 1×1 convolution kernels to compress or expand the number of channels, batch normalization to improve training stability, and nonlinear activations to enhance model expressiveness. A top-down feature path is then constructed, starting with the lowest-resolution (most semantically significant) feature map. This map does not need to be fused with other layers and can be directly used as one of the pyramid outputs.
[0055] When generating pyramid features for the next level, the processed pyramid features of the previous level are spatially upsampled to maintain the same resolution as the horizontally connected feature maps of the current level. This upsampling process can be implemented in a variety of ways, including the most common bilinear interpolation method, deconvolution (with learnable parameters), or sub-pixel reconstruction. The choice is determined based on the trade-off between real-time performance and accuracy. The upsampled feature maps are then element-wise added and fused with the horizontally connected feature maps of the current level to form a multi-level information reconstruction feature. The fused result is then passed through a standard convolution module to further extract features, improving its discriminative and representational capabilities while also smoothing the fusion boundaries and removing noise from multiple sources.
[0056] This process is repeated from top to bottom until all levels are fused, forming a multi-level pyramid feature with unified semantic abstraction capabilities while retaining different spatial perception capabilities. Multi-level pyramid features not only provide a multi-granular input foundation for subsequent attention weight generation and candidate region positioning, but also establish a stable collaborative path between spatial and semantic information, improving the recognition accuracy and robustness of multi-scale sensitive elements (such as subtitles of different font sizes). It should be noted that multi-level semantic fusion is not a simple feature stacking or splicing, but a layer-by-layer information integration process with information guidance and alignment structure, which has higher model interpretability and generalization capabilities.
[0057] In actual deployment, it also supports integration with lightweight structures. For example, the pyramid module can be designed as a scalable structure to adapt to the resource constraints of edge devices, or a dynamic channel adjustment mechanism can be introduced to reduce redundant feature transmission. In addition, to enhance the quality of cross-level information fusion, guided attention mechanisms, residual connections, or feature reweighting modules can be introduced in the upsampling path to further improve the responsiveness to key areas in complex image structures. The construction of the entire pyramid structure has both clear hierarchical logic and flexible technical scalability, making it suitable for visual task scenarios that require multi-scale information integration.
[0058] By inputting feature maps of multiple scales into the feature pyramid network for multi-scale fusion, not only the edge and local detail information in the low-level feature maps is retained, but also the global semantic expression of the high-level feature maps is integrated, effectively solving the detection difficulties caused by the uncertainty of size, position, and structure of sensitive subtitles in the image, and improving the model's comprehensive perception ability and stability of sensitive areas of different scales.
[0059] S30, integrating a spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0060] In this embodiment, the spatial attention mechanism is introduced into the feature maps of each level of the pyramid feature. This aims to improve the expressiveness of spatial position information in the feature map, allowing the model to focus more on areas that are discriminative to the task target, thereby effectively suppressing the interference of redundant background information on target recognition. The spatial attention mechanism is a feature enhancement method centered on two-dimensional spatial relationships. Its processing focuses on learning and generating a weight map that is consistent with the spatial distribution of the feature map. This weight map characterizes the importance of each spatial position.
[0061] In actual operation, the feature map of each pyramid level is used as an independent input, and the fusion processing of the attention mechanism is performed separately to ensure that the spatial semantic enhancement does not introduce mutual interference between levels. First, in order to construct the spatial attention response map, global average pooling and global maximum pooling operations are performed on each feature map in the channel dimension. Average pooling is used to model the global background response of the spatial region, while maximum pooling highlights the salient target response of the region. This combination method is derived from the spatial modeling method in the general attention network and can fully retain different types of spatial information. After the pooling operation is completed, two compressed feature maps with the same spatial size as the original feature map but with 1 channel are obtained.
[0062] The two compressed feature maps are then concatenated along the channel dimension to generate a two-dimensional intermediate feature map with two channels. This concatenation operation forms the input basis for spatial attention modeling. To extract discriminative spatial dependencies from the concatenated result, the intermediate feature map is fed into a standard convolutional module. This module typically uses a convolution kernel with a large receptive field (e.g., 7×7) to enhance context modeling. A nonlinear activation function is then applied after the convolution to improve expressiveness. The convolution output is a single-channel spatial response map that represents the importance distribution of each spatial location.
[0063] To normalize the spatial response map, a Sigmoid activation function is typically introduced to map its numerical range to between 0 and 1, ensuring that the weight map can be interpreted as a significance coefficient for each position. Finally, this normalized spatial weight map is element-wise multiplied with the original pyramid feature map at the corresponding level to enhance key regions and suppress non-key regions within the feature map. Because the attention response map has a single-channel structure, element-wise multiplication is typically automatically expanded to the same number of channels as the original feature map through a broadcast mechanism, ensuring dimensional consistency in the fusion calculation.
[0064] This attention enhancement method is pluggable and structurally flexible. It can be used as a module-level enhancement in the standard FPN pyramid structure, or it can be combined with the channel attention mechanism to form a more complete dual-branch attention path. Its advantage is that it can fully activate spatial regions with semantic relevance in the image, and has better response characteristics for images with uncertain target area size or blurred boundaries. It is especially suitable for processing fine-grained spatial regions such as image subtitles and local sensitive text. In addition, the optimized features generated by the feature maps of different levels after independent attention modeling can form spatial perception consistency at multiple scales when subsequently used for tasks such as candidate area positioning and semantic judgment, thereby enhancing the ability to separate sensitive information in complex backgrounds.
[0065] The construction and fusion process of the spatial attention mechanism can be implemented using a variety of different technical means. In the specific implementation process, a standard attention module structure can be used. First, the channel dimension is compressed by global average pooling and global maximum pooling respectively, retaining the average response and maximum response of each spatial position on the channel. Then, the two feature maps are spliced along the channel dimension to form a dual-channel compressed representation. The spliced intermediate feature map can be input into a single-layer convolutional network. The convolution kernel size can be set to 3×3, 5×5 or 7×7 to cover different ranges of receptive fields. If it is necessary to deploy on edge devices or resource-constrained environments, a 3×3 lightweight convolution structure can be selected and combined with ReLU activation or Swish activation to improve the nonlinear expression capability of features.
[0066] The convolution output generates a single-channel spatial weight map. To ensure its numerical controllability and conformance to the normalization requirements of the attention mechanism, this map is mapped to a value between 0 and 1 using a sigmoid function. To align with the original pyramid feature map, this spatial weight map is typically expanded through a broadcast mechanism to have the same number of channels as the input feature map. Element-wise multiplication is then performed to achieve weighted enhancement of the spatial dimensions of the feature map. In a multi-layer pyramid structure, each level can independently perform this spatial attention fusion process, ensuring effective spatial attention at different resolutions.
[0067] Alternatively, the spatial module in a lightweight attention model, such as the Convolutional Block Attention Module (CBAM), can be used to replace the aforementioned structure, further reducing the number of parameters. Position encoding can also be introduced into the spatial weight map to provide relative or absolute spatial position information, improving the ability to locate sensitive areas. In special scenarios, such as when the input image contains specific occlusions or edge interference, a pre-built structural mask can be used as an attention constraint and integrated with the spatial weight map to guide the model to focus more on the core areas.
[0068] Example: In the healthcare field, electronic medical records, medical images, or medical records often contain private patient information such as names, ID numbers, and diagnoses. This information often appears in small font in the corners or edges of the image. By integrating the spatial attention mechanism into the pyramid feature map, we can precisely focus on these spatial regions and suppress irrelevant background in the image, such as medical equipment, rulers, or image watermarks. This allows for more accurate identification and extraction of areas containing sensitive information, laying the foundation for subsequent removal and restoration.
[0069] In the field of financial technology, bank card photos, invoice images, contract scans, and more often contain small embedded areas of account information, transaction details, or customer identification codes. These areas are located in irregular locations and have different fonts. Introducing a spatial attention mechanism into pyramid feature maps improves the model's responsiveness to these critical areas, maintaining high localization accuracy even in image corners or at low-resolution levels, effectively supporting the intelligent identification and removal of private financial information.
[0070] In the context of image content regulation on social platforms, user-uploaded screenshots, photos, and composite images may contain abusive and sensitive content in captions. The introduction of the spatial attention mechanism can enhance the recognition of densely packed text areas. Combined with context-aware features, it further strengthens the model's ability to identify sensitive areas, improving the accuracy and practicality of the illegal content detection system.
[0071] By introducing a spatial attention mechanism into the feature maps at each level of the pyramid feature, the model's ability to perceive the target area can be significantly improved. This mechanism extracts spatial responses by compressing channel information, generates an attention map that can reflect the distribution of spatial saliency, and uses this map to weight the original features element by element, achieving explicit feature enhancement and suppression of redundant areas. In this way, the feature map of each pyramid level further enhances the response strength to key areas while retaining the original semantic hierarchy, thereby improving the extraction quality of candidate areas and providing a more accurate spatial foundation for subsequent tasks such as sensitive word detection and image restoration. Ultimately, the accuracy and robustness of small target subtitle detection are improved, especially in scenes with complex backgrounds or weak boundary text.
[0072] S40, generating candidate region coordinates through a region candidate network based on the optimized attention feature map;
[0073] In this embodiment, the optimized attention feature map is a feature map obtained by introducing a spatial attention mechanism into a multi-scale pyramid feature map. It not only retains the semantic hierarchical information at different resolutions, but also enhances the responsiveness to the target area. Based on this type of feature map, target candidate regions can be generated more accurately. The region candidate network is a mechanism developed from target detection and is often used to quickly generate candidate boxes with high confidence on feature maps. It predicts the area where the target may exist for each spatial position of the feature map and estimates the position offset and target score of each candidate region.
[0074] In this process, multiple predefined anchor boxes are first generated for each spatial location in the optimized attention feature map. An anchor box refers to a rectangular box with multiple preset aspect ratios and scales set at each pixel position in the feature map. Common scales include 32, 64, 128, and 256 pixels, and aspect ratios can be set to 1:1, 1:2, 2:1, and other combinations. The purpose of setting multiple anchor boxes is to cover target areas of different shapes, sizes, and aspect ratios, thereby increasing the probability of matching sensitive subtitle areas. The generation of anchor boxes does not rely on a specific image, but rather acts structurally on the feature map itself.
[0075] The optimized attention feature map is then convolved to form a sliding window prediction module. Each sliding window extracts local features of the current anchor frame region and predicts two pieces of information: a classification score for each anchor frame, used to determine whether the region contains potentially sensitive subtitle information; and a regression offset, including fine-tuning parameters for the center point position and width and height. These offset parameters are used to fine-tune the anchor frame to more accurately fit the actual subtitle boundaries.
[0076] After obtaining the predicted offsets and confidence scores for the anchor boxes, all anchor boxes need to be screened for candidate selection. They are sorted by confidence score, and the top few high-scoring anchor boxes (e.g., the top 300) are selected. These are then filtered using non-maximum suppression to remove redundant candidate boxes with excessive overlap. Non-maximum suppression is based on the intersection-over-union (IoU) calculation. When the IoU of two candidate boxes exceeds a set threshold (e.g., 0.7), only the one with the higher score is retained, ensuring a balanced distribution of candidate regions and clear boundaries.
[0077] The final output set of candidate region coordinates includes the center point position, width, and height parameters of each region. These coordinate values are calculated in the feature map coordinate space and can be subsequently aligned with the original image space through mapping operations, serving as the basis for further sensitive area positioning, text analysis, and repair.
[0078] In actual deployment, region proposal networks can be implemented based on a variety of deep learning architectures. For example, the classic Region Proposal Network (RPN) can be used as the core component. Its structure consists of three parts: a shared feature extraction layer, a small convolution prediction layer, and a classification and regression branch. The shared layer uses a 3×3 convolution to extract local contextual information. Subsequently, two parallel 1×1 convolutional layers output the classification score and bounding box regression offset for each anchor box.
[0079] In lightweight deployment scenarios, MobileNet or ShuffleNet can be used as the basic backbone network, combined with a lightweight RPN module to reduce the number of parameters and computational complexity. In multi-task joint detection tasks, RPN and the backbone network can also be feature-fused, and upper-layer semantics can be introduced in advance to assist in candidate region generation.
[0080] In addition, the anchor-free idea can be introduced, abandoning the anchor frame preset and instead directly regressing the key point coordinates and area boundaries in the feature map, thereby improving the positioning ability in sensitive subtitle areas such as complex deformations and oblique text.
[0081] Parameters such as the intersection-over-union (IoU) threshold, the number of candidate boxes to be screened, and the anchor box size ratio can be flexibly adjusted based on the needs of different scenarios. For example, in high-resolution image processing scenarios, the density of anchor box scales can be increased to improve coverage; in small-sized input images, the number of candidate regions can be reduced to avoid false positives.
[0082] By building a region candidate network based on the optimized attention feature map, the perception of subtitle regions is enhanced based on multi-scale semantic features, while the accuracy of region positioning is strengthened by the spatial attention mechanism. The region candidate network built on this basis can quickly screen candidate regions with high confidence, and further improve the accuracy and independence of candidate boxes through bounding box regression and non-maximum suppression mechanisms, significantly increasing the detection success rate of subtitle-sensitive regions. With higher positioning efficiency and scalability, it can achieve high-quality candidate region extraction in complex scenes, low-contrast backgrounds, or small text areas, providing a structured, high-precision input foundation for subsequent semantic detection and image restoration.
[0083] S50, mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region;
[0084] In this embodiment, the candidate region coordinates generated by the region candidate network are based on the feature map coordinate system, which represents the spatial position and size of the potential sensitive area identified on the optimized attention feature map. However, there is a difference in the downsampling ratio between the feature map and the original input image. Therefore, if the corresponding area needs to be accurately extracted in the original image, the feature map coordinates must be mapped back to the original image coordinate system. This process is called candidate region coordinate mapping, and its purpose is to restore the absolute position and size of the region in the original image space, so that subsequent image analysis or restoration tasks have an accurate positioning basis.
[0085] In specific implementations, feature maps are usually scaled down compared to the original image due to operations such as convolution and pooling. The scale of this reduction is determined by the downsampling step size in the feature pyramid network. For example, if the step size is 16, then a pixel on the feature map corresponds to a 16×16 area in the original image. When performing coordinate mapping, the horizontal coordinate of the center point of the candidate box can be compensated by multiplying its horizontal coordinate in the feature map by the downsampling step size and adding half of the step size. The vertical coordinate mapping method is the same. The mapping of width and height is relatively simple. Simply multiplying the width and height of the candidate area by the downsampling step size can restore it to the original image scale.
[0086] After completing the basic mapping, boundary constraints must be applied. Since some candidate boxes may be located at the edge of the feature map, their mapped center coordinates or dimensions may extend beyond the original image boundaries. Therefore, the horizontal and vertical coordinates of the center point must be no less than zero and must not exceed the image width and height. Furthermore, the upper, lower, left, and right boundary coordinates must be calculated based on the center point and dimensions of the candidate box. The actual width and height must then be adjusted to the difference between the right boundary and the left boundary, and the bottom boundary and the top boundary, to ensure the cropped area is complete and usable.
[0087] Finally, based on the mapped center coordinates and the adjusted width and height information, a rectangular area can be directly cropped from the original image to be processed to obtain the corresponding local image. This area corresponds one-to-one with the candidate area in space and is semantically a suspected sensitive area to be analyzed.
[0088] In practical implementation, the downsampling factor between the output feature maps of each layer of the feature pyramid network and the input image can be recorded, and the coordinates of the anchor boxes output by the region proposal network can be inversely scaled based on this factor. In a multi-scale pyramid structure, the step size of each feature map layer varies, so the corresponding mapping coefficient must be dynamically selected based on the layer from which the candidate region originates. During the mapping process, the coordinate cropping functions provided by image processing libraries (such as OpenCV or PIL) can be used to convert the mapped coordinates into the image cropping region. Interpolation algorithms such as bilinear interpolation or region copying can be used during cropping to ensure pixel continuity along the cropping boundary. Regarding boundary control strategies, the upper bound of the boundary can be dynamically set based on the original image size, and symmetrical padding or edge cropping can be performed when the candidate region exceeds the boundary. For example, if the horizontal coordinate is widened beyond the image width, the right bound can be set to the maximum image width while reducing the width to maintain the center unchanged. If the center point is too close to the image edge, the cropping region can be translated or scaled to ensure a complete and usable image tile. In addition, the candidate region mapping information can be saved in a structured data structure, such as a JSON object or a tensor dictionary, to support subsequent batch processing, visualization echo, or joint training process.
[0089] By mapping the coordinates of candidate regions from feature map space to the original image space, the problem of inconsistent coordinate systems in object detection tasks is resolved, enabling the model to accurately extract suspected sensitive areas in the image. This operation ensures that subsequent image analysis, text recognition, or texture restoration operations are performed based on the correct and precise image location, avoiding desensitization failures, miscropping, or semantic deviations caused by coordinate errors. The mapping mechanism achieves coordinate transformation and boundary alignment, ensuring consistency in spatial semantics throughout the desensitization process and enhancing the overall stability and accuracy of the system.
[0090] S60, dividing the local image into pixel blocks, and inputting the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract a text sequence;
[0091] In this embodiment, the local image is usually a sub-region cropped from the original image, which has an irregular size and complex texture structure and may contain fine-grained sensitive subtitle information. In order to achieve an in-depth understanding and accurate extraction of the potential text information in the area, the image area must first be converted from a two-dimensional pixel representation to a serialized representation that adapts to the language modeling structure. The first step in the process is to segment the image into pixel blocks, that is, to divide the entire local image into several small rectangular areas, usually called patches. In the standard visual Transformer architecture, these patches are fixed in size, such as 16×16 or 32×32, and are extracted in a non-overlapping sliding window manner on the entire image to form a set of tiled image units.
[0092] Each image patch is then treated as an input token and further mapped to a unified embedding space via linear projection. This linear projection is typically performed via a fully connected layer, converting the high-dimensional representation of the original pixel patch (e.g., a flattened vector of the concatenated RGB channels) into a low-dimensional embedding vector, preserving local texture information while compressing the dimensions. Furthermore, positional encoding is required to preserve the spatial order between patches in the image. This positional encoding can employ either a fixed trigonometric encoding or a trainable vector encoding, providing each patch with positional awareness within the image.
[0093] After linear projection and positional encoding, the sequence of all patch embedding vectors is fed into an encoder-decoder architecture based on a self-attention mechanism. The encoder uses multi-head self-attention layers to model global dependencies between patches, enhancing the model's contextual awareness. The decoder further converts the encoded results into a parsable sequence of text symbols. This architecture overcomes the limitations of the local receptive field of traditional CNNs, enabling the model to globally identify and interpret sensitive textual information implicit in local images, providing a foundation for subsequent semantic detection.
[0094] In a specific implementation, the local image is first normalized to a uniform size (e.g., 224×224), then partitioned into non-overlapping 16×16 windows, resulting in 196 pixel blocks. Each pixel block is then channel-wise flattened to form a 768-dimensional vector, which serves as the input to the linear projection layer and outputs a 128-dimensional embedding vector. All embedding vectors form a sequence of length 196 and are summed with the position encoding vector to form the input sequence. Position encoding can be implemented using sine and cosine functions, where each dimension is encoded with a different frequency, ensuring the model can distinguish between relative and absolute positions. A trainable position embedding matrix can also be used to automatically learn the semantic mapping of spatial position information through training. The encoder architecture comprises several layers of Transformer blocks, each of which incorporates a multi-head attention mechanism and a feedforward network. The number of attention heads, embedding dimension, and hidden layer size can be adjusted based on computing power (e.g., 8 heads and 256 hidden layers). The decoder architecture is similar to the encoder, but can also incorporate a masking mechanism to enable the decoding stage to maintain progressive predictive power over the output information sequence, thereby facilitating the localization and type of subtitle text. In addition, to improve recognition efficiency, pre-trained models (such as ViT or Swin Transformer) can be introduced for transfer learning to shorten training time and improve accuracy.
[0095] By converting image regions into sequences of pixel blocks and introducing a modeling approach based on a self-attention mechanism, this approach effectively addresses the limited local recognition capabilities of traditional convolutional models in scenarios with long text, complex backgrounds, or spatial deformation. Through linear projection and positional encoding, the model gains enhanced structural representation and spatial context awareness, enabling it to accurately extract text semantic sequences from unstructured images. This improves the recognition rate and error tolerance for sensitive subtitles, demonstrating greater robustness in scenes with distorted, occluded, or low-contrast characters.
[0096] S70, inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0097] In this embodiment, the text sequence generated by the image encoding module is essentially a semantic representation of the underlying text content within a local image region. This text sequence may contain subtitles, labels, seal information, etc., and has characteristics such as unstable semantic structure and weak contextual association. Therefore, further semantic classification model is required to identify whether it contains sensitive words or confidential content.
[0098] After a text sequence is input into the semantic classification model, it first passes through an embedding layer, mapping discrete text tokens into high-dimensional semantic vectors. The sequence is then fed into a deep Transformer architecture consisting of multiple stacked encoders. The Transformer encoder features a multi-head self-attention mechanism that captures contextual dependencies between text at different locations and constructs a global semantic representation. In this architecture, increasing the number of encoder layers improves the model's ability to model semantic relationships in long texts and understand complex language structures, avoiding sentence misjudgments and polysemy caused by shallow networks.
[0099] Finally, after aggregating the representations of all tokens through the pooling layer or CLS tokenization, the fully connected classification layer outputs a category probability distribution, indicating whether the current text sequence contains sensitive words and the category of sensitive information (such as ID numbers, phone numbers, medical terms, and institution names). To further improve generalization, regularization methods such as dropout or residual connection structures can be used to prevent overfitting during the training phase.
[0100] In addition, the category system of sensitive words can be configured through predefined sensitive word dictionaries, compliance standards or business rules, and different categories can be finely divided at the model output end, thereby supporting more interpretable recognition output.
[0101] In one specific embodiment, a text sequence is first encoded into a token sequence and then fed into a semantic classification module. This module can be built based on pre-trained language models such as BERT, RoBERTa, or DeBERTa, with a 12- or 24-layer encoder structure, depending on the complexity of the task. Increasing the number of encoder layers enables the model to construct semantic information at a deeper level of abstraction, making it particularly suitable for scenarios with interference, occlusion, or multilingual subtitles. For model training, a dual loss structure can be employed to simultaneously optimize the presence and absence of sensitive words and their classification, improving detection accuracy. Training data can be constructed from human-annotated captioned images or synthetic data, covering sensitive words of various types and contexts. During the inference phase, after a text sequence is input into the model, it outputs a vector containing sensitivity probabilities and categories, such as [non-sensitive, medical term, personal identifier, organizational information]. The vector with the highest probability represents the text classification for the current local image. The model output is used to drive the subsequent image inpainting module to perform targeted masking and reconstruction operations. To improve response speed and deployment flexibility, the semantic classification model can be encapsulated as an independent inference service, deployed in the text discrimination module of the image processing system, and linked with the image recognition component through a lightweight API.
[0102] By inputting text sequences converted from image regions into a multi-layer semantic classification model for sensitive word detection, we can accurately identify hidden sensitive words in complex image-text structures. By increasing the number of encoder layers, we strengthen the model's semantic abstraction capabilities, enabling it to capture contextual dependencies and semantic ambiguity in long texts. This significantly improves recognition robustness in noisy environments or polysemous scenarios, addressing the inability of traditional shallow networks to recognize sensitive content in small characters or weak contexts.
[0103] S80: Perform local texture restoration on the sensitive area of the image to be processed according to the sensitive word detection result to generate a desensitized image.
[0104] In this embodiment, the sensitive area in the image to be processed is a high-confidence text area identified by the upstream semantic classification model, which is mapped to a rectangular area in the image space after position decoding for subsequent local replacement. The positioning accuracy of the sensitive area directly affects the quality of subsequent restoration. Therefore, it is first necessary to screen the high-probability area through a threshold mechanism, and combine morphological operations to expand and standardize its spatial boundaries. The generation of the mask can adopt the closing operation in image morphology. Through the sequential operation of first dilation and then corrosion, noise interference is eliminated, broken structures are connected, and regional coherence is enhanced. The mask is used to define the range that needs to be completely replaced in the image. Its boundary not only defines the restoration range, but also determines the semantic boundary of the restoration texture to a certain extent.
[0105] Local texture inpainting is premised on image context consistency. Its goal is to fill in missing image pixels in the masked area while maintaining continuity with the surrounding structure, color, and texture. Feature extraction is required before inpainting. Multi-scale convolution modules are used to extract image information such as local details, regional associations, and global layout within different receptive fields. Convolution kernel sizes such as 3×3, 5×5, and 7×7 correspond to the process from fine-grained texture modeling to large-scale structural understanding, respectively. This structural design facilitates accurate restoration of background content obscured by text areas in image inpainting tasks. By concatenating feature maps of various scales along the channel dimension and performing dimensionality compression via 1×1 convolution, context-aware features integrating different semantic granularities can be constructed.
[0106] The fused features are further fed into the self-attention module, which models non-local dependencies between features on a pixel-by-pixel basis. The attention mechanism is based on a scaled dot-product attention architecture. Its core is to generate a weighted image representation through dot products and normalization between key, value, and query vector matrices. This process dynamically adjusts each pixel's dependence on other regions of the image. Parallel modeling of multiple attention heads enables the model to simultaneously perceive semantic cues at different directions and scales across multiple semantic channels, thereby strengthening semantic consistency and spatial coherence.
[0107] Inpainting networks typically employ an encoder-decoder architecture, where the generator is responsible for generating candidate textures for desensitized areas, and the discriminator is responsible for determining whether the textures are natural and credible. The encoder can optionally employ a residual structure to enhance feature retention, and stacking residual blocks improves the model's ability to abstract spatial structure and contextual information. The decoder restores the original image resolution through transposed convolutions and introduces skip connections from the encoder at each upsampling stage to ensure spatial alignment while guiding texture reconstruction. An attention module can be embedded within the skip connection path to further improve the synthesis quality of key areas. The discriminator employs a multi-scale patch discrimination approach to evaluate the authenticity of generated content from different scales of the image, ensuring that the synthesized textures conform to the distribution of the real image both locally and globally.
[0108] The final generated image is fused with the original image using a Poisson fusion mechanism. Its core concept is to use the image gradient field as a constraint to find the optimal intensity value for each pixel within the generated region, thereby achieving a smooth transition within the transition zone. The fusion process is centered on the mask boundary, establishing gradient continuity equations at the inner and outer edges. A sparse linear solver is then used to optimize each pixel value, ensuring that the inpainted texture seamlessly embeds into the original image while avoiding edge abruptness.
[0109] While maintaining the underlying architecture, local texture restoration can be implemented differently based on different generation strategies and fusion methods. In terms of feature extraction, multi-scale convolutions can be replaced with pyramid convolutions or dilated convolutions to adapt to the contextual awareness requirements of input images of varying resolutions. In terms of attention mechanisms, standard multi-head self-attention can be replaced with sparse attention or local window attention mechanisms to reduce computational complexity and enhance local information modeling capabilities. The generator architecture can adopt a Transformer structure instead of a convolutional U-Net, particularly for high-resolution sensitive area restoration tasks, offering superior long-range dependency modeling capabilities. Regarding the discriminator architecture, in addition to the multi-scale patch discriminator, a frequency-domain discriminator or a discriminator based on a graphical model can be introduced to enhance the ability to recognize periodic structures or complex patterns in the generated textures. During Poisson fusion, different gradient solving strategies, such as the fast Poisson solver and the weighted Laplacian balancer, can be employed to achieve a trade-off between fusion efficiency and boundary quality. In certain specific scenarios, such as applications in medical imaging that are highly sensitive to edge structures, a guided graph fusion mechanism can also be used to use known edge structures in the image as gradient direction references to ensure boundary continuity.
[0110] Example illustration: In the scenario of medical and health data management, when a hospital archives patients' examination images (such as MRI or CT images), to protect patients' privacy, it is necessary to remove the text information embedded in the images, such as names, ID numbers or examination numbers. These information are usually displayed in the form of subtitles in the edge area of the image, with small fonts, low contrast and complex backgrounds. Traditional rule-based image blurring methods cannot accurately locate and naturally replace them. The system first receives the original image, such as a chest CT image, and extracts image features at multiple scales through a residual convolutional network. These feature maps can respectively represent edge textures, organ boundaries and overall structures. Subsequently, these feature maps are input into a feature pyramid network to fuse context semantics at different scales and generate multi-level pyramid features. The pyramid features further introduce a spatial attention mechanism to enhance the contrast sensitivity between the local and the global, making the text area show a stronger response on the feature map. Based on the optimized attention feature map, the region candidate network generates candidate regions of different scales and ratios at each spatial position and predicts their sensitivity scores. The system retains the high-score regions, and after non-maximum suppression, a set of candidate regions is obtained. The system maps these candidate boxes to the coordinates of the original CT image through the downsampling step of the pyramid network, and crops out the local image area through boundary correction and size constraints. The system divides each local image into pixel blocks, and after linear projection and position encoding, sends them into a self-attention encoder-decoder to extract sequence features, and then inputs them into a semantic classification model for sensitive word detection. For example, texts such as "Li Moumou" and "421************" are detected, and if their position confidence exceeds the threshold, they are marked as sensitive targets. Subsequently, according to these detection results, the system performs local texture repair operations on the corresponding regions. First, a sensitive region mask is generated, and the surrounding boundaries of the sensitive text are extended using morphological operations, and then the target region is cropped out. This region undergoes multi-scale convolution and self-attention processing to generate context-aware features, and is sent into a repair network composed of stacked residual convolution and dilated convolution to generate a new image region without sensitive words. Finally, the system uses Poisson fusion to naturally fit the repaired region back to the original image to generate a desensitized image, ensuring texture continuity, smooth edges and no obvious repair traces.
[0111] In financial operations, when enterprises process imaging materials such as loan contracts, insurance policy scans, bank statements, customer risk assessment documents, etc., they often contain a large amount of sensitive information, such as customer names, ID numbers, account information, credit ratings, fund flows, etc. These information are often embedded in the image in the form of text or small tables. To achieve automated desensitization, before the information is uploaded to the cloud or disclosed externally, a set of image sensitive subtitle removal mechanisms with high accuracy, strong controllability and good visual consistency needs to be constructed.
[0112] The system first receives a scanned image of a financial contract, which may contain complex background features such as anti-counterfeiting textures, watermarks, and red official seals. Traditional OCR or image filtering methods are unlikely to guarantee accurate desensitization and visual fidelity. The system preprocesses the image, performing grayscale conversion, binarization, noise removal, and contrast enhancement. This generates a sharper image to be processed, suppressing background interference and enhancing text edge features. This image is then fed into a residual convolutional network to extract multi-scale feature maps. The network's initial convolutional layers extract basic edge features, while stacked residual blocks extract complex structures. Skip connections preserve details, and a channel attention module adjusts the weights of each channel to enhance sensitivity to objects such as numbers and text lines. For example, for a region containing the bank account number "6222**********," the system can amplify the response intensity of narrow handwriting channels.
[0113] The extracted multi-scale feature maps are then fed into a feature pyramid network for fusion. High-level feature maps focus on the global outlines of the official seal and signature area, while low-level feature maps focus on the edge segments of the ID card number and the bank account. Through operations such as channel unification, lateral connections, and top-down upsampling and fusion, a pyramid feature with multi-scale semantic expression is formed. The system then applies a spatial attention mechanism to each pyramid level, constructing an attention response map through global average pooling and maximum pooling. This is then element-wise multiplied with the original feature map to further enhance the response to sensitive text areas (such as fields like "ID card" and "Customer number") while suppressing background texture and watermarks.
[0114] On the optimized attention feature map, the region proposal network generates anchor boxes of various scales and proportions. Using a sliding window, it predicts the anchor box category scores and position offsets, retaining high-scoring regions and eliminating redundant candidate boxes with excessive overlap through non-maximum suppression. The mapping module obtains the FPN downsampling step size and maps the center points, width, and height of these candidate boxes to the original image coordinate space. Cropping is performed using boundary constraints to ensure the generated local image is complete and bounded, preserving valid information such as the customer's signature area.
[0115] The system divides the cropped image into pixel blocks and feeds them into a Transformer encoder-decoder architecture with a self-attention mechanism to extract sequence features. The semantic classification model then determines whether sensitive words are present. For example, it identifies high-confidence fields such as "loan amount," "credit period," and "guarantor," records their location information, and outputs the sensitive word detection results.
[0116] For image segments identified as sensitive areas, the system performs local texture restoration. First, a mask is generated, using a closed operation to enclose the entire sensitive text area. 3×3, 5×5, and 7×7 convolution kernels are then used to extract contextual and detailed features at different scales. A self-attention mechanism models spatial correlations, enhancing the consistency between the contract border, reconciliation grid, and background. The contextual features are fed into the restoration network, which uses a U-Net structure to fuse attention features within skip connections. Ultimately, a content-filled image of the sensitive area is generated, maintaining visual consistency and the integrity of the contract structure.
[0117] The Poisson fusion module uses the gradient of the repaired area to seamlessly blend sensitive areas with the original image's edges in terms of lighting, texture, and handwriting thickness. For example, in the area where the "loan amount" is replaced, the spacing between adjacent contract lines is maintained, ensuring no impact on subsequent business personnel review. Ultimately, the system outputs a desensitized image that matches the original image size, with sensitive text precisely removed and replaced, background textures restored losslessly, and the contract format preserved, allowing for archiving, display, or transmission without manual verification.
[0118] Through these steps, sensitive areas can be accurately restored at the spatial, semantic, and textural levels, ensuring that the desensitized image is visually free of obvious artifacts. The entire process, from location recognition to texture synthesis, combines strong constraints with a high degree of freedom, preserving the full image while effectively masking sensitive information, improving usability and compliance after desensitization.
[0119] The present invention relates to the field of image processing technology and can be applied to business scenarios such as medical health and financial technology. A method for desensitizing sensitive text in an image is disclosed, comprising: extracting multiple feature maps from an image to be processed, inputting the multiple feature maps into a feature pyramid network to generate multi-level semantically fused pyramid features, fusing a spatial attention mechanism to enhance the response of sensitive areas in feature maps at each level, generating candidate area coordinates through a region candidate network, mapping the candidate area coordinates to the image to be processed to obtain a local image, extracting text semantic information from the local image using a codec based on a self-attention mechanism, performing sensitive word detection in combination with a semantic classification model, and performing a local texture repair operation on the sensitive area based on the detection results to generate a desensitized image. The present invention improves the detection capability of small-sized sensitive text in an image by introducing a spatial attention mechanism and a semantic understanding module based on multi-scale feature fusion, and achieves accurate identification and natural desensitization of sensitive areas through candidate area positioning and a semantically driven repair strategy, thereby enhancing the security and usability of image content.
[0120] In one embodiment, the above step S20 includes:
[0121] S201, inputting the plurality of feature maps into a feature pyramid network, wherein the plurality of feature maps are arranged in a hierarchical order from high resolution to low resolution;
[0122] S202, performing lateral connection processing on the feature maps of each level through the feature pyramid network, and unifying the channel dimensions of the feature maps of each level through convolution operations to generate corresponding lateral connection feature maps;
[0123] S203, constructing a top-down path through the feature pyramid network, performing a convolution operation on the horizontally connected feature map of the lowest level, and generating pyramid features corresponding to the lowest level;
[0124] S204, starting from the second lowest level, in order of resolution from low to high, performing an upsampling operation on the pyramid features generated at the previous level, and performing element-by-element addition and fusion of the upsampled pyramid features with the horizontally connected feature map of the current level, performing a convolution operation on the fusion result, and generating a pyramid feature corresponding to the current level;
[0125] S205 , constructing the multi-level semantic fusion pyramid features from the pyramid features corresponding to all levels.
[0126] In this embodiment, the purpose of multi-scale fusion of multiple feature maps input into the feature pyramid network is to integrate semantic information and detailed features at different levels to form a multi-level expression that takes into account both global and local aspects. Feature maps are arranged from high to low resolution. High-level feature maps (such as the output of the fifth stage) contain rich semantic information but lack spatial details, while low-level feature maps (such as the output of the second stage) retain fine textures but have low semantic abstraction. The lateral connection process performs a 1×1 convolution operation on the feature maps of each level, unifying the number of channels to a preset dimension (usually 256 channels), eliminating channel differences between feature maps across levels, and ensuring compatibility for subsequent fusion. For example, in medical image processing, the 1024-channel feature map of the fifth stage is compressed to 256 channels through a 1×1 convolution and aligned with the 256-channel feature map of the second stage to facilitate cross-level information interaction.
[0127] The top-down path begins with the laterally connected feature maps at the deepest (lowest resolution) layer. 3×3 convolutions are used to refine the feature representation and generate initial pyramid features. This convolution removes noise introduced by channel compression and enhances semantic consistency. For example, in satellite imagery, the 3×3 convolutions on the lowest-level feature maps provide a clearer topology for the road network. Then, starting at the next deepest level, the pyramid features generated at the previous level are upsampled by a factor of 2 (typically using bilinear interpolation) to restore them to the resolution of the current level. This upsampled feature map is element-wise added to the laterally connected feature map at the current level, fusing high-level semantics with low-level details. The fused result is further refined by 3×3 convolutions to remove edge blurring caused by upsampling and enhance feature consistency. In financial document processing, semantic features from the fourth level (such as table borders) are added to detailed features from the third level (such as handwriting), and then 3×3 convolutions can accurately separate overlapping text and table lines.
[0128] The construction of multi-level pyramid features forms a hierarchical feature representation system. The highest-resolution pyramid features (e.g., level 2) are suitable for detecting tiny objects (such as microcalcifications in medical images), while intermediate levels (e.g., levels 3-4) are suitable for detecting medium-sized objects (such as signatures in financial documents), and the lowest level (e.g., level 5) is suitable for detecting large-scale objects (such as buildings in satellite imagery). Features at each level are strictly aligned in terms of channel count and spatial resolution, supporting parallel multi-scale object detection and segmentation.
[0129] Example: Assume that the residual convolutional network extracts 5 levels of feature maps from a 512×512 abdominal CT scan image, which are arranged from high to low resolution as follows:
[0130] C1 layer: 512×512 resolution (1 / 2 downsampling), 64 channels, capturing subtle textures of the original image (such as the boundary between subcutaneous fat and muscle);
[0131] C2 layer: 256×256 resolution (1 / 4 downsampling), 256 channels, identifies vascular branches and tiny calcifications;
[0132] C3 layer: 128×128 resolution (1 / 8 downsampling), 512 channels, localizes the edges and internal structures of the liver;
[0133] C4 layer: 64×64 resolution (1 / 16 downsampling), 1024 channels, encoding the morphological features of the tumor area;
[0134] C5 layer: 32×32 resolution (1 / 32 downsampling), 2048 channels, representing the semantic associations of the entire body's anatomical structures.
[0135] The feature maps of each level are unified to 256 dimensions through 1×1 convolution:
[0136] C1 layer: 64 channels → 256 channels, outputting a 512×512 horizontal feature map;
[0137] C2 layer: 256 channels → 256 channels, outputting a 256×256 horizontal feature map;
[0138] C3 layer: 512 channels → 256 channels, outputting a 128×128 horizontal feature map;
[0139] C4 layer: 1024 channels → 256 channels, outputting a 64×64 horizontal feature map;
[0140] C5 layer: 2048 channels → 256 channels, outputting a 32×32 horizontal feature map.
[0141] The top-down path building process includes:
[0142] Generate the lowest level pyramid features (P5):
[0143] Input: C5 horizontal feature map (32×32, 256 channels);
[0144] Operation: 3×3 convolution to optimize semantic features;
[0145] Output: P5 pyramid features (32×32, 256 channels), marking potential tumor areas throughout the body.
[0146] Generate P4 pyramid features:
[0147] Input: P5 feature map (32×32) is upsampled to 64×64 by 2x bilinear interpolation;
[0148] Fusion: element-wise addition with the C4 horizontal feature map (64×64);
[0149] Optimization: 3×3 convolution to eliminate fusion noise;
[0150] Output: P4 pyramid features (64×64, 256 channels), refined tumor boundaries.
[0151] Generate P3 pyramid features:
[0152] Input: P4 feature map (64×64) upsampled to 128×128;
[0153] Fusion: Added with the C3 horizontal feature map (128×128);
[0154] Optimization: 3×3 convolution to enhance feature consistency;
[0155] Output: P3 pyramid features (128×128, 256 channels) to separate tumor and healthy tissue.
[0156] Generate P2 pyramid features:
[0157] Input: P3 feature map (128×128) upsampled to 256×256;
[0158] Fusion: Added with the C2 horizontal feature map (256×256);
[0159] Optimization: 3×3 convolution to capture microcalcification points;
[0160] Output: P2 pyramid features (256×256, 256 channels), localizing vascular infiltration details.
[0161] Generate P1 pyramid features (optional):
[0162] Input: P2 feature map (256×256) upsampled to 512×512;
[0163] Fusion: Added with the C1 horizontal feature map (512×512);
[0164] Optimization: 3×3 convolution restores high-resolution details;
[0165] Output: P1 pyramid features (512×512, 256 channels), enhancing subcutaneous tissue contrast.
[0166] Then, the multi-level pyramid features obtained after the above process include:
[0167] P1: 512 × 512 resolution, for visualizing tiny nodules (<1 mm) in the subcutaneous fat layer;
[0168] P2: 256×256 resolution, detects vascular wall calcifications and assists in determining tumor blood supply;
[0169] P3: 128×128 resolution, segmenting the liver tumor core and surrounding tissue, and quantifying the proportion of necrotic area;
[0170] P4: 64×64 resolution, measuring the maximum diameter of the tumor (long diameter / short diameter), TNM staging;
[0171] P5: 32×32 resolution, analyzes tumor distribution throughout the body and assesses metastasis risk.
[0172] For example, in a 512×512 CT image: the P5 layer marks the right lobe of the liver as a high-risk area (probability >90%); the P4 layer refines the tumor boundary to 3.2cm×4.1cm with an error of <0.5mm; the P3 layer segments the tumor core (CT value +85HU) from the surrounding edema zone (+40HU); the P2 layer detects 12 microcalcification points (diameter 0.3-0.8mm), 8 of which were missed by traditional methods; the P1 layer enhances and shows 3 subcutaneous tiny nodules, which were confirmed to be early metastases by pathological biopsy.
[0173] This embodiment achieves a synergistic enhancement of semantic expression and spatial resolution by constructing a feature hierarchy from low to high layers and fusing upper-layer semantics with current spatial information at each layer. This improves the model's ability to recognize objects of various sizes, with a particular advantage in localizing small objects or text regions. It also avoids the computational cost of high-resolution modeling for all layers, achieving a balance between computational efficiency and expressive power.
[0174] In one embodiment, the above step S10 includes:
[0175] S101, inputting the image to be processed into the residual convolutional network, and generating an initial feature map through the initial convolutional layer of the residual convolutional network;
[0176] S102, inputting the initial feature map into a plurality of stacked residual blocks, each residual block sequentially extracting features of the input feature map through a convolution layer, normalizing the features through a batch normalization layer, performing nonlinear activation processing on the normalized features through an activation function layer, and adding the input feature map and the activated feature map element by element through a skip connection to generate a residual feature map;
[0177] S103, after each residual block generates a residual feature map, the channel attention module is used to adjust the channel weight of the residual feature map. The channel attention module compresses the spatial dimension information through global pooling and generates a weight coefficient for each channel through a fully connected layer. The weight coefficient is multiplied by the residual feature map channel by channel to generate a residual feature map after channel enhancement.
[0178] S104: In the residual blocks at different stages, the residual feature maps after channel enhancement are downsampled by a convolution operation with a step size greater than 1 to generate feature maps of multiple levels with decreasing resolution.
[0179] In this embodiment, the core task of extracting high-quality feature maps from the input image is to form a unified semantic representation for downstream attention fusion and region candidate modules by constructing a multi-level feature expression structure with deep semantic modeling capabilities and low-level spatial detail preservation capabilities. To this end, a residual convolutional network is introduced as the backbone of feature extraction to achieve multi-scale semantic abstraction and detail preservation while taking into account both depth and stability. The feature extraction process starts at the image input and usually includes an initial convolution operation. A larger convolution kernel (such as 7×7) is used to cover a wide receptive field, extracting initial texture and edge structure information from the full image level, and performing a first downsampling of the spatial resolution with a step size of 2 to compress the data dimension and enhance noise resistance.
[0180] The initial feature map serves as the input for subsequent residual blocks, undergoing layer-by-layer semantic extraction through multiple stacked residual blocks. Each residual block is built on the basic unit of "convolution-batch normalization-nonlinear activation." The convolution layer uses a fixed-size (e.g., 3×3) convolution kernel to expand the receptive field of the local structure. Batch normalization is used to standardize the feature scale between different batches, improving training convergence speed and model stability. Nonlinear activation functions (e.g., ReLU or Swish) enhance the model's expressiveness and introduce complex decision boundaries. Each residual block introduces a skip connection structure, passing the input features directly to the output and performing an element-by-element addition operation with the nonlinearly transformed result. This structure is essentially a gradient short-circuiting mechanism that alleviates the vanishing gradient problem in deep networks while maintaining model depth while retaining low-level input information, enhancing feature reversibility and plasticity.
[0181] After the output of each level of residual block, a channel attention module will be further introduced to enhance the representation ability of the feature map in the channel dimension. This module compresses the spatial dimensions in the feature map through global average pooling and global maximum pooling, forming two one-dimensional channel description vectors, which are then input into a fully connected network with shared weights to generate channel weight coefficients. These weights reflect the saliency of each channel in the current task and are ultimately injected into the original feature map through channel-by-channel multiplication, achieving dynamic enhancement of semantically salient channels and suppression of redundant channels. This mechanism is particularly suitable for distinguishing high semantic response areas from background redundant information in images. For example, in the subtitle detection task, it can significantly enhance the response amplitude of the text contour channel.
[0182] The structure of the residual network is not flat, but rather designed in stages. Between each key stage, spatial downsampling is performed through convolution operations with a stride of 2, gradually compressing the resolution of the feature map while improving its semantic abstraction capabilities. For example, the feature map output by the first stage retains almost all spatial details and is suitable for detecting small edges in the image; while the feature map output by the fifth stage, although with a lower spatial resolution, contains the contextual structure and high-level semantics of the entire image, which helps to identify long subtitles, repetitive text, or large sensitive areas. This multi-level feature map structure from high resolution to low resolution not only provides the original input for the pyramid fusion of the subsequent feature pyramid network, but also provides a multi-angle, multi-scale image semantic foundation for the region candidate and semantic classification modules.
[0183] Each component module in this feature extraction process is adjustable and scalable. For example, the kernel size of the initial convolutional layer can be adjusted according to the image resolution, the number and depth of the residual blocks can be scalable to the model's computational resources and target detection difficulty, and the channel attention module can be switched to the SE module, ECA module, or CBAM module to adapt to feature response patterns in different fields. In addition, the stride downsampling method can also choose depthwise separable convolution, pooling substitution, or spatial pyramid pooling strategies to optimize computational efficiency and feature fidelity in different scenarios.
[0184] This embodiment uses this feature extraction structure to extract high-level semantic information while preserving local image details, forming multi-scale feature maps with contextual understanding capabilities. These feature maps provide a foundational feature representation with deep semantics, wide resolution, and strong representation capabilities for subsequent steps such as pyramid fusion and region selection, significantly improving the accuracy and robustness of sensitive region positioning. This structure can effectively improve the ability to distinguish sensitive text areas, especially in image scenes with complex text and significant background interference.
[0185] In one embodiment, the above step S30 includes:
[0186] S301, performing global average pooling and global maximum pooling processing on each level feature map in the pyramid feature in the channel dimension to generate two compressed feature maps with the same spatial dimension;
[0187] S302, splicing the two compressed feature maps along the channel dimension into an intermediate feature map;
[0188] S303, performing spatial information modeling on the intermediate feature map through a convolutional layer to generate a single-channel spatial weight map;
[0189] S304, performing normalization processing on the spatial weight map to generate a normalized spatial weight map;
[0190] S305: Multiply the normalized spatial weight map by the corresponding hierarchical feature map element by element to generate an optimized attention feature map.
[0191] In this embodiment, after the multi-level pyramid feature map is constructed, a spatial attention mechanism is introduced within each pyramid feature map to further enhance the model's ability to focus on spatially sensitive areas. This mechanism strengthens the response weights of key locations in the spatial dimension. The core goal of this mechanism is to learn the importance of different locations within the feature map, allowing the network to focus more on local areas that may contain sensitive information, suppress interference from irrelevant background areas, and improve subsequent caption recognition and image restoration.
[0192] The spatial attention mechanism is implemented by first performing global average pooling and global max pooling on the channel dimension of each pyramid feature map, extracting the spatial distribution characteristics of the image from different statistical perspectives. Global average pooling captures the overall activation trend, reflecting the overall spatial response of the feature map; while global max pooling emphasizes the boundaries of strong response areas, capturing salient textures such as sensitive word edges and logo lines. Structurally, the outputs of these two pooling operations maintain the same spatial dimensions as the original, with a channel number of 1, forming two spatially compressed feature maps.
[0193] The two compressed feature maps are then concatenated along the channel dimension to form an intermediate feature map with two channels. This concatenation preserves both the mean and maximum response spatial distributions, facilitating the subsequent learning phase to combine these two characteristics to model spatial weights. This intermediate feature map is then fed into a convolutional layer, typically a two-dimensional convolution with a 7×7 receptive field. This convolutional layer establishes the spatial dependency structure between neighborhoods, learning the correlation between locations through the convolution kernel, and ultimately outputting a single-channel spatial weight map.
[0194] To enhance the interpretability and normalization capabilities of the spatial weight map, an activation function (such as Sigmoid) is used to normalize it, mapping the weight values of all pixels to between 0 and 1. This generates a normalized spatial weight map. Normalization prevents overfitting of certain regions with extremely large responses during model training and facilitates stable gradient return.
[0195] Finally, the normalized spatial weight map is fused with the original hierarchical pyramid feature map via element-by-element multiplication to achieve weighted modulation. This process is equivalent to applying a weight factor dynamically generated by the attention mechanism to each spatial location, thereby strengthening the feature representation of the target subtitle region and suppressing the response of irrelevant pixels. Unlike the channel attention mechanism, this method only models the spatial dimension, making it particularly suitable for complex scenes with text regions of varying shapes and irregular contours.
[0196] Throughout the execution process, each feature map layer independently completes the aforementioned attention calculation path, enabling parallel processing and ensuring efficient inference. The spatial attention module does not rely on high-level semantic inputs such as image categories, but instead models the image based solely on the statistical representation of the feature map itself, resulting in strong cross-image adaptability and scalability.
[0197] This spatial attention mechanism can be embedded into the processing path of each pyramid level. For example, a spatial attention branch is deployed in the pyramid feature maps of levels P2 to P5. Each branch consists of an average pooling operation, a max pooling operation, a concatenation operation, a 7×7 convolution layer, and a sigmoid activation function. The convolution layer weights can be shared across different levels or trained individually based on the complexity of the task.
[0198] When selecting deployment parameters, the convolution kernel size can be adjusted based on the object detection task. For small target characters in medical images, a 5×5 convolution is recommended to avoid over-smoothing of the context. For large-scale caption detection tasks such as news images or long social media images, a 7×7 convolution is recommended to achieve a larger spatial receptive field. Pooling operations use a non-overlapping sliding window approach by default to ensure spatial scale consistency. The activation function can be replaced with nonlinear functions more suitable for embedded deployments, such as Hard Sigmoid or Swish, depending on the model architecture.
[0199] In system implementation, this module can be built by calling existing APIs through standard deep learning frameworks (such as TensorFlow or PyTorch) without the need for additional handwritten operators, and has good engineering feasibility and cross-platform compatibility.
[0200] This implementation introduces a spatial attention mechanism to weight the significance of each pyramid-level feature map, enhancing the model's ability to locate spatial target areas, effectively suppressing background noise, and improving the accuracy of sensitive area detection. Spatial weight modeling is performed after multi-scale semantic fusion, inheriting global context while focusing on spatial differences, avoiding information omission or bias caused by early fusion.
[0201] In one embodiment, the above step S40 includes:
[0202] S401, generating anchor frames of multiple scales and aspect ratios at each spatial position of the optimized attention feature map;
[0203] S402, performing sliding window processing on the optimized attention feature map through the convolutional layer of the region candidate network to predict the category score and bounding box offset of each anchor box;
[0204] S403, adjusting the center coordinates and size of the anchor box according to the bounding box offset to generate an adjusted candidate box;
[0205] S404, sorting by category score from high to low, and retaining a preset number of candidate boxes with the highest scores;
[0206] S405 , performing non-maximum suppression processing on the retained candidate boxes, and removing redundant candidate boxes whose intersection-over-union ratio is greater than a preset threshold, to generate the candidate region coordinates.
[0207] In this embodiment, based on the attention feature map after optimizing the spatial attention mechanism, a Region Proposal Network (RPN) is introduced as a target localization module to extract high-confidence candidate region coordinates from the feature map. The goal is to obtain salient regions in the image that may contain sensitive subtitles in a lightweight manner, providing region-level input for subsequent semantic recognition and image restoration. RPN does not rely on specific category labels and predicts areas where targets may be located based solely on the spatial response information in the feature map. Therefore, it is particularly suitable for general sensitive information localization tasks.
[0208] The first step in this technical approach is to predefine anchor boxes of multiple scales (e.g., 32, 64, and 128 pixels) and aspect ratios (e.g., 1:1, 2:1, and 1:2) at each spatial location in the optimized attention feature map. Each anchor box is a candidate detection window, covering potential target regions of varying sizes and shapes. Anchor box generation follows a dense sliding window strategy, with each pixel in the feature map corresponding to a set of anchor boxes, thus achieving comprehensive coverage of the image space.
[0209] The optimized attention feature map is then processed using a sliding window by the convolutional layer in the RPN architecture to extract the spatial features of the local receptive field. For each anchor box, the convolutional layer outputs two key prediction values: a category score indicating whether the target region contains sensitive information; and a bounding box offset, which represents the position and size correction parameters of the anchor box relative to the ground-truth target box. This offset is typically composed of the center point coordinate offsets Δx and Δy, and the width and height scaling factors Δw and Δh.
[0210] By applying the predicted bounding box offsets to the center coordinates and width and height dimensions of the original anchor box, we can generate more precisely positioned adjusted candidate boxes. These adjusted candidate boxes are sorted from high to low based on their corresponding category scores, and a preset number (e.g., 200) are retained as the initial candidate set to prevent redundant candidate boxes from consuming excessive subsequent processing resources.
[0211] To further enhance the diversity and redundancy removal capabilities of candidate regions, a non-maximum suppression (NMS) strategy is introduced. Specifically, the algorithm iterates through the candidate box set, starting with the highest-scoring box, and sequentially removes overlapping candidate boxes whose intersection over union (IoU) with the current box exceeds a set threshold (e.g., 0.7). This method retains the target box set with strong spatial mutual exclusivity. The resulting candidate region coordinates represent a set of high-confidence, spatially complementary candidate subtitle regions.
[0212] In practical implementation, nine anchor boxes (three scales × three aspect ratios) can be assigned to each spatial location, and feature responses within each sliding window can be extracted using 3×3 convolutions. The RPN output structure can be configured as two parallel branches: a two-channel softmax branch outputting binary foreground and background classification scores, and a four-channel linear branch for bounding box regression. During the category score ranking stage, a top-k strategy is used, retaining 200 or 300 candidate boxes as a preliminary selection. The IoU threshold in non-maximum suppression can be adjusted to suit the task: 0.5 for improved recall in medical images and 0.7 for improved precision in complex financial instruments. It is recommended that all coordinate transformations and filtering operations be performed in parallel on the GPU to improve inference efficiency. The RPN can share parameters with the backbone network or be trained as an independent submodule. If the system has end-to-end training capabilities, it is recommended to reverse-optimize the RPN module using a joint loss function (category cross entropy and regression L1 loss) to improve localization performance.
[0213] This embodiment significantly improves the accuracy of early localization of sensitive subtitle areas by executing region candidate network processing based on the optimized attention feature map, avoiding missed detections due to incomplete semantic coverage. A dense set of candidate regions is constructed through a three-step mechanism of anchor box + boundary regression + NMS, significantly reducing the interference of redundant candidate boxes on downstream processing while improving localization recall.
[0214] In one embodiment, the above S50 includes:
[0215] S501, obtaining a downsampling step size of the feature pyramid network, and determining, based on the downsampling step size, the abscissa of the center point of the candidate region of the candidate region coordinates in the image to be processed, where the abscissa of the center point of the candidate region is the abscissa of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size;
[0216] S502, determining the vertical coordinate of the center point of the candidate region of the candidate region in the image to be processed based on the downsampling step size, where the vertical coordinate of the center point of the candidate region is the vertical coordinate of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size;
[0217] S503, determining an actual width of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step size, where the actual width of the candidate region is the multiplication of the candidate region width in the feature map space and the downsampling step size;
[0218] S504, calculating the actual height of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step size, where the actual height of the candidate region is the height of the candidate region in the feature map space multiplied by the downsampling step size;
[0219] S505: performing boundary constraint processing on the horizontal coordinate of the center point of the candidate region so that the horizontal coordinate of the center point of the candidate region is not less than zero and does not exceed the width of the image to be processed, and performing boundary constraint processing on the vertical coordinate of the center point of the candidate region so that the vertical coordinate of the center point of the candidate region is not less than zero and does not exceed the height of the image to be processed;
[0220] S506: Determine the left boundary coordinates and the right boundary coordinates of the candidate region in the image to be processed based on the actual width and the actual height of the candidate region, and adjust the actual width of the candidate region to the difference between the right boundary coordinate and the left boundary coordinate, so that the right boundary coordinate does not exceed the width of the image to be processed;
[0221] S507: Determine the upper and lower boundary coordinates of the candidate region in the image to be processed based on the actual width and the actual height of the candidate region, and adjust the actual height of the candidate region to the difference between the lower and upper boundary coordinates, with the lower boundary coordinate not exceeding the height of the image to be processed.
[0222] S508 , based on the horizontal coordinate of the center point of the candidate area after constraint processing, the vertical coordinate of the center point of the candidate area, and the adjusted actual width and actual height of the candidate area, crop the corresponding rectangular area from the image to be processed to generate a local image.
[0223] In this embodiment, in the process of mapping the coordinates of the candidate region from the optimized attention feature map space to the image space to be processed, the goal is to restore the spatial consistency between the semantic features and the original image to support subsequent local image recognition and repair operations. Since the feature pyramid network introduces multi-level downsampling in the process of constructing pyramid features, each layer of feature maps has a different spatial resolution, so its coordinate system is compressed compared to the original image. In order to achieve the restoration of the coordinate scale, it is necessary to build the mapping logic based on the downsampling step corresponding to each layer of feature maps. The downsampling step refers to the pixel range of the original image covered by each feature map pixel. For example, when the step is 16, a pixel position in the feature map corresponds to a 16×16 pixel area in the original image. This parameter is usually defined by the network structure. For example, the C5 layer of ResNet has a step of 32, and the P3 layer has a step of 8.
[0224] Mapping the center point position of the candidate region is the first step in this process. The conversion logic from feature map space to image space is as follows: multiply the horizontal and vertical coordinates of the center point of the candidate box in the feature map by the downsampling step size and add half of the step size to form the center point coordinates that accurately correspond to the original image area. For example, if the position of the candidate box on the feature map is (6,8) and the step size is 16, then the horizontal and vertical coordinates of the corresponding image center point are 6×16+8=104 and 8×16+8=136 respectively. This compensation mechanism ensures that the center point is not biased towards the boundary, but is aligned with the geometric center of the corresponding area, which is conducive to the complete extraction of subsequent target information. In particular, in text area detection, offset errors may lead to incomplete character segmentation, affecting the desensitization effect.
[0225] Restoring the size of the candidate box also needs to be combined with the downsampling step size for amplification. If the candidate box has a width of 4, a height of 3, and a step size of 16 on the feature map, it should be a rectangular area of 64×48 pixels in the image space. However, the mapped coordinates may partially fall outside the image boundary, especially when the target is close to the edge of the image, and boundary constraint operations need to be performed to ensure the legality of the coordinates. First, the center point coordinates are corrected to ensure that their horizontal and vertical values are not less than 0 and not greater than the maximum width and height of the image. Then, the upper, lower, left, and right boundaries of the rectangular area are deduced based on this. If the right or lower boundary exceeds the image range, it is truncated to the edge of the image, and the actual width and height are recalculated accordingly. This logic effectively avoids image reading overflow errors while ensuring that the target area is not deformed and distorted due to truncation.
[0226] Once the mapped center point coordinates and dimensions have been adjusted using boundary constraints, the image can be cropped based on this coordinate set. By calling the common rectangular cropping function in the image processing module, an image block that completely overlaps with the candidate region is extracted and used as input for subsequent sensitive word recognition and texture restoration. In medical images, this cropping strategy ensures that even tiny lesions (such as 0.5mm microcalcifications) are fully included; in financial documents, this strategy supports the precise extraction of sensitive fields such as signatures and ID numbers.
[0227] In order to improve the adaptability of the mapping operation in different application scenarios, a set of dynamic adjustment strategies can be designed. For example, for high-resolution image scenes, a larger step size can be automatically set according to the width and height of the input image to reduce the computational burden; while in low-resolution images or small target dense scenes, a smaller step size is used to ensure that details are not compressed and lost. At the same time, for the boundary crossing problem generated during the mapping process, the boundary filling mechanism can be enabled to fill the excess part of the candidate box by mirror filling or repeating the edge pixels to ensure the integrity of the target. In addition, in embedded or mobile deployment scenarios, considering performance optimization, the multiplication operation can be replaced by a bit shift operation. For example, multiplication by 16 can be represented by a 4-bit left shift, which effectively reduces processing delays.
[0228] For example, in healthcare, patient radiological images (such as CT scans and MRI images) often contain manually annotated patient names, serial numbers, or examination dates. This information often appears as text overlaid on the edges or corners of the image. Using the aforementioned image coordinate mapping technique, the candidate regions generated from the feature map space for sensitive text can be accurately restored to the original image space. For example, consider an MRI image with a resolution of 512×512 pixels. The sensitive text "Patient ID: 8392" is located in the upper right corner of the image. In the third-layer feature map of the feature pyramid network (with a downsampling stride of 8), the candidate region coordinates are (x=60, y=10, w=6, h=3). After coordinate mapping, the center coordinates are (60×8+4, 10×8+4)=(484, 84), with a width of 6×8=48 and a height of 3×8=24. Further application of boundary constraint logic confirms that the right boundary of 484+24=508 does not exceed the image width, making the cropped region legal. Finally, a rectangular image block containing "PatientID:8392" was successfully cropped from the original image for subsequent sensitive word identification and repair. This precise mapping and cropping process ensures the integrity and accurate positioning of sensitive areas, effectively desensitizing patient privacy without compromising the core diagnostic content of the medical image. This approach is suitable for a variety of scenarios, including hospital archive management, pre-processing for remote consultations, and medical image sharing platforms.
[0229] This embodiment uses coordinate mapping processing to accurately locate the feature map spatial candidate box generated in the region candidate network in the original image, ensuring the direct perception consistency of the image content in subsequent text recognition, semantic classification, and image restoration processing. It avoids problems such as mis-cropping of regions and size mismatch due to inconsistent scales, which is particularly important in small target detection or boundary-sensitive restoration scenarios. The boundary constraint mechanism improves the robustness of the system in corner areas, preventing partial loss of sensitive information or abnormal image access.
[0230] In one embodiment, the above S80 includes:
[0231] S801, determining a local sensitive area in the local image based on the confidence level of the sensitive word position in the sensitive word detection result, and mapping the position of the local sensitive area to the global coordinate system of the image to be processed to generate global sensitive area coordinates;
[0232] S802, cropping the corresponding global sensitive area from the image to be processed according to the global sensitive area coordinates, and generating a repair area mask;
[0233] S803, performing a multi-scale convolution operation on the global sensitive area to generate a multi-scale feature map containing global semantic information and local detail features;
[0234] S804, performing a self-attention mechanism on the multi-scale feature map, analyzing the correlation weights between pixel positions in the multi-scale feature map, generating an attention weight map, and multiplying the attention weight map by the multi-scale feature map element by element to generate a context-aware feature map;
[0235] S805, inputting the context-aware feature map into the restoration network, and generating a restored sensitive area image through alternately stacked residual convolution layers and dilated convolution layers;
[0236] S806 , performing Poisson fusion processing on the repaired sensitive area image and the corresponding position in the image to be processed according to the repair area mask to generate the desensitized image.
[0237] In this embodiment, the sensitive areas in the image usually exist in the form of text or occlusion, with a clear spatial position and content structure. In order to achieve directional replacement of these areas, it is necessary to determine the spatial position of the local sensitive area based on the confidence information given in the sensitive word detection result. The detection result is usually a list of text boxes, each box contains the center coordinates, size information and the predicted probability that the position is a sensitive word. When mapping the sensitive area located in the local image to the global image space, it is necessary to record the original starting coordinates of the current local image, restore it to the absolute position in the full image coordinate system through offset transformation, and then accurately crop out the global sensitive area for repair.
[0238] After cropping the sensitive area, a repair mask is generated to guide subsequent repair. This mask, in the form of a binary image, defines the boundary between the repaired and non-repaired areas. To enhance the continuity of the repaired edges, a morphological closing operation can be used during the mask generation phase. This involves first dilating the sensitive area and then removing isolated noise through erosion, ensuring smooth edges and internal continuity. The mask restricts the repair operation to the target area, preventing inadvertent modification of other valid image information.
[0239] Multi-scale convolution uses kernels of different sizes (such as 3×3, 5×5, and 7×7) to simultaneously extract local details and global structure. Small kernels are better suited for extracting texture features such as character edges and stroke corners, while large kernels can capture the spatial relationships between characters and their overall arrangement. Multi-scale feature maps are concatenated in the channel dimension and then compressed to a uniform dimension using a 1×1 convolution. This improves the compactness of the representation and enhances semantic fusion, resulting in a multi-scale feature map rich in contextual information.
[0240] The self-attention mechanism is used to model long-range dependencies between pixels in the spatial dimension within a feature map. By calculating the correlation weights between each pixel and other pixels, an attention weight map is constructed. This map serves as an explicit guidance mechanism for feature enhancement and is element-wise multiplied with the multi-scale feature map to produce a context-aware feature map. This mechanism allows the model to focus on regions with similar content and continuous structure, effectively suppressing background interference and making the inpainting operation more context-consistent.
[0241] The context-aware feature map is fed into the inpainting network, which uses a combination of residual and dilated convolutions to expand the receptive field while preserving local details. Residual connections mitigate the vanishing gradient problem in deep networks, while dilated convolutions enhance the feature map's ability to capture long-range semantics without increasing the number of parameters. This inpainting network generates high-fidelity, structurally consistent inpainted images, effectively filling in areas occupied by sensitive information.
[0242] Finally, the inpainted image is fused back to its corresponding position in the original image using the Poisson fusion method. Based on the principle of gradient consistency, Poisson fusion constructs a set of Poisson equations at the boundaries of the inpainted area. Through iterative solutions, the grayscale gradient at the edge of the inpainted area seamlessly blends with the surrounding image, ensuring no noticeable abrupt changes in color or texture in the transition zone. The resulting desensitized image is visually coherent, making the inpainting traces difficult to detect, meeting the security requirement of irreversible reconstruction of sensitive information.
[0243] In one specific embodiment, for the detected sensitive word position, it is first necessary to extract the corresponding local image area from the image to be processed and accurately restore its coordinate position in the global image. The mapping process is based on the local image cropping record obtained by the previous candidate frame processing, for example, the displacement between the original image and the candidate area (the upper left corner reference coordinate) is recorded, and the local coordinates can be restored to the global image coordinates by adding the offset. Morphological image processing technology is used in the mask generation stage to improve the quality of the regional boundary. Specifically, the cv2.dilate and cv2.erode functions of OpenCV are used to construct a closed operation process. The initial mask is a binary image, in which the sensitive area is 1 and the rest are 0. A 3×3 structural element is used for one expansion (the number of iterations can be set to 1 or 2), followed by erosion of the same scale to effectively fill the holes in the area and connect the broken areas, such as the disconnected digital strokes in the ID card number or the broken segments of the handwritten signature. When the cropped sensitive areas are fed into the convolutional neural network, a multi-scale convolutional module (like an Inception-like structure) is constructed, consisting of three parallel branches. These modules use 3×3, 5×5, and 7×7 convolution kernels to extract features at different scales. The channel outputs are set to 64, 64, and 128, respectively. After channel concatenation, 1×1 convolutions are used to compress the channels to 256 dimensions and normalize the dimensions. This operation can be implemented in PyTorch, with BatchNorm and ReLU activations inserted between convolutional blocks to improve representation stability. Self-attention modeling is then performed on the fused features using the standard Scaled Dot-Product Attention mechanism. A linear mapping is used to generate query (Q), key (K), and value (V) matrices. An attention weight matrix is then calculated and multiplied with the V matrix to produce a context-aware feature map. This implementation can leverage a multi-head attention module (such as some implementations of the Transformer Encoder) with four or eight attention heads to capture multi-dimensional feature relationships. The context-aware feature map is fed into the restoration network as input. The restoration network adopts a U-Net structure. The encoder part contains four stacked residual blocks, each of which contains two 3×3 convolutions, BatchNorm and ReLU activations, and is equipped with skip connections. The decoder part uses a four-layer deconvolution or upsampling + convolution combination, and introduces a dilated convolution (dilation = 2 or 3) to expand the receptive field and improve background modeling capabilities. The skip connection of each layer can be embedded in the spatial attention module to strengthen semantic alignment. The output image size of the restoration network is related to the sensitive area of the input. Figure 1To predict a reconstructed area that is consistent with the surrounding background texture. In the fusion stage, the Poisson fusion strategy is used to achieve lighting consistency and natural edge transition between the repaired area and the original image. In actual implementation, the gradients of the repaired area and the edge transition zone (such as expanding 10 pixels around) are extracted, a sparse Poisson equation system (based on the divergence of pixel gradients) is constructed, and iterative calculations are performed using solvers such as scipy.sparse.linalg.cg, and the solution results are overwritten to the corresponding positions of the original image. If the fusion area contains high-frequency backgrounds (such as seals or grid lines), the edge gradient weight parameter in Poisson fusion needs to be increased to prevent texture blurring.
[0244] Example illustration: In the scenario of medical and health data processing, for example, a hospital system needs to publicly share scientific research on chest X-ray films, and the lower left corner of the image contains handwritten patient names, numbers, and shooting dates. First, text areas such as "Zhang San" and "2024-05-01" are identified through sensitive word detection, and their position confidence exceeds 0.95, triggering the desensitization process. After mapping the coordinates, the corresponding area is cropped, and stable masks are formed by filling in the discontinuous strokes of the font through closing operations; multi-scale convolutions are used to extract stroke textures, character arrangements, and background structures; the self-attention mechanism strengthens the context consistency between characters and the background transition areas; the repair network reconstructs textures consistent with the surrounding lung tissues while maintaining the integrity of the skeleton lines; finally, Poisson fusion makes the edge lighting consistent, and the output image has no name, no timestamp, and continuous structure, without affecting subsequent diagnostic tasks.
[0245] Through the above steps, this embodiment realizes a full-process processing link for the detected sensitive areas from positioning, characterization, semantic modeling to high-quality texture generation and natural fusion. It effectively overcomes problems such as missing structures, semantic drift, and abrupt edges in traditional repair methods, ensuring that in scenarios with extremely high requirements for visual authenticity and content security such as medical and financial fields, desensitized images that meet business specifications can also be output.
[0246] In one embodiment, an image sensitive text desensitization device is provided, and this image sensitive text desensitization device corresponds one-to-one with the image sensitive text desensitization method in the above embodiment. Refer to Figure 3 , Figure 3 is a schematic diagram of the functional modules of a preferred embodiment of the image sensitive text desensitization device of the present invention. Residual feature extraction module 10, multi-scale fusion module 20, spatial attention enhancement module 30, candidate region generation module 40, coordinate mapping and cropping module 50, self-attention text extraction module 60, sensitive word recognition module 70, and local image repair module 80. The detailed description of each functional module is as follows:
[0247] The residual feature extraction module 10 is used to extract multiple feature maps from the image to be processed through a residual convolutional network;
[0248] A multi-scale fusion module 20 is used to input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0249] A spatial attention enhancement module 30 is configured to integrate a spatial attention mechanism into the feature maps of each level of the pyramid feature, generate a spatial weight map corresponding to the feature map of each level, and perform element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0250] A candidate region generation module 40 is configured to generate candidate region coordinates through a region candidate network based on the optimized attention feature map;
[0251] A coordinate mapping and cropping module 50 is used to map the coordinates of the candidate region to the image to be processed and determine a local image of the corresponding region;
[0252] A self-attention text extraction module 60 is used to segment the local image into pixel blocks, and input the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract text sequences;
[0253] A sensitive word identification module 70 is configured to input the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0254] The local image restoration module 80 is used to perform local texture restoration on the sensitive area of the image to be processed according to the sensitive word detection result to generate a desensitized image.
[0255] In one embodiment, the multi-scale fusion module 20 is specifically configured to:
[0256] Inputting the plurality of feature maps into a feature pyramid network, wherein the plurality of feature maps are arranged in a hierarchical order from high resolution to low resolution;
[0257] Performing lateral connection processing on the feature maps of each level through the feature pyramid network, and unifying the channel dimensions of the feature maps of each level through convolution operations to generate corresponding lateral connection feature maps;
[0258] Constructing a top-down path through the feature pyramid network, performing a convolution operation on the horizontally connected feature map of the lowest level to generate pyramid features corresponding to the lowest level;
[0259] Starting from the second lowest level, in order from low to high resolution, the pyramid features generated by the previous level are upsampled, and the upsampled pyramid features are fused element by element with the horizontal connection feature map of the current level. The convolution operation is performed on the fusion result to generate the pyramid features corresponding to the current level.
[0260] The pyramid features corresponding to all levels constitute the multi-level semantic fusion pyramid features.
[0261] In one embodiment, the residual feature extraction module 10 is specifically configured to:
[0262] Inputting the image to be processed into the residual convolutional network, and generating an initial feature map through the initial convolutional layer of the residual convolutional network;
[0263] Input the initial feature map into multiple stacked residual blocks, each residual block extracts features of the input feature map in sequence through a convolution layer, normalizes the features through a batch normalization layer, performs nonlinear activation on the normalized features through an activation function layer, and adds the input feature map and the activated feature map element by element through a skip connection to generate a residual feature map;
[0264] After each residual block generates a residual feature map, the channel weight of the residual feature map is adjusted through the channel attention module. The channel attention module compresses the spatial dimension information through global pooling and generates a weight coefficient for each channel through a fully connected layer. The weight coefficient is multiplied by the residual feature map channel by channel to generate a residual feature map after channel enhancement.
[0265] In the residual blocks at different stages, the residual feature maps after channel enhancement are downsampled through convolution operations with a step size greater than 1 to generate feature maps of multiple levels with decreasing resolution.
[0266] In one embodiment, the spatial attention enhancement module 30 is specifically configured to:
[0267] For each level feature map in the pyramid feature, global average pooling and global maximum pooling are performed in the channel dimension to generate two compressed feature maps with the same spatial dimension;
[0268] Concatenate the two compressed feature maps into an intermediate feature map along the channel dimension;
[0269] Performing spatial information modeling on the intermediate feature map through a convolutional layer to generate a single-channel spatial weight map;
[0270] Normalizing the spatial weight map to generate a normalized spatial weight map;
[0271] The normalized spatial weight map is multiplied element-wise with the corresponding hierarchical feature map to generate the optimized attention feature map.
[0272] In one embodiment, the candidate region generating module 40 is specifically configured to:
[0273] Generating anchor boxes of multiple scales and aspect ratios at each spatial position of the optimized attention feature map;
[0274] Performing sliding window processing on the optimized attention feature map through the convolutional layer of the region proposal network to predict the category score and bounding box offset of each anchor box;
[0275] Adjusting the center coordinates and size of the anchor box according to the bounding box offset to generate an adjusted candidate box;
[0276] Sort by category score from high to low, and retain a preset number of candidate boxes with the highest scores;
[0277] Non-maximum suppression processing is performed on the retained candidate boxes, and redundant candidate boxes with an intersection-over-union ratio greater than a preset threshold are removed to generate the candidate region coordinates.
[0278] In one embodiment, the coordinate mapping and clipping module 50 is specifically configured to:
[0279] Obtaining a downsampling step size of the feature pyramid network, and determining, based on the downsampling step size, the abscissa of the center point of the candidate region of the candidate region coordinates in the image to be processed, where the abscissa of the center point of the candidate region is the abscissa of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size;
[0280] Determine, based on the downsampling step size, the vertical coordinate of the center point of the candidate region in the image to be processed, wherein the vertical coordinate of the center point of the candidate region is the vertical coordinate of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size;
[0281] Determine, based on the downsampling step, an actual width of the candidate region of the candidate region coordinates in the image to be processed, where the actual width of the candidate region is the multiplication of the candidate region width in the feature map space and the downsampling step;
[0282] Calculating the actual height of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step, wherein the actual height of the candidate region is the height of the candidate region in the feature map space multiplied by the downsampling step;
[0283] Performing boundary constraint processing on the horizontal coordinate of the center point of the candidate region so that the horizontal coordinate of the center point of the candidate region is not less than zero and does not exceed the width of the image to be processed, and performing boundary constraint processing on the vertical coordinate of the center point of the candidate region so that the vertical coordinate of the center point of the candidate region is not less than zero and does not exceed the height of the image to be processed;
[0284] Determine the left boundary coordinates and the right boundary coordinates of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region, and adjust the actual width of the candidate region to the difference between the right boundary coordinate and the left boundary coordinate, and the right boundary coordinate does not exceed the width of the image to be processed;
[0285] Determine the upper boundary coordinates and lower boundary coordinates of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region, and adjust the actual height of the candidate region to the difference between the lower boundary coordinate and the upper boundary coordinate, and the lower boundary coordinate does not exceed the height of the image to be processed;
[0286] According to the horizontal coordinate of the center point of the candidate area after constraint processing, the vertical coordinate of the center point of the candidate area and the adjusted actual width and actual height of the candidate area, the corresponding rectangular area is cropped from the image to be processed to generate a local image.
[0287] In one embodiment, the local image restoration module 80 is specifically configured to:
[0288] Determining a local sensitive area in the local image according to the confidence level of the sensitive word position in the sensitive word detection result, and mapping the position of the local sensitive area to the global coordinate system of the image to be processed to generate global sensitive area coordinates;
[0289] According to the global sensitive area coordinates, the corresponding global sensitive area is cropped from the image to be processed, and a repair area mask is generated;
[0290] Performing a multi-scale convolution operation on the global sensitive area to generate a multi-scale feature map containing global semantic information and local detail features;
[0291] Performing a self-attention mechanism on the multi-scale feature map, analyzing the correlation weights between pixel positions in the multi-scale feature map to generate an attention weight map, and multiplying the attention weight map by the multi-scale feature map element-by-element to generate a context-aware feature map;
[0292] Inputting the context-aware feature map into the restoration network, and generating a restored sensitive area image through alternately stacked residual convolution layers and hole convolution layers;
[0293] According to the repaired area mask, the repaired sensitive area image and the corresponding position in the image to be processed are subjected to Poisson fusion processing to generate the desensitized image.
[0294] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 4As shown. The computer device includes a processor, memory, network interface and database connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes non-volatile and / or volatile storage media and internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external user terminal via a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the server side of a method for desensitizing image-sensitive text.
[0295] In one embodiment, a computer device is provided. The computer device may be a user terminal, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, memory, network interface, display screen and input device connected via a system bus. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server via a network connection. When the computer program is executed by the processor, it realizes the functions or steps of a user-side method for desensitizing image-sensitive text.
[0296] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are performed:
[0297] Extract multiple feature maps from the image to be processed through the residual convolutional network;
[0298] Inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0299] Integrating the spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0300] Based on the optimized attention feature map, generating candidate region coordinates through a region proposal network;
[0301] Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region;
[0302] Segmenting the local image into pixel blocks, and inputting the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract text sequences;
[0303] Inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0304] According to the sensitive word detection result, local texture restoration is performed on the sensitive area of the image to be processed to generate a desensitized image.
[0305] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0306] Extract multiple feature maps from the image to be processed through the residual convolutional network;
[0307] Inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features;
[0308] Integrating the spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map;
[0309] Based on the optimized attention feature map, generating candidate region coordinates through a region proposal network;
[0310] Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region;
[0311] Segmenting the local image into pixel blocks, and inputting the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract text sequences;
[0312] Inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result;
[0313] According to the sensitive word detection result, local texture restoration is performed on the sensitive area of the image to be processed to generate a desensitized image.
[0314] It should be noted that the above functions or steps that can be implemented by the computer-readable storage medium or computer device can be found in the relevant descriptions of the server side and the user side in the aforementioned method embodiment. To avoid repetition, they will not be described one by one here.
[0315] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When executed, the computer program can include the processes of the above-described method embodiments. Any reference to memory, storage, database, or other media used in the various embodiments provided herein may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in various forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link DRAM (SLDRAM), RAMbus direct RAM (RDRAM), direct RAMbus dynamic RAM (DRDRAM), and RAMbus dynamic RAM (RDRAM).
[0316] Those skilled in the art will clearly understand that for the sake of convenience and brevity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.
[0317] It should be noted that if any software tools or components other than those of the Company appear in the embodiments of this application, they are merely for illustration and do not represent actual use. The above embodiments are intended only to illustrate the technical solutions of the present invention, not to limit them. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the above embodiments, or replace some of the technical features therein with equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the scope of protection of the present invention.
Claims
1. A method for desensitizing image-sensitive text, characterized in that: The following steps are involved: Extract multiple feature maps from the image to be processed through the residual convolutional network; Inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features; Integrating the spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map; Based on the optimized attention feature map, generating candidate region coordinates through a region proposal network; Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region; Segmenting the local image into pixel blocks, and inputting the pixel blocks into a codec based on a self-attention mechanism after linear projection and position encoding to extract text sequences; Inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result; Determining a local sensitive area in the local image according to the confidence level of the sensitive word position in the sensitive word detection result, and mapping the position of the local sensitive area to the global coordinate system of the image to be processed to generate global sensitive area coordinates; According to the global sensitive area coordinates, the corresponding global sensitive area is cropped from the image to be processed, and a repair area mask is generated; Performing a multi-scale convolution operation on the global sensitive area to generate a multi-scale feature map containing global semantic information and local detail features; Performing a self-attention mechanism on the multi-scale feature map, analyzing the correlation weights between pixel positions in the multi-scale feature map to generate an attention weight map, and multiplying the attention weight map by the multi-scale feature map element-by-element to generate a context-aware feature map; Inputting the context-aware feature map into the restoration network, and generating a restored sensitive area image through alternately stacked residual convolution layers and hole convolution layers; According to the repaired area mask, the repaired sensitive area image and the corresponding position in the image to be processed are subjected to Poisson fusion processing to generate a desensitized image.
2. The method for desensitizing image-sensitive text according to claim 1, wherein: Inputting the multiple feature maps into the feature pyramid network for multi-scale fusion to generate multi-level semantic fusion pyramid features, including: Inputting the plurality of feature maps into a feature pyramid network, wherein the plurality of feature maps are arranged in a hierarchical order from high resolution to low resolution; Performing lateral connection processing on the feature maps of each level through the feature pyramid network, and unifying the channel dimensions of the feature maps of each level through convolution operations to generate corresponding lateral connection feature maps; Constructing a top-down path through the feature pyramid network, performing a convolution operation on the horizontally connected feature map of the lowest level to generate pyramid features corresponding to the lowest level; Starting from the second lowest level, in order from low to high resolution, the pyramid features generated by the previous level are upsampled, and the upsampled pyramid features are fused element by element with the horizontal connection feature map of the current level. The convolution operation is performed on the fusion result to generate the pyramid features corresponding to the current level. The pyramid features corresponding to all levels constitute the multi-level semantic fusion pyramid features.
3. The method for desensitizing image-sensitive text according to claim 1, wherein: Multiple feature maps are extracted from the image to be processed through the residual convolutional network, including: Inputting the image to be processed into the residual convolutional network, and generating an initial feature map through the initial convolutional layer of the residual convolutional network; Input the initial feature map into multiple stacked residual blocks, each residual block extracts features of the input feature map in sequence through a convolution layer, normalizes the features through a batch normalization layer, performs nonlinear activation on the normalized features through an activation function layer, and adds the input feature map and the activated feature map element by element through a skip connection to generate a residual feature map; After each residual block generates a residual feature map, the channel weight of the residual feature map is adjusted through the channel attention module. The channel attention module compresses the spatial dimension information through global pooling and generates a weight coefficient for each channel through a fully connected layer. The weight coefficient is multiplied by the residual feature map channel by channel to generate a residual feature map after channel enhancement. In the residual blocks at different stages, the residual feature maps after channel enhancement are downsampled through convolution operations with a step size greater than 1 to generate feature maps of multiple levels with decreasing resolution.
4. The method for desensitizing image-sensitive text according to claim 1, wherein: Integrating the spatial attention mechanism into the feature maps of each level of the pyramid feature to generate a spatial weight map corresponding to the feature map of each level, and performing element-wise multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map, including: For each level feature map in the pyramid feature, global average pooling and global maximum pooling are performed in the channel dimension to generate two compressed feature maps with the same spatial dimension; Concatenate the two compressed feature maps into an intermediate feature map along the channel dimension; Performing spatial information modeling on the intermediate feature map through a convolutional layer to generate a single-channel spatial weight map; Normalizing the spatial weight map to generate a normalized spatial weight map; The normalized spatial weight map is multiplied element-wise with the corresponding hierarchical feature map to generate the optimized attention feature map.
5. The method for desensitizing image-sensitive text according to claim 1, wherein: Based on the optimized attention feature map, candidate region coordinates are generated through a region proposal network, including: Generating anchor boxes of multiple scales and aspect ratios at each spatial position of the optimized attention feature map; Performing sliding window processing on the optimized attention feature map through the convolutional layer of the region proposal network to predict the category score and bounding box offset of each anchor box; Adjusting the center coordinates and size of the anchor box according to the bounding box offset to generate an adjusted candidate box; Sort by category score from high to low, and retain a preset number of candidate boxes with the highest scores; Non-maximum suppression processing is performed on the retained candidate boxes, and redundant candidate boxes with an intersection-over-union ratio greater than a preset threshold are removed to generate the candidate region coordinates.
6. The method for desensitizing image-sensitive text according to claim 1, wherein: Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region includes: Obtaining a downsampling step size of the feature pyramid network, and determining, based on the downsampling step size, the abscissa of the center point of the candidate region of the candidate region coordinates in the image to be processed, where the abscissa of the center point of the candidate region is the abscissa of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size; Determine, based on the downsampling step size, the vertical coordinate of the center point of the candidate region in the image to be processed, wherein the vertical coordinate of the center point of the candidate region is the vertical coordinate of the candidate region in the feature map space multiplied by the downsampling step size plus half of the downsampling step size; Determine, based on the downsampling step, an actual width of the candidate region of the candidate region coordinates in the image to be processed, where the actual width of the candidate region is the multiplication of the candidate region width in the feature map space and the downsampling step; Calculating the actual height of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step, wherein the actual height of the candidate region is the height of the candidate region in the feature map space multiplied by the downsampling step; Performing boundary constraint processing on the horizontal coordinate of the center point of the candidate region so that the horizontal coordinate of the center point of the candidate region is not less than zero and does not exceed the width of the image to be processed, and performing boundary constraint processing on the vertical coordinate of the center point of the candidate region so that the vertical coordinate of the center point of the candidate region is not less than zero and does not exceed the height of the image to be processed; Determine the left boundary coordinates and the right boundary coordinates of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region, and adjust the actual width of the candidate region to the difference between the right boundary coordinate and the left boundary coordinate, and the right boundary coordinate does not exceed the width of the image to be processed; Determine the upper boundary coordinates and lower boundary coordinates of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region, and adjust the actual height of the candidate region to the difference between the lower boundary coordinate and the upper boundary coordinate, and the lower boundary coordinate does not exceed the height of the image to be processed; According to the horizontal coordinate of the center point of the candidate area after constraint processing, the vertical coordinate of the center point of the candidate area and the adjusted actual width and actual height of the candidate area, the corresponding rectangular area is cropped from the image to be processed to generate a local image.
7. A device for desensitizing image-sensitive text, characterized in that: The image-sensitive text desensitization device includes: A residual feature extraction module is used to extract multiple feature maps from the image to be processed through a residual convolutional network; A multi-scale fusion module is used to input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate multi-level semantically fused pyramid features; A spatial attention enhancement module is used to integrate the spatial attention mechanism into the feature maps of each level of the pyramid feature, generate a spatial weight map corresponding to the feature map of each level, and perform element-by-element multiplication of the spatial weight map with the corresponding feature map of each level to generate a corresponding optimized attention feature map; A candidate region generation module, configured to generate candidate region coordinates through a region candidate network based on the optimized attention feature map; A coordinate mapping and cropping module, configured to map the coordinates of the candidate region to the image to be processed and determine a local image of the corresponding region; A self-attention text extraction module is used to divide the local image into pixel blocks, and input the pixel blocks into a codec based on the self-attention mechanism after linear projection and position encoding to extract text sequences; A sensitive word recognition module is used to input the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result; A local image restoration module is used to determine the local sensitive area in the local image based on the confidence of the sensitive word position in the sensitive word detection result, and map the position of the local sensitive area to the global coordinate system of the image to be processed to generate the global sensitive area coordinates; according to the global sensitive area coordinates, the corresponding global sensitive area is cropped from the image to be processed, and a restoration area mask is generated; a multi-scale convolution operation is performed on the global sensitive area to generate a multi-scale feature map containing global semantic information and local detail features; a self-attention mechanism is performed on the multi-scale feature map, the correlation weights between the pixel positions in the multi-scale feature map are analyzed, an attention weight map is generated, and the attention weight map is element-wise multiplied with the multi-scale feature map to generate a context-aware feature map; the context-aware feature map is input into the restoration network, and a restored sensitive area image is generated by alternatingly stacking residual convolution layers and void convolution layers; according to the restoration area mask, the restored sensitive area image is Poisson fused with the corresponding position in the image to be processed to generate a desensitized image.
8. A computer device, characterized in that: The computer device includes a memory, a processor, and an image-sensitive text desensitization program stored in the memory and runnable on the processor. When the image-sensitive text desensitization program is executed by the processor, the steps of the image-sensitive text desensitization method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium, characterized in that The storage medium stores an image-sensitive text desensitization program, which, when executed by a processor, implements the steps of the image-sensitive text desensitization method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Image desensitization method and device, electronic equipment and storage medium
CN114758145A
Removing distracting objects from digital images
US20240171848A1