Image sensitive character desensitization method and device, equipment and medium
By introducing multi-scale feature fusion, spatial attention mechanism and self-attention mechanism in image processing, the problems of inaccurate detection of sensitive subtitles in the image are solved, accurate identification and natural repair of sensitive areas are achieved, and the security and usability of image content are improved.
Patent Information
- Application Number
- CN202510673103.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2025-06-24
- Estimated Expiration
- 2045-05-23
AI Technical Summary
In the prior art, when processing sensitive subtitles embedded in images, there is a problem that sensitive text detection is inaccurate and image repair after desensitization is unnatural.
Multiple feature maps are extracted through the residual convolution network, the input feature pyramid network is used for multi-scale fusion, and the spatial attention mechanism is fused to generate the optimized attention feature map. Based on the feature map, candidate area coordinates are generated, local images are extracted, text sequences are extracted using the self-attention mechanism, sensitive word detection is performed in combination with the semantic classification model, and local texture repair is 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 CN120198925A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of image processing, and particularly to an image-sensitive text desensitization method, device, equipment and storage medium. Background Art
[0002] With the acceleration of the digitalization process, images, as an important carrier for information dissemination, are widely used in multiple industries such as medical health, fintech, government services, and media dissemination. A large amount of image data often contains key textual information, especially sensitive content embedded in images in the form of subtitles, such as user identities, diagnostic information, transaction details, addresses, phone numbers, etc. If directly disclosed without processing, it is extremely likely to cause personal privacy leakage, data security incidents, and compliance risks.
[0003] In the field of medical and health services, image information such as electronic medical records, imaging reports, and prescription forms often embeds text information such as patient identities, 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 release. However, when faced with the characteristics of high-density layout, small font presentation, and complex background textures in medical images, subtitle detection is easily interfered, especially in images with irregular structures or partial occlusion, the performance of traditional object detection or edge detection-based solutions significantly deteriorates. In addition, during the image desensitization process, existing subtitle removal methods mainly rely on methods such as blurred filling and occlusion box covering. Although the operation is simple, obvious traces are easily left, affecting the integrity of the image, especially being unfavorable for subsequent clinical diagnosis or teaching research of medical images.
[0004] In the field of fintech services, in processes such as credit approval, insurance claims settlement, and risk control analysis, picture materials such as bill screenshots, contract photos, and on-site photo receipts are often collected and processed. These pictures may contain sensitive information embedded in the form of subtitles, such as customer names, bank card numbers, loan amounts, etc. Currently, the widely used subtitle detection methods mainly rely on image segmentation models based on convolutional neural networks (such as FCN) or object detection frameworks (such as YOLO, Faster RCNN) to locate the text areas in the picture. However, when dealing with images with small-sized subtitles, complex backgrounds, or compressed distortion, these methods have poor robustness and often have problems such as missed detection and misdetection of subtitle areas. Especially in financial data images with multi-scale small target subtitles, the accuracy is difficult to meet the 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 changes in images. In terms of image restoration, although the generative adversarial network (GAN) can improve the naturalness of the repaired area, the restoration effect on the occluded area of small target text is unstable, and it lacks 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 is prone to content misunderstanding or incomplete desensitization coverage.
[0006] In summary, the existing image sensitive subtitle detection and removal technology still has problems such as low detection accuracy, stiff restoration effect, and weak semantic understanding ability 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 mechanism, and semantic information to better meet the actual needs of the financial, medical and other industries 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 an image, aiming to solve the technical problems of the prior art 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: Extract multiple feature maps from the image to be processed through a 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 maps of each level, and performing element-by-element multiplication of the spatial weight map with the corresponding feature maps 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 candidate network; Mapping the candidate region coordinates to the image to be processed to determine a local image of the corresponding region; The local image is divided into pixel blocks, and the pixel blocks are input into a codec based on a self-attention mechanism after linear projection and position encoding to extract a text sequence; Inputting the text sequence into a semantic classification model to perform sensitive word detection and generate a sensitive word detection result; According to the sensitive word detection result, locally texture repair the sensitive area of the to-be-processed image to generate a desensitized image.
[0009] Furthermore, to achieve the above object, the present invention provides an image sensitive text desensitization device, including: A residual feature extraction module, configured to extract multiple feature maps from the to-be-processed image through a residual convolutional network; A multi-scale fusion module, configured to input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; A spatial attention enhancement module, configured to fuse a spatial attention mechanism in each level feature map of the pyramid features to generate a spatial weight map corresponding to each level feature map, and perform element-wise multiplication of the spatial weight map and the corresponding each level feature map to generate a corresponding optimized attention feature map; A candidate region generation module, configured to generate candidate region coordinates through a region proposal network based on the optimized attention feature map; A coordinate mapping and cropping module, configured to map the candidate region coordinates to the to-be-processed image to determine a local image of the corresponding region; A self-attention text extraction module, configured to divide the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on a self-attention mechanism after linear projection and position encoding processing to extract a text sequence; A sensitive word recognition module, configured to input the text sequence into a semantic classification model for sensitive word detection to generate a sensitive word detection result; A local image repair module, configured to locally texture repair the sensitive area of the to-be-processed image according to the sensitive word detection result to generate a desensitized image.
[0010] Furthermore, to achieve the above object, the present invention also provides a computer device, where the computer device includes a memory, a processor, and an image sensitive text desensitization program stored on the memory and executable on the processor, and when the image sensitive text desensitization program is executed by the processor, the steps of the image sensitive text desensitization method as described above are implemented.
[0011] Furthermore, to achieve the above object, the present invention also provides a computer-readable storage medium, where an image sensitive text desensitization program is stored on the storage medium, and when the image sensitive text desensitization program is executed by a processor, the steps of the image sensitive text desensitization method as described above are implemented.
[0012] 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. It discloses an image sensitive text desensitization method, including: extracting multiple feature maps from the image to be processed, inputting the multiple feature maps into a feature pyramid network to generate pyramid features with multi-level semantic fusion, fusing a spatial attention mechanism to enhance the response of sensitive regions in each level of feature maps, generating candidate region coordinates through a region proposal network, mapping the candidate region coordinates to the image to be processed to obtain a local image, using an encoder-decoder based on a self-attention mechanism to extract text semantic information in the local image, combining a semantic classification model to detect sensitive words, and performing a local texture repair operation on the sensitive region according to the detection result to generate a desensitized image. By introducing a spatial attention mechanism and a semantic understanding module on the basis of multi-scale feature fusion, the present invention improves the detection ability of small-size sensitive text in images, and through candidate region localization and a semantic-driven repair strategy, realizes the accurate identification and natural desensitization of sensitive regions, enhancing the security and usability of image content. Description of the Drawings
[0013] The following will further illustrate the present invention in conjunction with the drawings. In the drawings: Figure 1 It is a schematic diagram of an application environment of the image sensitive text desensitization method in an embodiment of the present invention; Figure 2 It is a schematic flowchart of an embodiment of the image sensitive text desensitization method of the present invention; Figure 3 It is a schematic diagram of the functional modules of a preferred embodiment of the image sensitive text desensitization device of the present invention; Figure 4 It is a schematic diagram of the structure of a computer device in an embodiment of the present invention; Figure 5 It is another schematic diagram of the structure of a computer device in an embodiment of the present invention. Detailed Embodiments
[0014] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0015] The image sensitive text desensitization method provided by the embodiments of the present invention can be applied in, for example Figure 1In the application environment, the client communicates with the server through the network. The server can extract multiple feature maps from the image to be processed through the client, input the multiple feature maps into a feature pyramid network to generate pyramid features with multi-level semantic fusion, fuse the spatial attention mechanism to enhance the response of sensitive regions in each level of feature maps, generate candidate region coordinates through a region candidate network, map the candidate region coordinates to the image to be processed to obtain a local image, extract text semantic information in the local image using an encoder-decoder based on the self-attention mechanism, combine a semantic classification model to detect sensitive words, and perform a local texture repair operation on the sensitive region according to the detection result to generate a desensitized image. By introducing a spatial attention mechanism and a semantic understanding module on the basis of multi-scale feature fusion, the present invention improves the detection ability of small-size sensitive text in images, and through candidate region localization and a semantic-driven repair strategy, realizes the accurate identification and natural desensitization of sensitive regions, enhancing the security and usability of image content. Among them, the client can be, but is not limited to, various personal computers, laptop computers, smart phones, tablet computers, and portable wearable devices. The server can be implemented by an independent server or a server cluster composed of multiple servers. The present invention will be described in detail below through specific embodiments.
[0016] Please refer to Figure 2 , Figure 2 which is a schematic flowchart of an embodiment of the method for desensitizing sensitive text in an image provided by the present invention. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than here.
[0017] As Figure 2 shown, the method for desensitizing sensitive text in an image proposed by the present invention includes the following steps: S10, extracting multiple feature maps from the image to be processed through a residual convolutional network; In this embodiment, during the desensitization process of sensitive information, image preprocessing is the precondition of the whole process, and its purpose is to perform preliminary structuring and standardization processing on the input image to provide more discriminative and stable input data for subsequent feature extraction and recognition tasks. The input images usually have diverse sources and uneven quality, and may have problems such as noise interference, complex colors, low contrast, or blurred fonts. If directly used for subsequent deep learning models, it is easy to cause unstable feature expressions, 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 more distinct visual boundaries.
[0018] During the preprocessing process, first, the input image is subjected to grayscale conversion, transforming the original multi-channel color image into a single-channel grayscale image. This conversion operation can remove color interference, retain only the luminance information, simplify the image content representation, and reduce the model's computational load. The acquisition of the grayscale image can be accomplished through methods such as weighted averaging, maximum value selection, or based on luminance distribution. Different strategies are applicable to different application scenarios.
[0019] Subsequently, binaryzation is performed on the grayscale image to further enhance the contrast between the target region and the background, and strengthen the separability of captions, characters, or other edge structures. Binaryzation can be achieved using fixed threshold methods, global adaptive algorithms (such as Otsu), or local adaptive methods (such as local window averaging). This processing can effectively highlight the structured regions and suppress the background complexity, which is a key step in text-like target extraction.
[0020] To remove low-level noise interferences such as isolated points, edge burrs, or scanning artifacts that may exist in the image, a noise elimination operation is introduced after binaryzation. This operation is usually performed based on means such as median filtering, morphological processing (such as erosion and dilation), and elimination of small connected components, aiming to optimize the image structure continuity and enhance the clarity of region boundaries.
[0021] Finally, to further enhance the structural distinctiveness and detail perceptibility of the image, contrast enhancement processing is performed. This step can be completed using methods such as histogram equalization, Gamma correction, or contrast stretching, which are used to expand the dynamic range of the image luminance values, enhance the gray-scale gradient difference between edges and fonts, thereby improving the recognition of character boundaries and the model extraction ability. After the above grayscale conversion, binaryzation, noise elimination, 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 for the subsequent residual network, which helps to improve the accuracy and robustness of sensitive region detection.
[0022] The essential goal of image caption desensitization is to achieve high-precision detection and natural and seamless reconstruction of sensitive information regions in the image. Therefore, in the initial stage of processing, it is necessary to extract as comprehensive and discriminative deep semantic features as possible from the image to be processed. 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, which further lays 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 convolutional processing, effectively avoiding the gradient vanishing and degradation problems in the training of deep networks and retaining the original information flow, which is conducive to the fusion of shallow features and deep features.
[0023] At different stages of the residual network, in order to obtain feature maps with decreasing resolution but enhanced semantics, a convolutional operation with a stride greater than 1 is introduced as a downsampling method. This operation replaces the traditional pooling structure, has the advantage of parameter learnability, and compresses the spatial dimension while maintaining semantic integrity, which is beneficial to constructing the multi-level feature maps required for the feature pyramid network. These feature maps respectively 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 proposal generation, and sensitive information recognition. By stacking multiple residual block structures layer by layer, the network can not only capture multi-scale semantics but also explicitly encode context dependencies in deep representations, enabling subtitles to be effectively distinguished and subsequently desensitized even when located in complex backgrounds.
[0024] To adapt to different image complexities and target subtitle scales, the depth and width of the residual network can be dynamically adjusted. For example, when facing high-resolution images or subtitles with small fonts, the network depth can be increased and the number of convolutional channels per layer can be increased to enhance the model's response ability to weak features. When dealing with low-contrast or blurred images, a shallower network structure can be preferentially selected, and a larger receptive field can be introduced in the convolutional kernel design (such as using a large 3×3 or 5×5 convolutional kernel) to obtain stronger global perception ability. 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 enhance the feature expression ability at the channel level and spatial level.
[0025] Example illustration: In the field of medical and health, for panoramic images of pathological sections (resolution approximately 200,000×100,000 pixels), a four-stage residual convolutional network is adopted, with each stage containing 4 residual blocks. The first-stage residual block uses a large 7×7 convolutional kernel with a stride of 4 to quickly compress the image size to 1 / 16, and the number of channels is increased to 64; in subsequent stages, the number of channels is gradually increased to 512, and at the same time, the resolution is reduced to 1 / 256 of the original size through a convolutional operation with a stride of 2. The channel attention module is enabled in the third and fourth stages to strengthen the feature response of the nucleus edge and blood vessel structure. This design enables the network to process million-pixel-level images on a GPU with 10GB of video memory, accurately extract the features of the tumor area, and support subsequent automatic annotation and quantitative analysis.
[0026] In the financial field, when processing scanned loan contract images (usually with a resolution of 300 dpi), a three-stage residual convolutional network is adopted. The input image undergoes a 3×3 convolution (stride 1) in the first stage to extract the basic texture, and the number of channels is maintained at 32 to reduce the computational complexity. In the second stage, a 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, a 1×1 convolution is used to compress the channels to 16 to generate a lightweight feature map. The channel attention module is only enabled in the second stage to focus on enhancing the channels of the signature area and the amount figures. This configuration enables real-time processing on embedded devices (such as bank intelligent terminals), with the feature extraction time for a single-frame image being less than 50 ms, and accurately separating the sensitive information area for desensitization processing.
[0027] In the satellite remote sensing monitoring scenario, for the surface cover classification task, the residual convolutional network adopts a five-stage structure. In the first two stages, standard convolutions are used to capture the outlines of roads and buildings, and in the last three stages, hybrid dilated convolutions (with dilation rates alternating between 2 and 4) are introduced to effectively identify the river flow direction and forest boundaries. The channel attention module strengthens the channels related to the vegetation index in the fourth stage and suppresses the noise in the cloud-covered areas. The feature extraction accuracy of this network on 4K resolution satellite images is improved by 12% compared to the traditional U-Net, and the inference speed is increased by 3 times, meeting the timeliness requirements of dynamic monitoring of land resources.
[0028] By adopting the residual convolutional network as the initial feature extraction structure, it is possible to fully integrate the shallow texture and edge information and the deep semantic and structural information, and alleviate the problem of information flow loss through skip connections, enabling the feature map extracted from the image to have a good gradient propagation path while maintaining high expression ability, providing rich underlying information expressions for subsequent multi-scale fusion and semantic recognition, and effectively improving the detection accuracy and positioning stability of sensitive caption areas.
[0029] S20, input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; In this embodiment, inputting multiple feature maps into a feature pyramid network for multi-scale fusion, the core lies in constructing a cross-level semantic information conduction path to overcome the limitations of single-scale feature maps in terms of spatial resolution or semantic abstraction. Multiple features Figure 1 generally come from the feature representations output by the previous-stage residual convolutional network at different stages. For example, when using ResNet as the basic network, the feature maps may correspond to different-depth levels such as C2, C3, C4, C5 in sequence, and the feature maps at each level have different spatial dimensions and semantic expression capabilities. High-resolution levels usually pay more attention to details such as edges, textures, and local contours, while low-resolution levels focus more on object-level semantic understanding.
[0030] To achieve multi-scale semantic fusion, first, multiple input feature maps need to be sorted in order according to their levels, and channel-wise normalization is performed on each feature map to ensure that information mismatch does not occur due to differences in the number of channels during the fusion process. Channel alignment is usually achieved through convolutional operations that set a unified output channel number. Common configurations include 1×1 convolutional kernels for compressing or expanding the number of channels, batch normalization for improving training stability, and non-linear activation for introducing the model's expressive ability. After that, a top-down feature path is constructed, starting from the feature map with the lowest resolution (strongest semantics), which does not need to be fused with other layers and can be directly used as one of the pyramid outputs.
[0031] When generating the pyramid features of the next level, upsampling processing in terms of spatial scale needs to be performed on the pyramid features that have been processed in the previous level to make their resolutions consistent with the horizontally connected feature maps of the current level. The upsampling process can be implemented in various ways, such as the most common bilinear interpolation method, deconvolution operation (learnable parameters), or sub-pixel reconstruction, etc. The specific choice can be determined by weighing the requirements for real-time performance and accuracy. The upsampled feature map and the horizontally connected feature map of the current level perform an element-wise addition fusion operation to form a multi-level information reconstruction feature. The fused result is further processed by a standard convolutional module to extract features, enhance its discrimination ability and representation ability, and at the same time play a role in smoothing the fusion boundary and removing multi-source feature noise.
[0032] This process is repeated from top to bottom until all levels are fused, thus forming multi-level pyramid features with unified semantic abstraction ability and retaining different spatial perception abilities. The multi-level pyramid features not only provide a multi-granularity input basis for subsequent attention weight generation and candidate region localization but also establish a stable collaborative path between spatial-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 an information guidance and alignment structure, possessing higher model interpretability and generalization ability.
[0033] During the actual deployment process, it also supports combination with lightweight structures. For example, the pyramid module can be designed as a prunable structure to adapt to the resource limitations of edge devices, or a dynamic channel adjustment mechanism can be introduced to reduce redundant feature conduction. In addition, to enhance the quality of cross-level information fusion, a guided attention mechanism, residual connection, or feature re-weighting module can be introduced in the upsampling path, thereby further improving the response ability to key regions in complex image structures. The construction of the entire pyramid structure has both clear hierarchical logic and flexible technical scalability, and is suitable for visual task scenarios that require multi-scale information integration.
[0034] 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 are retained, but also the global semantic expressions of the high-level feature maps are fused, effectively solving the detection difficulties brought by the uncertainty of the size, position, and structure of sensitive subtitles in the image, and enhancing the model's comprehensive perception ability and stability for sensitive regions of different scales.
[0035] S30, in each level of the feature map of the pyramid features, fuse the spatial attention mechanism to generate a spatial weight map corresponding to each level of the feature map, and perform element-wise multiplication of the spatial weight map and the corresponding feature maps of each level to generate the corresponding optimized attention feature map; In this embodiment, introducing the spatial attention mechanism into each level of the pyramid features aims to enhance the expression ability of the spatial position information in the feature map, enabling the model to pay more attention to the regions that are discriminative for the task objectives, 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, and its processing focus is on learning and generating a weight map consistent with the spatial distribution of the feature map, which depicts the importance degree of each spatial position.
[0036] In actual operation, the feature maps of each pyramid level are used as independent inputs and separately perform the fusion processing of the attention mechanism 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 max pooling operations need to be performed on each feature map separately in the channel dimension. Average pooling is used to model the global background response of the spatial region, while max pooling highlights the significant target response of the region. This combination method originates from the spatial modeling means in the general attention network and can fully retain different types of spatial information. After the pooling operations, two compressed feature maps with the same spatial size as the original feature map but with a channel number of 1 are obtained respectively.
[0037] Subsequently, the two compressed feature maps are concatenated along the channel dimension to generate an intermediate feature map with a two-dimensional channel of 2. This concatenation operation constitutes the input basis for spatial attention modeling. In order to extract the discriminative spatial dependence relationship from the concatenation result, the intermediate feature map is fed into a standard convolutional module. Usually, a convolutional kernel with a large receptive field (such as 7×7) is used to enhance the context modeling ability, and a non-linear activation function is used after convolution to enhance the expression ability. The convolutional output is a single-channel spatial response map, which is used to characterize the importance distribution of each spatial position.
[0038] To make the spatial response map have a normalization property, a Sigmoid activation function is usually introduced to map its numerical range to between 0 and 1, so as to ensure that the weight map can be interpreted as the saliency coefficient at each position. Finally, the normalized spatial weight map is multiplied element-wise with the original pyramid feature map at the corresponding level to achieve the enhancement of key regions and the suppression of non-key regions in the feature map. Since the attention response map is a single-channel structure, it is usually automatically expanded to the same number of channels as the original feature map through the broadcasting mechanism during the element-wise multiplication to ensure the dimensional consistency of the fusion calculation.
[0039] This way of attention enhancement has pluggability and structural flexibility. It can be applied as a module-level enhancement in the standard FPN pyramid structure or cooperate with the channel attention mechanism to form a more complete dual-branch attention path. Its advantage is that it can fully activate the spatially relevant regions in the image and has better response characteristics for images with uncertain target region sizes or blurred boundaries, especially suitable for processing fine-grained spatial regions such as image captions and locally sensitive texts. In addition, the optimized features generated after the independent attention modeling of feature maps at different levels can form spatial perception consistency at multiple scales when used in subsequent tasks such as candidate region localization and semantic judgment, enhancing the ability to separate sensitive information in complex backgrounds.
[0040] 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 adopted. First, the channel dimension is compressed respectively through global average pooling and global max pooling, retaining the average response and maximum response of each spatial position along the channel dimension. Then, the two feature maps are concatenated along the channel dimension to form a two-channel compressed representation. The concatenated intermediate feature map can be input into a single-layer convolutional network, and the kernel size of the convolutional layer can be set to 3×3, 5×5, or 7×7 to cover different ranges of receptive fields. If it needs to be deployed on edge devices or in resource-constrained environments, a lightweight convolutional structure of 3×3 can be selected and combined with ReLU activation or Swish activation to enhance the non-linear expression ability of the features.
[0041] After the convolution, a single-channel spatial weight map is generated. To make its value controllable and meet the normalization requirements of the attention mechanism, this map is mapped to between 0 and 1 through the Sigmoid function. To align with the original pyramid feature map, this spatial weight map is usually expanded to the same number of channels as the input feature map through the broadcasting mechanism, and then the element-wise multiplication operation is performed to achieve the weighted enhancement of the spatial dimension of the feature map. In a multi-layer pyramid structure, the above spatial attention fusion process can be independently executed at each level to ensure effective spatial attention can be obtained at different resolutions.
[0042] In addition, a lightweight attention model such as the spatial module in CBAM (Convolutional Block Attention Module) can be used to replace the above structure to further compress the number of parameters. Position encoding can also be introduced into the spatial weight map to endow it with relative or absolute spatial position information, enhancing the ability to locate sensitive regions. In special scenarios, such as when the input image contains specific occlusions, edge interferences, etc., a structure mask can be pre-constructed as an attention constraint and fused with the spatial weight map to guide the model to focus more on the core region.
[0043] Example illustration: In the field of healthcare, electronic medical records, medical images, or case-taking images often contain patient privacy information, such as names, ID numbers, diagnosis conclusions, etc. These information usually appear in small fonts in the corner or edge area of the image. By integrating the spatial attention mechanism into the pyramid feature map, these spatial regions can be precisely focused on, and the irrelevant background in the image, such as medical equipment, rulers, or image watermarks, can be suppressed, so as to more accurately identify and extract the regions containing sensitive information, providing a basis for subsequent removal and repair.
[0044] In the field of fintech, bank card photos, invoice images, contract scans, etc. often contain account information, transaction details, or customer identification codes embedded in small areas. These information have non-fixed positions and non-uniform fonts. Introducing the spatial attention mechanism into the pyramid feature map can enhance the model's response ability to these key regions. Even if they are in the corners or low-resolution levels of the image, high positioning accuracy can be maintained, thus effectively supporting the intelligent identification and clearing of financial privacy content.
[0045] In the scenario of social platform image content supervision, the screenshots, photos, and composite images uploaded by users may contain subtitle content such as abusive words and sensitive remarks. The introduction of the spatial attention mechanism can enhance the recognition ability of text-dense regions, and cooperate with context-aware features to further strengthen the model's judgment ability for sensitive regions, improving the accuracy and practicality of the violation content detection system.
[0046] By introducing the spatial attention mechanism into the feature maps of each level of the pyramid features, the model's perception ability for the target region can be significantly improved. This mechanism extracts spatial responses by compressing channel information, generates an attention map that can reflect the spatial saliency distribution, and uses this map to weight the original features element by element, realizing the explicit enhancement of features and the suppression of redundant regions. In this way, the feature maps of each pyramid level further enhance the response intensity to the key regions while retaining the original semantic hierarchical structure, thus improving the extraction quality of candidate regions, providing a more accurate spatial basis for subsequent tasks such as sensitive word detection and image repair. Ultimately, it realizes the improvement of the accuracy and robustness of small target subtitle detection, especially performing better in complex background or weak boundary text scenarios.
[0047] S40. Generate candidate region coordinates through a region proposal network based on the optimized attention feature map. In this embodiment, the optimized attention feature map is a feature map obtained by introducing a spatial attention mechanism into the multi-scale pyramid feature map. It not only retains the semantic hierarchical information at different resolutions but also enhances the response ability to the target region. Based on this type of feature map, the generation of target candidate regions can be performed more precisely. The region proposal network is a mechanism developed from object detection and is commonly used to quickly generate candidate boxes with high confidence on the feature map. It predicts the regions where objects may exist at each spatial position of the feature map and estimates the position offsets and object scores of each candidate region.
[0048] In this process, first, multiple predefined anchor boxes are generated for each spatial position in the optimized attention feature map. An anchor box refers to setting multiple rectangular boxes with preset aspect ratios and scales at each pixel position of the feature map. Common scales include pixel levels such as 32, 64, 128, 256, etc., and the aspect ratios can be set to combinations such as 1:1, 1:2, 2:1, etc. The purpose of setting multiple anchor boxes is to cover target regions of different shapes, sizes, and aspect ratios and improve the probability of matching sensitive subtitle regions. The generation of anchor boxes does not depend on a specific image but structurally acts on the feature map itself.
[0049] Subsequently, a convolutional operation is performed on the optimized attention feature map to form a sliding window prediction module. Each sliding window extracts the local features of the current anchor box region and predicts two pieces of information: one is the classification score of each anchor box, used to determine whether the region contains potential subtitle-sensitive information; the other is the regression offset, including the fine-tuning parameters for the center point position and width and height. These offset parameters are used to finely adjust the anchor boxes to more precisely fit the true subtitle boundaries.
[0050] After obtaining the predicted offsets and confidence scores of the anchor boxes, all anchor boxes need to be subjected to candidate screening processing. They are sorted by the confidence scores, and the top several high-score anchor boxes (such as the top 300) are selected. Then, the non-maximum suppression method is used to filter them to remove redundant candidate boxes with too high overlap. The process of non-maximum suppression is based on the intersection over union calculation. When the intersection over union of two candidate boxes is greater than a set threshold (such as 0.7), only the one with a higher score is retained to ensure that the final candidate regions are evenly distributed and have clear boundaries.
[0051] 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 aligned with the original image space through a mapping operation later, serving as the basis for further sensitive region localization, text analysis, and repair.
[0052] In actual deployment, the regional candidate network can be implemented based on various deep learning structures. For example, the classic Region Proposal Network (RPN) can be adopted as the core component, and its structure includes three parts: a shared feature extraction layer, a small convolution prediction layer, and a classification and regression branch. The shared layer uses 3×3 convolution to extract context local information, and then outputs the classification score and bounding box regression offset of each anchor box through two parallel 1×1 convolution layers respectively.
[0053] 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 volume; in multi-task joint detection tasks, the RPN can also be feature-fused with the backbone network to introduce upper-layer semantics in advance to assist in generating candidate regions.
[0054] In addition, the Anchor-free idea can be introduced, abandoning the preset of anchor boxes, and instead directly regressing the key point coordinates and regional boundaries in the feature map to improve the positioning ability in sensitive subtitle regions such as complex deformations and oblique texts.
[0055] Parameters such as the intersection-over-union threshold, the number of candidate box filtrations, and the anchor box size ratio can be flexibly adjusted according to the requirements of different scenarios. For example, in high-resolution image processing scenarios, the density of anchor box scales can be increased to improve the coverage rate; in small-sized input images, the number of candidate regions can be reduced to avoid false alarms.
[0056] By constructing a regional candidate network based on the optimized attention feature map, the perception ability of subtitle regions is enhanced on the basis of multi-scale semantic features, and at the same time, the accuracy of regional positioning is strengthened by means of the spatial attention mechanism. The regional candidate network constructed on this basis can quickly filter out candidate regions with high confidence, and further improve the accuracy and independence of candidate boxes through the bounding box regression and non-maximum suppression mechanisms, significantly improving the detection success rate of subtitle-sensitive regions. It has higher positioning efficiency and scalability, and can achieve high-quality candidate region extraction in complex scenarios, low-contrast backgrounds or small text regions, providing a structured and high-precision input basis for subsequent semantic detection and image restoration.
[0057] S50, map the coordinates of the candidate region to the image to be processed, and determine the local image of the corresponding region; In this embodiment, the coordinates of the candidate regions 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 regions identified on the optimized attention feature map. However, there is a downsampling ratio difference between this feature map and the original input image. Therefore, if we need to accurately extract the corresponding regions in the original image, we must map the feature map coordinates 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 regions in the original image space, providing an accurate positioning basis for subsequent image analysis or restoration tasks.
[0058] In terms of specific implementation, the feature map usually undergoes scale reduction compared to the original image due to operations such as convolution and pooling, and this reduction ratio is determined by the downsampling stride in the feature pyramid network. For example, if the stride is 16, then one pixel point on the feature map corresponds to a 16×16 region in the original image. When performing coordinate mapping, the abscissa of the center point of the candidate box can be obtained by multiplying the abscissa of the center point in the feature map by the downsampling stride and adding half of the stride for center compensation. The ordinate mapping method is the same. The mapping of width and height is relatively simple. We can directly multiply the width and height of the candidate region by the downsampling stride to restore them to the scale of the original image.
[0059] After completing the basic mapping, boundary constraint processing needs to be performed. Since some candidate boxes may be located at the edge of the feature map, their mapped center coordinates or sizes may exceed the boundaries of the original image. Therefore, it is necessary to limit the abscissa and ordinate of the center point to be not less than zero and not exceed the width and height of the image. At the same time, the upper, lower, left, and right boundary coordinates need to be calculated based on the center point and size of the candidate box, and the actual width and height are further adjusted to be the difference between the right boundary and the left boundary, and the difference between the lower boundary and the upper boundary, so as to ensure that the cropped region is complete and usable.
[0060] Finally, based on the mapped center coordinates and the adjusted width and height information, a rectangular region can be directly cropped from the original image to be processed to obtain the corresponding local image. This region corresponds one-to-one with the candidate region in space and is the suspected sensitive region to be analyzed semantically.
[0061] In actual implementation, the downsampling factors between the output feature maps of each layer of the Feature Pyramid Network and the input image can be recorded first, and the coordinates of the output anchor boxes of the Region Proposal Network can be inversely scaled according to this factor. In the multi-scale pyramid structure, the stride of each layer of the feature map is different. Therefore, the corresponding mapping coefficient needs to be dynamically selected according to the level from which the candidate region is sourced. During the mapping process, the coordinate cropping function provided by an image processing library (such as OpenCV or PIL) can be combined to convert the mapped coordinates into the cropping region of the image. Bilinear interpolation or region copying and other interpolation algorithms can be used during cropping to improve the pixel continuity at the cropping boundary. In terms of the boundary control strategy, the boundary upper limit can be dynamically set according to the size of the original image, and symmetric filling or edge cropping can be performed when the candidate region exceeds the boundary. For example, if the abscissa is widened and exceeds the image width, the right boundary can be set to the maximum value of the image width, and the width can be reduced while keeping 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 tile is obtained. In addition, the mapping information of the candidate region 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 processes.
[0062] By mapping the candidate region coordinates from the feature map space to the original image space, the problem of inconsistent coordinate systems in the object detection task is solved, enabling the model to accurately extract suspected sensitive regions in the image. This operation ensures that subsequent image analysis, text recognition, or texture repair operations are all performed based on the correct and accurate image positions, avoiding problems such as desensitization failure, incorrect cropping, or semantic deviation caused by coordinate errors. Through the mapping mechanism, coordinate conversion and boundary alignment are achieved, making the entire desensitization process consistent in spatial semantics and enhancing the overall stability and accuracy of the system.
[0063] S60, segment the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on the self-attention mechanism after linear projection and position encoding processing to extract a text sequence; In this embodiment, the local image is usually a sub-region cropped from the original image. Its size is not fixed, the texture structure is complex, and it may contain fine-grained sensitive subtitle information. To achieve in-depth understanding and accurate extraction of potential text information in this region, the image region needs to be first converted from a two-dimensional pixel representation to a serialized representation suitable for the language modeling structure. The first step of this process is to segment the image into pixel blocks, that is, to divide the entire local image into several small-sized rectangular regions, usually called patches. In the standard Vision Transformer architecture, these patch sizes are fixed, such as 16×16 or 32×32, and are extracted in a non-overlapping sliding window manner across the entire image, thus forming a set of tiled image units.
[0064] Each image patch is then regarded as an input token, which needs to be further projected into a unified embedding space through linear projection. Linear projection is usually accomplished by a fully connected layer, which converts the high-dimensional representation of the original pixel patch (such as the vector flattened after splicing the three RGB channels) into a low-dimensional embedding vector, while preserving local texture information and compressing the dimensions. In addition, to preserve the spatial arrangement order between patches in the image, positional encoding needs to be added. The positional encoding can adopt a fixed trigonometric function encoding method or a trainable vector encoding method to introduce the position perception ability of each patch in the image.
[0065] After completing the linear projection and positional encoding, the sequence composed of all patch embedding vectors is fed into an encoder-decoder structure based on the self-attention mechanism. The encoder models the global dependencies between patches through multi-head self-attention layers to enhance the model's context awareness; the decoder part further converts the encoded results into a sequence of interpretable text symbols. This structure breaks through the limitation of the local receptive field of traditional CNNs, enabling the model to identify and interpret the sensitive text information hidden in local images from a global perspective, providing a basis for subsequent semantic detection.
[0066] In one of the specific implementation manners, the local image is first normalized to a unified size (such as 224×224), and then non-overlappingly divided into windows of 16×16 to obtain 196 pixel patches. Each pixel patch forms a 768-dimensional vector after channel flattening, which serves as the input of the linear projection layer, and outputs a 128-dimensional embedding vector. All the embedding vectors form a sequence of length 196, and are added to the positional encoding vectors to form the input sequence. The positional encoding can be implemented using the sine-cosine function method, where each dimension is encoded with a different frequency to ensure that the model has the ability to distinguish relative and absolute positions. It is also possible to use a trainable positional embedding matrix to automatically learn the semantic mapping of spatial position information during the training process. The encoder structure includes several layers of Transformer blocks, each layer containing a multi-head attention mechanism and a feed-forward network. The number of attention heads, the embedding dimension, and the hidden layer size can be adjusted according to the computing power conditions (such as 8 heads and 256 hidden layers). The decoder structure is similar to the encoder, and a masking mechanism can be additionally introduced to enable the decoder stage to maintain the ability to predict the output information sequence step by step, thus facilitating the positioning of the position and type of the caption text. In addition, to improve the recognition efficiency, a pre-trained model (such as ViT or Swin Transformer) can be introduced for transfer learning to shorten the training time and improve the accuracy.
[0067] By converting the image region into a sequence of pixel blocks and introducing a modeling method based on the self-attention mechanism, the problem of insufficient local recognition ability of traditional convolutional models in scenarios with long texts, complex backgrounds, or spatial deformations is effectively solved. Through linear projection and position encoding processing, the model obtains stronger structural expression ability and spatial context awareness ability, enabling it to accurately extract the text semantic sequence from unstructured images. The recognition rate and fault tolerance of sensitive captions are improved, and it shows stronger robustness especially in scenarios with character distortion, occlusion, or low contrast.
[0068] S70, input the text sequence into a semantic classification model for sensitive word detection, and generate a sensitive word detection result; In this embodiment, the text sequence generated by the image encoding module is essentially a semantic representation of the potential text content in the local image region. This text sequence may contain captions, labels, seal information, etc., and has characteristics such as unstable semantic structure and weak context association. It needs to be further semantically discriminated by a semantic classification model to identify whether it contains sensitive words or confidential content.
[0069] After the text sequence is input into the semantic classification model, it is first processed by an embedding layer to map discrete text tokens into high-dimensional semantic vectors. Subsequently, the sequence is fed into a deep Transformer structure stacked by multiple encoders. The Transformer encoder has a multi-head self-attention mechanism, which can capture the context dependence between texts at different positions and construct a global semantic representation. In this structure, by increasing the number of encoder layers, the model's ability to model the semantic relationship of long texts and its understanding ability of complex language structures are improved, avoiding semantic misjudgment of sentences or ambiguity of polysemous words caused by shallow networks.
[0070] Finally, after aggregating the representations of all tokens through a pooling layer or a CLS token, it enters a fully connected classification layer to output a class probability distribution, indicating whether the current text sequence contains sensitive words and which category of sensitive information it belongs to (such as ID number, phone number, medical term, organization name, etc.). To further improve the generalization ability, regularization methods such as dropout or residual connection structures can be combined to prevent overfitting during the training phase.
[0071] In addition, the category system of sensitive words can be configured through a predefined sensitive word dictionary, compliance standards, or business rules, and different categories can be refined at the model output end, thus supporting more interpretable recognition output.
[0072] In one specific embodiment, the text sequence is first encoded into a token sequence and then fed into the semantic classification module. This module can be constructed based on pre-trained language models such as BERT, RoBERTa, or DeBERTa, and the number of encoder layers is selected as 12 or 24 layers according to the task complexity. Increasing the number of encoder layers enables the model to construct semantic information at a deeper abstract level, especially suitable for processing scenarios with interference, occlusion, or multilingual subtitles. For model training, a dual-loss structure can be adopted to simultaneously optimize the discrimination of the presence or absence of sensitive words and the classification of specific categories, improving the detection accuracy. The training data can be constructed through manually annotated subtitle images or synthetic data, covering various types and contexts of sensitive words. In the inference stage, after the text sequence is input into the model, a vector containing sensitive probabilities and categories is output, such as [no sensitivity, medical term, personal identifier, organizational information], and the one with the highest probability is the determination result of the current local image text. The model output result is used to drive the subsequent image repair module to perform targeted covering and reconstruction operations. To improve the 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.
[0073] By inputting the text sequence converted from the image region into a multi-layer semantic classification model for sensitive word detection, accurate recognition of hidden sensitive words can be achieved in complex graphic and text structures. By increasing the number of encoder layers to strengthen the semantic abstraction ability of the model, it can capture the context dependencies and semantic ambiguities in long texts, significantly improving the recognition robustness in noisy environments or polysemous scenarios, and solving the problem of insufficient recognition ability of traditional shallow networks for sensitive content in small characters and weak contexts.
[0074] S80, according to the sensitive word detection result, perform local texture repair on the sensitive area of the image to be processed to generate a desensitized image.
[0075] 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 subsequent repair quality. Therefore, it is first necessary to screen high-probability areas through a threshold mechanism and expand and standardize their spatial boundaries by combining morphological operations. The generation of the mask can adopt the closing operation in image morphology. Through a sequence of operations of dilation first and then erosion, 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, and its boundary not only defines the repair range but also determines the semantic boundary of the repair texture to a certain extent.
[0076] Local texture repair is premised on the context consistency of the image. The goal is to fill in the missing image pixels in the masked area while maintaining the continuity with the surrounding structures, colors, and textures. Feature extraction operations need to be performed before repair. A multi-scale convolutional module is used to extract image information such as local details, regional associations, and global layouts at different receptive field ranges. Convolution kernel sizes such as 3×3, 5×5, and 7×7 correspond to the process from fine-grained texture modeling to large-scale structure understanding. This structural design facilitates the accurate restoration of the background content occluded by the text area in the image repair task. By concatenating feature maps of each scale in the channel dimension and performing dimensional compression through 1×1 convolution, a context-aware feature that fuses different semantic granularities can be constructed.
[0077] The fused features are further input into the self-attention module to model the non-local dependence relationship between features in terms of pixels. The implementation of the attention mechanism is based on the scaled dot-product attention structure. The core lies in generating a weighted image representation through the dot product and normalization operations among the three vector matrices of keys, values, and queries. This process can dynamically adjust the dependence degree of each pixel on other regions of the entire image. Multiple attention heads are modeled in parallel, enabling the model to simultaneously perceive semantic cues in different directions and scales on multiple semantic channels, thereby strengthening semantic consistency and spatial coherence.
[0078] The repair network usually adopts an encoder-decoder architecture. The generator is responsible for generating candidate textures for the desensitized area, and the discriminator is responsible for judging whether the textures are natural and credible. The encoder can select a residual structure to enhance the feature retention ability and improve the model's abstraction ability for spatial structures and context information by stacking residual blocks. The decoder restores the original image resolution through transposed convolution and introduces skip connections from the encoder at each upsampling stage to ensure spatial alignment and guide texture reconstruction. The attention module can be embedded in the skip connection path to further improve the synthesis quality of key regions. The discriminator adopts a multi-scale Patch discrimination method to evaluate the authenticity of the generated content from different scale regions of the image, ensuring that the synthesized textures conform to the real image distribution both locally and globally.
[0079] The fusion between the finally generated image and the original image adopts the Poisson fusion mechanism. Its core idea is to use the image gradient field as a constraint to solve the optimal intensity value of each pixel in the generated area, thereby achieving a natural transition within the transition zone. The fusion process takes the mask boundary as the center, establishes a gradient continuity equation in the inner and outer edge regions, and optimizes each pixel value through a sparse linear solution method, enabling the repaired texture to be seamlessly embedded in the original image and avoiding edge abruptness.
[0080] On the premise of unchanged basic structure, local texture repair can be differentially implemented based on different generation strategies and fusion methods. In terms of feature extraction, multi-scale convolution can be replaced with a pyramid convolution structure or a dilated convolution module to adapt to the context awareness requirements of input images with different resolutions. In the attention mechanism part, the standard multi-head self-attention can also be replaced with sparse attention or local window attention mechanisms to reduce the computational complexity and enhance the local information modeling ability. The generator architecture can adopt a Transformer structure to replace the convolutional U-Net, especially having a better long-range dependence modeling ability in the high-resolution sensitive area repair task. In the discriminator structure, in addition to the multi-scale Patch discriminator, a frequency domain discriminator or a discriminator based on a graph model can also be introduced to strengthen the recognition ability of periodic structures or complex patterns in the generated texture. During the Poisson fusion process, different gradient solving strategies, such as a fast Poisson solver, a weighted Laplacian balancer, etc., can be adopted to achieve a trade-off between fusion efficiency and boundary quality. In some specific scenarios, such as applications in medical images that are highly sensitive to edge structures, a guided graph fusion mechanism can also be used to use the known edge structures in the image as a gradient direction reference to ensure boundary continuity.
[0081] Example Illustration: In the scenario of medical and health data management, when a certain 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 local and global areas, making the text areas show stronger responses on the feature maps. Based on the optimized attention feature maps, 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 original CT image coordinates through the downsampling step of the pyramid network and crops out local image regions through boundary correction and size constraints. The system divides each local image into pixel blocks, and after linear projection and position encoding, it is sent into a self-attention encoder-decoder to extract sequence features, and then input 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 area mask is generated, and the surrounding boundaries of the sensitive text are expanded using morphological operations, and then the target area is cropped out. This area undergoes multi-scale convolution and self-attention processing to generate context-aware features, which are sent into a repair network composed of stacked residual convolution and dilated convolution to generate a new image area without sensitive words. Finally, the system uses Poisson fusion to naturally fit the repaired area back to the original image to generate a desensitized image, ensuring texture continuity, smooth edges, and no obvious repair marks.
[0082] In financial operations, when enterprises process imaging materials such as loan contracts, insurance policy scans, bank statements, and customer risk assessment documents, they often contain a large amount of sensitive information, such as customer names, ID numbers, account information, credit ratings, and fund flows. These information are often embedded in images in the form of text or small tables. To achieve automated desensitization, before the information is uploaded to the cloud or disclosed externally, it is necessary to build an image sensitive subtitle removal mechanism with high accuracy, strong controllability, and good visual consistency.
[0083] The system first receives scanned financial contract images, which may contain complex backgrounds such as anti-counterfeiting textures, watermarks, red official seals, etc. It is difficult to ensure desensitization accuracy and visual restoration by directly using traditional OCR or image filtering methods. The system first preprocesses the images, performing operations such as grayscale conversion, binarization, noise elimination, and contrast enhancement to generate the to-be-processed images with improved clarity, so as to suppress the interference of the image background and enhance the text edge features. The images are fed into a residual convolutional network to extract multi-scale feature maps. The initial convolutional layer of the network extracts basic edge features, the stacked residual blocks extract complex structures, the skip connections retain details, and at the same time, the channel attention module adjusts the weights of each channel to enhance the sensitivity to targets such as numbers and text lines. For example, for the area containing the bank account number "6222**********", the system can amplify the response intensity of the channels of the slender handwriting.
[0084] The extracted multi-scale feature maps enter the Feature Pyramid Network for fusion. The high-level feature maps focus on the global contours of the official seals and signatures, and the low-level feature maps focus on the edge segments of the ID numbers and the opening bank. Through operations such as channel unification, lateral connection, and top-down upsampling fusion, pyramid features with multi-scale semantic expressions are formed. Subsequently, the system applies a spatial attention mechanism to each pyramid level, constructs an attention response map through global average pooling and max pooling, and then multiplies it element-wise with the original feature map to further enhance the response of the sensitive text areas (such as fields like "ID card" and "customer number"), and suppress the background textures and watermarks.
[0085] On the optimized attention feature maps, the Region Proposal Network generates anchor boxes of multiple scales and ratios, predicts the class scores and position offsets of the anchor boxes through a sliding window, retains the high-score regions, and eliminates the redundant candidate boxes with too high overlap through non-maximum suppression. The mapping module obtains the downsampling stride of the FPN, maps the center points and widths and heights of these candidate boxes to the original image coordinate space, and performs cropping in combination with boundary constraints to ensure that the generated local images are complete and do not cross the boundaries, retaining valid information such as the customer signature area.
[0086] The system divides the cropped local images into pixel blocks, feeds them into the Transformer encoder-decoder structure with self-attention mechanism to extract sequence features, and then judges whether they contain sensitive words through a semantic classification model. For example, when identifying high-confidence fields such as "loan amount", "credit period", and "guarantor", the system records their position information and outputs the sensitive word detection results.
[0087] For the image segments determined to be sensitive areas, the system performs local texture repair. First, a mask is generated, and the entire sensitive text area is wrapped using the closing operation; then, context and detail features at different scales are extracted through 3×3, 5×5, and 7×7 convolution kernels. The self-attention mechanism models the spatial correlation to strengthen the consistency of the contract border, reconciliation grid, and background. The context features enter the repair network, and the U-Net structure is used to fuse the attention features in the skip connections, and finally, an image of the sensitive area after content filling is generated, maintaining visual consistency and the integrity of the contract structure.
[0088] The Poisson fusion module guides the seamless fusion of the sensitive area and the original image edge in terms of illumination, texture, handwriting thickness, etc. according to the gradient of the repair area. For example, in the area where "loan amount" is replaced, it can maintain the same line spacing as the adjacent contract, without affecting the subsequent review by business personnel. Finally, the system outputs a desensitized image with the same size as the original image, the sensitive text is accurately deleted and replaced, the background texture is restored without damage, and the contract format remains unchanged, and it can be archived, displayed, or transmitted without manual verification.
[0089] Through the above steps, accurate repair of sensitive areas can be achieved at the spatial, semantic, and texture levels, ensuring that there are no obvious artificial traces in the visual level of the desensitized image. The entire process combines strong constraints and high freedom from position recognition to texture synthesis, retaining the overall image while effectively shielding sensitive information, and improving the usability and compliance of the desensitized image.
[0090] The present invention relates to the technical field of image processing and can be applied to business scenarios such as medical health and fintech. It discloses an image sensitive text desensitization method, including: extracting multiple feature maps from the image to be processed, inputting the multiple feature maps into a feature pyramid network to generate pyramid features with multi-level semantic fusion, fusing a spatial attention mechanism to enhance the response of sensitive areas in each level of feature maps, generating candidate region coordinates through a region candidate network, mapping the candidate region coordinates to the image to be processed to obtain a local image, using an encoder-decoder based on the self-attention mechanism to extract text semantic information in the local image, combining a semantic classification model to detect sensitive words, and performing local texture repair operations on the sensitive areas according to the detection results to generate a desensitized image. The present invention improves the detection ability of small-size sensitive text in images by introducing a spatial attention mechanism and a semantic understanding module on the basis of multi-scale feature fusion, and realizes the accurate identification and natural desensitization of sensitive areas through candidate region positioning and semantic-driven repair strategies, enhancing the security and usability of image content.
[0091] In one embodiment, the above step S20 includes: S201, inputting the multiple feature maps into a feature pyramid network, and the multiple feature maps are arranged in a hierarchical order from high resolution to low resolution; S202. Perform lateral connection processing on the feature maps of each level through the feature pyramid network, and unify the channel dimensions of the feature maps of each level through convolution operations respectively to generate corresponding laterally connected feature maps; S203. Construct a top-down path through the feature pyramid network, perform convolution operations on the laterally connected feature maps of the lowest level to generate pyramid features corresponding to the lowest level; S204. Starting from the second lowest level, in the order of increasing resolution, perform upsampling operations on the pyramid features generated in the previous level, and perform element-wise addition fusion on the upsampled pyramid features and the laterally connected feature maps of the current level, and perform convolution operations on the fusion result to generate pyramid features corresponding to the current level; S205. The pyramid features corresponding to all levels constitute the pyramid features of the multi-level semantic fusion.
[0092] In this embodiment, the purpose of inputting multiple feature maps into the feature pyramid network for multi-scale fusion is to integrate semantic information and detailed features at different levels to form a multi-level expression that takes into account both the global and local aspects. The feature maps are arranged in descending order of resolution. High-level feature maps (such as the output of the 5th stage) contain rich semantic information but lack spatial details, while low-level feature maps (such as the output of the 2nd stage) retain fine textures but have low semantic abstraction. Lateral connection processing performs 1×1 convolution operations on the feature maps of each level to unify the number of channels to a preset dimension (usually 256 channels), eliminate the channel differences of cross-level feature maps, and ensure the compatibility of subsequent fusion. For example, in medical image processing, the 1024-channel feature map of the 5th stage is compressed to 256 channels through 1×1 convolution and aligned with the 256-channel feature map of the 2nd stage to facilitate cross-level information interaction.
[0093] The top-down path starts from the laterally connected feature maps of the deepest layer (lowest resolution). The feature expression can be optimized through 3×3 convolution to generate initial pyramid features. This convolution operation eliminates the noise introduced by channel compression and enhances semantic consistency. For example, in satellite images, after the 3×3 convolution of the feature maps of the lowest level, the topological structure of the road network becomes clearer. Subsequently, starting from the second deepest level, the pyramid features generated in the previous level are upsampled by a factor of 2 (usually using bilinear interpolation) to restore the resolution of the current level. The upsampled feature maps are added element-wise to the laterally connected feature maps of the current level to achieve the fusion of high-level semantics and low-level details. The fusion result is further optimized through 3×3 convolution to eliminate the edge blurring caused by upsampling and enhance feature consistency. In financial bill processing, after adding the semantic features (such as table frame lines) of the 4th level and the detailed features (such as handwritten notes) of the 3rd level, the 3×3 convolution can accurately separate overlapping characters and table lines.
[0094] The construction of multi-level pyramid features forms a hierarchical feature expression system. The pyramid features at the highest resolution level (e.g., the 2nd layer) are suitable for detecting tiny objects (such as microcalcifications in medical images), the middle levels (e.g., the 3rd - 4th layers) are suitable for medium-scale objects (such as signature areas in financial documents), and the lowest level (e.g., the 5th layer) is suitable for large-scale objects (such as building complexes in satellite images). The features at each level are strictly aligned in terms of the number of channels and spatial resolution, supporting parallel multi-scale object detection and segmentation.
[0095] Example illustration: Suppose a residual convolutional network extracts feature maps of 5 levels from a 512×512 abdominal CT scan image, arranged from the highest to the lowest resolution as follows: Layer C1: Resolution 512×512 (1 / 2 downsampling), 64 channels, capturing the fine texture of the original image (such as the boundary between subcutaneous fat and muscle); Layer C2: Resolution 256×256 (1 / 4 downsampling), 256 channels, identifying blood vessel branches and microcalcifications; Layer C3: Resolution 128×128 (1 / 8 downsampling), 512 channels, locating the edge and internal structure of the liver organ; Layer C4: Resolution 64×64 (1 / 16 downsampling), 1024 channels, encoding the morphological features of the tumor region; Layer C5: Resolution 32×32 (1 / 32 downsampling), 2048 channels, representing the semantic associations of the whole body's anatomical structure.
[0096] The feature maps of each level are unified to 256 dimensions through 1×1 convolution: Layer C1: 64 channels → 256 channels, outputting a 512×512 horizontal feature map; Layer C2: 256 channels → 256 channels, outputting a 256×256 horizontal feature map; Layer C3: 512 channels → 256 channels, outputting a 128×128 horizontal feature map; Layer C4: 1024 channels → 256 channels, outputting a 64×64 horizontal feature map; Layer C5: 2048 channels → 256 channels, outputting a 32×32 horizontal feature map.
[0097] The process of constructing the top-down path includes: Generating the lowest-level pyramid feature (P5): Input: C5 horizontal feature map (32×32, 256 channels); Operation: 3×3 convolution to optimize semantic features; Output: P5 pyramid feature (32×32, 256 channels), marking potential tumor regions throughout the body.
[0098] Generate P4 pyramid features: Input: The P5 feature map (32×32) is upsampled by bilinear interpolation by a factor of 2 to 64×64; Fusion: Element-wise addition with the C4 lateral feature map (64×64); Optimization: A 3×3 convolution to eliminate fusion noise; Output: P4 pyramid features (64×64, 256 channels), refining the tumor boundary.
[0099] Generate P3 pyramid features: Input: The P4 feature map (64×64) is upsampled to 128×128; Fusion: Addition with the C3 lateral feature map (128×128); Optimization: A 3×3 convolution to enhance feature consistency; Output: P3 pyramid features (128×128, 256 channels), separating the tumor from healthy tissue.
[0100] Generate P2 pyramid features: Input: The P3 feature map (128×128) is upsampled to 256×256; Fusion: Addition with the C2 lateral feature map (256×256); Optimization: A 3×3 convolution to capture microcalcification points; Output: P2 pyramid features (256×256, 256 channels), localizing the details of vascular invasion.
[0101] Generate P1 pyramid features (optional): Input: The P2 feature map (256×256) is upsampled to 512×512; Fusion: Addition with the C1 lateral feature map (512×512); Optimization: A 3×3 convolution to restore high-resolution details; Output: P1 pyramid features (512×512, 256 channels), enhancing the contrast of subcutaneous tissue.
[0102] Then, the multi-level pyramid features obtained after the above process include: P1: 512×512 resolution, used to visualize micro-nodules (<1mm) in the subcutaneous fat layer; P2: 256×256 resolution, detecting calcification points on the blood vessel wall to assist in judging tumor blood supply; P3: 128×128 resolution, segmenting the core of the liver tumor from the surrounding tissue and quantifying the proportion of the necrotic area; P4: 64×64 resolution, measuring the maximum diameter (long diameter / short diameter) of the tumor for TNM staging; P5: 32×32 resolution, analyze the whole-body tumor distribution, and evaluate the metastasis risk.
[0103] For example, in a 512×512 CT image: Layer P5 marks the right lobe of the liver as a high-risk area (probability > 90%); Layer P4 refines the tumor boundary to 3.2 cm × 4.1 cm with an error < 0.5 mm; Layer P3 segments the tumor core (CT value +85 HU) and the surrounding edema zone (+40 HU); Layer P2 detects 12 microcalcification points (diameter 0.3 - 0.8 mm), and 8 are missed by traditional methods; Layer P1 enhances the display of 3 subcutaneous micro-nodules, which are confirmed as early metastasis foci by pathological biopsy.
[0104] In this embodiment, by constructing a feature hierarchical structure from low layer to high layer, and fusing the upper-layer semantics with the current spatial information in each layer, the collaborative enhancement of semantic expression and spatial resolution is achieved. The recognition ability of the model for multi-size targets is improved, especially having obvious advantages in small target or text region localization tasks. At the same time, the computational cost brought by high-resolution modeling for all layers is avoided, and the balance between computational efficiency and expression ability is realized.
[0105] In one embodiment, the above step S10 includes: S101, input the image to be processed into a residual convolutional network, and generate an initial feature map through the initial convolutional layer of the residual convolutional network; S102, input the initial feature map into multiple stacked residual blocks. Each residual block sequentially extracts the features of the input feature map through a convolutional layer, normalizes the features through a batch normalization layer, non-linearly activates the normalized features through an activation function layer, and generates a residual feature map by element-wise adding the input feature map and the activated feature map through a skip connection; S103, after each residual block generates a residual feature map, adjust the channel weights of the residual feature map through a channel attention module. The channel attention module compresses the spatial dimension information through global pooling, generates the weight coefficients of each channel through a fully connected layer, and multiplies the weight coefficients with the residual feature map channel by channel to generate a channel-enhanced residual feature map; S104, in the residual blocks at different stages, perform downsampling processing on the channel-enhanced residual feature map through a convolutional operation with a stride greater than 1 to generate feature maps of multiple levels with decreasing resolution.
[0106] 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 retention capabilities. To this end, a residual convolutional network is introduced as the feature extraction backbone to achieve multi-scale semantic abstraction and detail retention while taking into account depth and stability. This feature extraction process starts from the image input end and usually includes an initial convolutional operation. A large convolutional kernel (such as 7×7) is used to cover a wide receptive field to extract initial texture and edge structure information at the full-image level, and the spatial resolution is first downsampled with a stride of 2 to compress the data dimension and enhance the anti-noise ability.
[0107] The initial feature map is used as the input of subsequent residual blocks, and layer-by-layer semantic extraction is performed through multiple stacked residual blocks. Each residual block is built on the basic unit of "convolution-batch normalization-nonlinear activation". The convolutional layer uses a fixed-size (such as 3×3) convolutional kernel to expand the receptive field of the local structure. Batch normalization is used to standardize the feature scales between different batches, improve the training convergence speed and model stability. The nonlinear activation function (such as ReLU or Swish) enhances the model's expressive ability and introduces complex decision boundaries. Each residual block introduces a skip connection structure that directly passes the input features to the output end and performs an element-wise addition operation with the result of the nonlinear transformation. This structure is essentially a gradient short-circuit mechanism that can alleviate the gradient vanishing problem in deep networks. At the same time, while maintaining the depth of the model, it still retains the low-level information of the input, enhancing the reversibility and plasticity of the features.
[0108] After the output of each level of residual blocks, a channel attention module will be further introduced to enhance the representational ability of the feature map in the channel dimension. This module compresses the spatial dimension in the feature map through global average pooling and global max pooling respectively to form two one-dimensional channel description vectors, and inputs them into a fully connected network with shared weights to generate channel weight coefficients. These weights reflect the significance of each channel in the current task. Finally, they are injected into the original feature map through channel-wise multiplication to achieve dynamic enhancement of semantically significant channels and suppression of redundant channels. This mechanism is particularly suitable for distinguishing high-semantic response regions and background redundant information in images. For example, in the caption detection task, it can significantly enhance the response amplitude of the text contour channels.
[0109] The structure of the residual network is not flat, but adopts a staged design. Between each key stage, spatial downsampling is performed through a convolutional operation with a stride of 2, gradually compressing the resolution of the feature map while enhancing its semantic abstraction ability. For example, the feature map output in the first stage retains almost all spatial details and is suitable for detecting small edges in the image; while the feature map output in the fifth stage has a low spatial resolution, but contains the context structure and high-level semantics of the entire image, which helps to identify long sentence captions, 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 and multi-scale image semantic basis for the region candidate and semantic classification modules.
[0110] Each component module in this feature extraction process is adjustable and scalable. For example, the size of the convolutional kernel in the initial convolutional layer can be adjusted according to the image resolution, the number and depth of the residual blocks can be scaled according to the model's computing resources and the difficulty of target detection, and the channel attention module can be switched to the SE module, ECA module, or CBAM module to adapt to the feature response patterns in different fields. In addition, the stride downsampling method can also choose depthwise separable convolution, pooling substitution, or spatial pyramid pooling strategy to optimize the computing efficiency and feature fidelity in different scenarios.
[0111] Through this feature extraction structure, this embodiment can refine high-level semantic information while retaining the local details of the image, forming multi-scale feature maps with context understanding ability. These feature maps provide a basic feature expression with deep semantics, wide resolution, and strong representation ability for subsequent steps such as pyramid fusion and region candidate, significantly improving the accuracy and robustness of sensitive area localization. Especially in image scenarios with complex text and significant background interference, this structure can effectively improve the ability to distinguish sensitive text areas.
[0112] In one embodiment, the above step S30 includes: S301, for each hierarchical feature map in the pyramid features, perform global average pooling and global maximum pooling processing respectively in the channel dimension to generate two compressed feature maps with the same spatial dimension; S302, concatenate the two compressed feature maps along the channel dimension to form an intermediate feature map; S303, perform spatial information modeling on the intermediate feature map through a convolutional layer to generate a single-channel spatial weight map; S304, perform normalization processing on the spatial weight map to generate a normalized spatial weight map; S305, multiply the normalized spatial weight map element-wise with the corresponding hierarchical feature map to generate an optimized attention feature map.
[0113] In this embodiment, after the multi-level pyramid features are constructed, to further enhance the model's focusing ability on spatially sensitive regions, a spatial attention mechanism is introduced into the pyramid feature maps at each level to strengthen the response weights of key positions in the spatial dimension. The core goal of this mechanism is to make the network pay more attention to local regions that may contain sensitive information by learning the importance of different positions in the feature map, suppress the interference of irrelevant background regions, and improve the subsequent subtitle recognition and image restoration effects.
[0114] The implementation of the spatial attention mechanism first performs global average pooling and global max pooling on each level of the pyramid feature map along the channel dimension to extract the spatial distribution features of the image from different statistical perspectives. Global average pooling can obtain the overall activation trend and reflect the overall spatial response profile of the feature map; while global max pooling highlights the strongly responding regions at the boundaries and captures significant textures such as the edges of sensitive words and identification lines. Structurally, the results of these two pooling operations maintain the same spatial dimension as the original and have a channel number of 1, respectively forming two spatially compressed feature maps.
[0115] Subsequently, the above two compressed feature maps are concatenated along the channel dimension to form an intermediate feature map with a channel number of 2. The concatenation operation retains both the average response and the maximum response spatial distribution information, which helps to model the spatial weights by integrating these two characteristics in the subsequent learning stage. This intermediate feature map is fed into a convolutional layer, usually a two-dimensional convolution with a receptive field of 7×7. The convolutional layer is used to establish the spatial dependence structure between neighborhoods and learn the correlation features between positions through the convolutional kernel, and finally outputs a single-channel spatial weight map.
[0116] To enhance the interpretability and normalization ability of this spatial weight map, an activation function (such as Sigmoid) is used to normalize it, mapping the weight values of all pixel points to between 0 and 1, thereby generating a normalized spatial weight map. The normalization process ensures that the model will not overfit to some extremely responding regions during training and is also beneficial for the stable backpropagation of gradients.
[0117] Finally, the normalized spatial weight map is fused with the original level pyramid feature map in an element-wise multiplication manner to complete the weighted modulation. This process is equivalent to applying a weight factor dynamically generated by the attention mechanism to each spatial position, thereby strengthening the feature expression of the subtitle target region and suppressing the responses of irrelevant pixels. Different from the channel attention mechanism, this method only models the spatial dimension and is particularly suitable for complex scenarios where the text region has various shapes and irregular contours.
[0118] During the entire execution process, each hierarchical feature map independently completes the above attention calculation path, so parallel processing is supported, ensuring the inference efficiency. The spatial attention module does not rely on high-level semantic inputs such as image categories and is modeled only based on the statistical representation of the feature map itself. Therefore, it has strong cross-image adaptability and scalability.
[0119] This spatial attention mechanism can be embedded into the processing path of each pyramid level. For example, spatial attention branches are respectively deployed in the pyramid feature maps of the four levels from P2 to P5. Each branch includes an average pooling operation, a max pooling operation, a concatenation operation, a 7×7 convolutional layer, and a Sigmoid activation function. The weights of the convolutional layer can be shared across different levels or trained separately according to the task complexity.
[0120] In terms of the selection of deployment parameters, the size of the convolutional kernel can be adjusted according to the object detection task. If dealing with small target characters in medical images, it is recommended to use a 5×5 convolution to avoid excessive context smoothing; if applied to tasks such as news image and social media long image large-scale caption detection, a 7×7 convolution is recommended to establish a larger spatial receptive field. The pooling operation defaults to a non-overlapping sliding window method to ensure spatial scale consistency. The activation function can be replaced with a non-linear function more suitable for embedded deployment, such as HardSigmoid or Swish, according to the model architecture.
[0121] In system implementation, this module can be constructed by calling existing APIs through standard deep learning frameworks (such as TensorFlow or PyTorch), without the need to write additional operators manually, and has good engineering feasibility and cross-platform compatibility.
[0122] In this embodiment, by introducing the spatial attention mechanism, significant weighting is performed on each pyramid-level feature map, strengthening the model's ability to locate spatial target regions, effectively suppressing background region noise, and improving the accuracy of sensitive region detection. Performing spatial weight reconstruction after multi-scale semantic fusion not only inherits the global context but also realizes the focus on spatial differences, avoiding information omission or bias caused by early fusion.
[0123] In one embodiment, the above step S40 includes: S401, generating multiple scales and aspect ratios of anchor boxes at each spatial position of the optimized attention feature map; S402, performing a sliding window process on the optimized attention feature map through the convolutional layer of the region proposal network to predict the class score and bounding box offset of each anchor box; S403, adjusting the center coordinates and sizes of the anchor boxes according to the bounding box offsets to generate adjusted candidate boxes; S404. Sort the candidate boxes in descending order according to the category scores, and retain the candidate boxes with the top preset number of scores. S405. Perform non-maximum suppression on the retained candidate boxes, and remove redundant candidate boxes with an intersection over union greater than the preset threshold to generate the coordinates of the candidate regions.
[0124] In this embodiment, based on the attention feature map after optimizing the spatial attention mechanism, a Region Proposal Network (RPN) is introduced as the target localization module to extract the coordinates of candidate regions with high confidence from the feature map. The goal is to obtain the significant regions in the image that may contain sensitive captions in a lightweight manner, providing region-level input for subsequent semantic recognition and image restoration. RPN does not rely on specific category labels and only predicts the regions where targets may exist based on the spatial response information of the feature map. Therefore, it is particularly suitable for the general sensitive information localization task.
[0125] The first step of this technical path is to pre-define multiple scales (such as 32, 64, 128 pixels) and aspect ratios (such as 1:1, 2:1, 1:2) of anchor boxes at each spatial position of the optimized attention feature map. Each anchor box is a candidate detection window used to cover potential target regions of different sizes and shapes. The generation method of anchor boxes follows the dense sliding window strategy, with an anchor box set corresponding to each pixel point on the feature map, thus achieving a comprehensive coverage of the image space.
[0126] Next, the optimized attention feature map is processed in the form of a sliding window through the convolutional layer in the RPN structure to extract the spatial features of the local receptive field. For each anchor box, the convolutional layer outputs two key prediction values: one is the category score of the presence of the target, indicating whether the region contains sensitive information; the other is the offset of the bounding box, that is, the position and size correction parameters of the anchor box relative to the true target box. This offset usually consists of the center point coordinate offsets Δx, Δy and the width and height scaling factors Δw, Δh.
[0127] After applying the predicted bounding box offset to the center coordinates and width and height dimensions of the original anchor box, more accurately positioned adjusted candidate boxes can be generated. These adjusted candidate boxes will be sorted in descending order according to their corresponding category scores, and the top preset number (such as 200) will be retained as the preliminary candidate set to avoid redundant candidate boxes occupying too much subsequent processing resources.
[0128] To further enhance the diversity and redundancy removal ability of candidate regions, the Non-Maximum Suppression (NMS) strategy is introduced. The specific approach is as follows: Traverse the set of candidate bounding boxes. Starting from the bounding box with the highest score, sequentially remove the overlapping candidate bounding boxes whose intersection over union (IoU) with the current bounding box exceeds a set threshold (such as 0.7), and retain the set of target bounding boxes with strong spatial exclusivity. The coordinates of the finally output candidate regions are the candidate set of sensitive subtitle regions with high confidence and spatial complementarity.
[0129] In actual implementation, 9 anchor boxes (3 scales × 3 aspect ratios) can be set for each spatial position, and the feature responses within each sliding window are extracted through a 3×3 convolution. The output structure of the RPN can be set as two parallel branches: a 2-channel softmax branch for outputting the binary classification scores of foreground and background, and a 4-channel linear branch for bounding box regression. In the category score sorting stage, the top-k strategy is used, and 200 or 300 candidate bounding boxes are set to be retained as the primary selection. The IoU threshold in non-maximum suppression can be adjusted for task adaptation: it can be set to 0.5 in medical images to improve the recall rate, and set to 0.7 in complex financial bills to improve the precision. It is recommended to perform all coordinate transformation and screening operations in parallel on the GPU to improve the inference efficiency. The RPN can share parameters with the backbone network or be trained as an independent sub-module. If the system has the ability of end-to-end training, it is recommended to perform backpropagation optimization on the RPN module through a joint loss function (category cross-entropy and regression L1 loss) to improve its localization effect.
[0130] In this embodiment, by performing region candidate network processing based on the optimized attention feature map, the early localization accuracy of sensitive subtitle regions can be significantly improved, and detection omissions caused by incomplete semantic coverage can be avoided. A dense set of candidate regions is constructed through a three-step mechanism of anchor box + bounding box regression + NMS, which can significantly reduce the interference of redundant candidate bounding boxes on downstream processing while improving the localization recall rate.
[0131] In one embodiment, the above S50 includes: S501, obtaining the downsampling stride of the feature pyramid network, and determining the abscissa of the center point of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling stride. 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 stride and then added with half of the downsampling stride; S502, determining the ordinate of the center point of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling stride. The ordinate of the center point of the candidate region is the ordinate of the candidate region in the feature map space multiplied by the downsampling stride and then added with half of the downsampling stride; S503. Determine the actual width of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step size. The actual width of the candidate region is the width of the candidate region in the feature map space multiplied by the downsampling step size. S504. Calculate the actual height of the candidate region of the candidate region coordinates in the image to be processed based on the downsampling step size. 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. S505. Perform boundary constraint processing on the abscissa of the center point of the candidate region, so that the abscissa 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. Perform boundary constraint processing on the ordinate of the center point of the candidate region, so that the ordinate 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. S506. Determine the left boundary coordinate and the right boundary coordinate of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region. 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. S507. Determine the upper boundary coordinate and the lower boundary coordinate of the candidate region in the image to be processed according to the actual width and the actual height of the candidate region. 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. S508. Crop the corresponding rectangular region from the image to be processed according to the abscissa of the center point of the candidate region, the ordinate of the center point of the candidate region, the adjusted actual width of the candidate region, and the adjusted actual height of the candidate region after constraint processing to generate a local image.
[0132] In this embodiment, in the process of mapping the candidate region coordinates 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 restoration operations. Since the feature pyramid network introduces multi-level downsampling in the process of constructing pyramid features, each layer of feature map has different spatial resolutions, so its coordinate system is compressed compared with the original image. To achieve the reduction of the coordinate scale, it is necessary to construct a mapping logic based on the downsampling step size corresponding to each layer of feature map. The downsampling step size refers to the range of original image pixels covered by each pixel of the feature map. For example, when the step size is 16, a pixel position in the feature map corresponds to a 16×16 pixel region in the original image. This parameter is usually defined by the network structure. For example, the C5 layer of ResNet has a step size of 32, and the P3 layer has a step size of 8.
[0133] The mapping of the center point position of the candidate region is the first step of this process. The conversion logic from the feature map space to the 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 respectively and then add half of the step size to form the center point coordinates that precisely correspond to the original image region. 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 does not deviate towards the boundary but aligns with the geometric center of the corresponding region, which is beneficial for the subsequent complete extraction of target information. Especially in text region detection, offset errors may cause incomplete character cutting and affect the desensitization effect.
[0134] The restoration of the candidate box size also needs to be enlarged in combination with the downsampling step size. If the width of the candidate box on the feature map is 4 and the height is 3, and the step size is 16, then it should be a rectangular region 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 image edge. In this case, boundary constraint operations need to be performed to ensure the legality of the coordinates. First, correct the center point coordinates 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, based on this, calculate the upper, lower, left, and right boundaries of the rectangular region. If the right boundary or the lower boundary exceeds the image range, truncate it towards the image edge and recalculate the actual width and height accordingly. This logic effectively avoids image reading overflow errors and ensures that the target region will not be deformed and distorted due to truncation.
[0135] When the center point coordinates and size after mapping are adjusted by boundary constraints, the image cropping operation can be completed based on this coordinate set. By calling the common rectangular cropping function in the image processing module, extract the image patch that completely coincides with the candidate region and use this region as the input for subsequent sensitive word recognition and texture repair. In medical images, this cropping strategy can ensure that tiny lesion areas (such as 0.5 - millimeter - level microcalcifications) are completely included; in financial documents, this strategy supports the precise extraction of sensitive fields such as signatures and ID numbers.
[0136] To improve the adaptability of this mapping operation in different application scenarios, a set of dynamic adjustment strategies can be designed. For example, in the scenario of high - resolution images, 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 the scenario of low - resolution images or small - target - dense scenes, a smaller step size is adopted to ensure that details are not compressed and lost. At the same time, for the boundary out - of - bounds problem generated during the mapping process, a boundary filling mechanism can be enabled to complement the part of the candidate box that exceeds the boundary by mirror filling or repeating edge pixels to ensure the integrity of the target. In addition, in the embedded or mobile deployment scenario, considering performance optimization, the multiplication operation can be replaced by a shift operation. For example, multiplying by 16 can be represented by shifting left by 4 bits, which effectively reduces the processing delay.
[0137] For example, in the field of healthcare, a patient's radiological images (such as CT scans, MRI images) often contain manually annotated patient names, numbers, or examination dates, which usually exist in the form of image-overlaid text in the edge or corner regions of the image. Through the above-mentioned image coordinate mapping technology, the candidate regions generated by the sensitive text regions in the feature map space can be accurately restored to the original image space. For example, a certain MRI image has a resolution of 512×512 pixels, and the sensitive text "Patient ID: 8392" is located in the upper right corner of the image. The candidate region coordinates detected in the 3rd layer feature map (downsampling stride is 8) of the feature pyramid network are (x = 60, y = 10, w = 6, h = 3). After coordinate mapping, the center point coordinates are (60×8 + 4, 10×8 + 4) = (484, 84), the width is 6×8 = 48, and the height is 3×8 = 24. Further applying the boundary constraint logic, it is found that the right boundary 484 + 24 = 508 does not exceed the image width, and the cropped region is legal. Finally, a rectangular image block containing "PatientID: 8392" is successfully cropped from the original image for subsequent sensitive word recognition and repair processing. Through this precise mapping and cropping process, it is ensured that the sensitive area is complete and accurately located, and the effective desensitization of patient privacy information is achieved without damaging the core diagnostic content of the medical image, which is applicable to various scenarios such as hospital file management, pre-processing of remote consultations, and medical image sharing platforms.
[0138] In this embodiment, through coordinate mapping processing, the candidate boxes in the feature map space generated by the region candidate network are accurately located in the original image, ensuring the direct perception consistency of the subsequent text recognition, semantic classification, and image repair processing with respect to the image content. It avoids problems such as incorrect region cropping and size mismatch caused by inconsistent scales, which is particularly important in small object detection or boundary-sensitive repair scenarios. The boundary constraint mechanism enhances the robustness of the system in the corner regions, preventing partial loss of sensitive information or abnormal image access.
[0139] In one embodiment, the above S80 includes: S801, determining the local sensitive region in the local image according to the sensitive word position confidence in the sensitive word detection result, and mapping the position of the local sensitive region to the global coordinate system of the image to be processed to generate global sensitive region coordinates; S802, cropping the corresponding global sensitive region from the image to be processed according to the global sensitive region coordinates, and generating a repair region mask; S803, performing multi-scale convolution operations on the global sensitive region to generate a multi-scale feature map containing global semantic information and local detail features; S804. Perform self-attention mechanism processing on the multi-scale feature map, analyze the correlation weights between pixel positions in the multi-scale feature map, generate an attention weight map, and multiply the attention weight map element-wise with the multi-scale feature map to generate a context-aware feature map; S805. Input the context-aware feature map into the restoration network, and generate a restored sensitive region image through alternately stacked residual convolutional layers and dilated convolutional layers; S806. According to the restoration region mask, perform Poisson fusion processing on the corresponding positions of the restored sensitive region image and the image to be processed to generate the desensitized image.
[0140] In this embodiment, sensitive regions in the image usually exist in the form of text or occlusion, with clear spatial positions and content structures. To achieve targeted replacement of these regions, it is necessary to determine the spatial positions of local sensitive regions based on the confidence information given in the sensitive word detection results. The detection results are usually a list of text boxes, and each box contains the center coordinates, size information, and the predicted probability that the position is a sensitive word. When mapping the sensitive regions located in the local image to the global image space, it is necessary to record the original starting coordinates of the current local image and restore them to the absolute position in the full-image coordinate system through offset transformation, so as to accurately crop the global sensitive region for restoration.
[0141] After cropping the sensitive region, it is necessary to generate a restoration region mask for subsequent restoration guidance. The mask defines the boundary between the restoration region and the non-restoration region in the form of a binary image. To enhance the continuity of the restoration edge, morphological closing operations can be used in the mask generation stage, that is, first dilate and expand the sensitive region, and then remove isolated noise through erosion operations to ensure smooth region edges and continuous interiors. The mask is used to limit the restoration operation to only act on the target region and avoid accidentally modifying other valid information in the image.
[0142] The multi-scale convolution operation extracts local details and global structures in parallel by using convolution kernels of different sizes (such as 3×3, 5×5, 7×7). Small kernels are more suitable for extracting texture features such as character edges and stroke corners, and large kernels can capture the spatial relationships and overall arrangement forms between characters. After the multi-scale feature maps are concatenated in the channel dimension, they are then compressed to a unified dimension through 1×1 convolution to improve the compactness of expression and enhance the semantic fusion ability, forming a multi-scale feature map with rich context information.
[0143] The self-attention mechanism is used to model the long-range dependencies between pixels in the spatial dimension of the feature map. By calculating the correlation weights between each pixel and other pixels, an attention weight map is constructed, which serves as an explicit guidance mechanism for feature enhancement. This map is multiplied element-wise with the multi-scale feature map to obtain 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 restoration operation more contextually consistent.
[0144] The context-aware feature map is input into the restoration network, which adopts a structure combining residual and dilated convolutions to expand the receptive field and preserve local details. Residual connections are used to alleviate the vanishing gradient problem in deep networks, while dilated convolutions enhance the ability of the feature map to capture long-range semantics without increasing the number of parameters. This restoration network can generate high-fidelity and structurally consistent restored images, effectively filling the regions occupied by sensitive information.
[0145] Finally, the restored image is fused back into the corresponding position in the original image through the Poisson fusion method. Poisson fusion is based on the principle of gradient consistency. Poisson equations are constructed at the boundary of the restored region, and through iterative solution, the gray gradients at the edge of the restored region are seamlessly connected to the surrounding image, ensuring that there are no obvious mutations in color and texture in the transition zone. The output desensitized image is visually coherent and it is difficult to detect the restoration traces, meeting the security requirements for the irreversible reconstruction of sensitive information.
[0146] In one specific implementation, for the detected sensitive word positions, it is first necessary to extract the corresponding local image regions from the image to be processed and accurately restore their coordinate positions in the global image. This mapping process is based on the local image cropping records obtained from the previous candidate box processing. For example, the displacement amount (the reference coordinate of the upper left corner) between the original image and the candidate region is recorded, and the local coordinates can be restored to the global image coordinates by adding this offset. In the mask generation stage, morphological image processing techniques are used to improve the quality of the region boundaries. Specifically, the cv2.dilate and cv2.erode functions in OpenCV are used to construct a closing operation process. The initial mask is a binary image, where the sensitive region is 1 and the rest is 0. A 3×3 structuring element is used for one dilation (the number of iterations can be set to 1 or 2), and then erosion of the same scale is performed to effectively fill the holes in the region and connect the broken regions, such as the broken digital strokes in an ID number or the broken pen segments in a handwritten signature. When the cropped sensitive region is input into the convolutional neural network, a multi-scale convolutional module (Inception-like structure) is constructed, which contains three parallel branches that use 3×3, 5×5, and 7×7 convolutional kernels to extract features of different scales. The channel outputs are set to 64, 64, and 128 respectively. After channel concatenation, a 1×1 convolution is used to compress the channels to 256 dimensions and unify the size. This operation can be implemented using PyTorch, and BatchNorm and ReLU activation are inserted between the convolutional blocks to improve the expression stability. Subsequently, self-attention modeling is performed on this fused feature, and the standard Scaled Dot-Product Attention mechanism is adopted. Query (Q), key (K), and value (V) matrices are generated through linear mapping, the attention weight matrix is calculated, and then multiplied by the V matrix to obtain the context-aware feature map. In implementation, a multi-head attention module (such as a partial implementation of the Transformer Encoder) can be used, and 4 or 8 attention heads are set 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 4 stacked residual blocks, each of which contains two 3×3 convolutions, BatchNorm, and ReLU activation, and is equipped with skip connections; the decoder part uses 4 layers of deconvolution or upsampling + convolution combinations, and dilated convolution (dilation = 2 or 3) is introduced to expand the receptive field and improve the background modeling ability. The skip connection of each layer can be embedded with a spatial attention module to strengthen semantic alignment. The output image size of the restoration network is the same as the input sensitive region 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 the 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.
[0147] 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 convolution is used to extract stroke textures, character arrangements, and background structures; the self-attention mechanism strengthens the context consistency between characters and the background transition area; the repair network reconstructs textures consistent with the surrounding lung tissues while keeping the skeleton line structure intact; 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.
[0148] Through the above steps, this embodiment realizes the full-process processing link from the positioning, characterization, semantic modeling of the detected sensitive area to the high-quality texture generation and natural fusion. It effectively overcomes problems such as structural loss, 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.
[0149] In one embodiment, an image sensitive text desensitization device is provided, and this image sensitive text desensitization device corresponds one-to-one to 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. The residual feature extraction module 10, the multi-scale fusion module 20, the spatial attention enhancement module 30, the candidate region generation module 40, the coordinate mapping and cropping module 50, the self-attention text extraction module 60, the sensitive word recognition module 70, and the local image repair module 80. The detailed description of each functional module is as follows: The residual feature extraction module 10 is used to extract multiple feature maps from the image to be processed through a residual convolutional network; The multi-scale fusion module 20 is used to input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion. The spatial attention enhancement module 30 is used to fuse the spatial attention mechanism in the feature maps of each level of the pyramid features, generate a spatial weight map corresponding to the feature map of each level, and multiply the spatial weight map element-wise with the corresponding feature map of each level to generate a corresponding optimized attention feature map. The candidate region generation module 40 is used to generate candidate region coordinates through a region proposal network based on the optimized attention feature map. The coordinate mapping and cropping module 50 is used to map the candidate region coordinates to the image to be processed and determine the local image of the corresponding region. The self-attention text extraction module 60 is used to divide the local image into pixel blocks, and after linearly projecting and position encoding the pixel blocks, input them into an encoder-decoder based on the self-attention mechanism to extract a text sequence. The sensitive word recognition module 70 is used to input the text sequence into a semantic classification model for sensitive word detection to generate a sensitive word detection result. The local image repair module 80 is used to perform local texture repair on the sensitive region of the image to be processed according to the sensitive word detection result to generate a desensitized image.
[0150] In one embodiment, the multi-scale fusion module 20 is specifically used for: Input the multiple feature maps into the feature pyramid network, and the multiple feature maps are arranged in a hierarchical order from high resolution to low resolution. Perform lateral connection processing on the feature map of each level through the feature pyramid network, and unify the channel dimensions of the feature map of each level through convolution operations respectively to generate corresponding lateral connection feature maps. Construct a top-down path through the feature pyramid network, perform convolution operations on the lateral connection feature map of the lowest level to generate the pyramid feature corresponding to the lowest level. Starting from the second lowest level, in the order of increasing resolution, perform upsampling operations on the pyramid feature generated by the previous level, add the upsampled pyramid feature and the lateral connection feature map of the current level element-wise for fusion, and perform convolution operations on the fusion result to generate the pyramid feature corresponding to the current level. The pyramid features corresponding to all levels constitute the pyramid features with multi-level semantic fusion.
[0151] In one embodiment, the residual feature extraction module 10 is specifically used for: Input the image to be processed into the residual convolutional network, and generate 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 sequentially extracts the features of the input feature map through a convolutional layer, normalizes the features through a batch normalization layer, non-linearly activates the normalized features through an activation function layer, and generates a residual feature map by element-wise adding the input feature map and the activated feature map through a skip connection; After each residual block generates a residual feature map, adjust the channel weights of the residual feature map through a channel attention module. The channel attention module compresses the spatial dimension information through global pooling, generates the weight coefficients of each channel through a fully connected layer, and multiplies the weight coefficients with the residual feature map channel by channel to generate a channel-enhanced residual feature map; In the residual blocks at different stages, perform downsampling processing on the channel-enhanced residual feature map through a convolutional operation with a stride greater than 1 to generate multiple levels of feature maps with decreasing resolutions.
[0152] In one embodiment, the spatial attention enhancement module 30 is specifically used for: Perform global average pooling and global maximum pooling processing on each level feature map in the pyramid feature respectively in the channel dimension to generate two compressed feature maps with the same spatial dimension; Concatenate the two compressed feature maps along the channel dimension to form an intermediate feature map; Perform spatial information modeling on the intermediate feature map through a convolutional layer to generate a single-channel spatial weight map; Perform normalization processing on the spatial weight map to generate a normalized spatial weight map; Multiply the normalized spatial weight map with the corresponding level feature map element by element to generate an optimized attention feature map.
[0153] In one embodiment, the candidate region generation module 40 is specifically used for: Generate multiple scales and aspect ratios of anchor boxes at each spatial position of the optimized attention feature map; Perform a sliding window process on the optimized attention feature map through the convolutional layer of the region candidate network to predict the class score and bounding box offset of each anchor box; Adjust the center coordinates and sizes of the anchor boxes according to the bounding box offsets to generate adjusted candidate boxes; Sort according to the class scores from high to low, and retain the candidate boxes with the top preset number of scores; Perform non-maximum suppression processing on the retained candidate boxes, and remove the redundant candidate boxes with an intersection over union greater than the preset threshold to generate the candidate region coordinates.
[0154] In one embodiment, the coordinate mapping and clipping module 50 is specifically configured to: Obtain the downsampling step size of the feature pyramid network, and based on the downsampling step size, determine the abscissa of the center point of the candidate region in the to-be-processed image for the candidate region coordinates. 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 and then added with half of the downsampling step size; Based on the downsampling step size, determine the ordinate of the center point of the candidate region in the to-be-processed image for the candidate region coordinates. The ordinate of the center point of the candidate region is the ordinate of the candidate region in the feature map space multiplied by the downsampling step size and then added with half of the downsampling step size; Based on the downsampling step size, determine the actual width of the candidate region in the to-be-processed image for the candidate region coordinates. The actual width of the candidate region is the width of the candidate region in the feature map space multiplied by the downsampling step size; Based on the downsampling step size, calculate the actual height of the candidate region in the to-be-processed image for the candidate region coordinates. 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; Perform boundary constraint processing on the abscissa of the center point of the candidate region, so that the abscissa of the center point of the candidate region is not less than zero and does not exceed the width of the to-be-processed image. Perform boundary constraint processing on the ordinate of the center point of the candidate region, so that the ordinate of the center point of the candidate region is not less than zero and does not exceed the height of the to-be-processed image; According to the actual width and actual height of the candidate region, determine the left boundary coordinate and right boundary coordinate of the candidate region in the to-be-processed image, 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 to-be-processed image; According to the actual width and actual height of the candidate region, determine the upper boundary coordinate and lower boundary coordinate of the candidate region in the to-be-processed image, 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 to-be-processed image; According to the abscissa of the center point of the candidate region, the ordinate of the center point of the candidate region after constraint processing, and the adjusted actual width and actual height of the candidate region, crop the corresponding rectangular region from the to-be-processed image to generate a local image.
[0155] In one embodiment, the local image repair module 80 is specifically configured to: Determine the local sensitive regions in the local image according to the confidence of the sensitive word positions in the sensitive word detection results, and map the positions of the local sensitive regions to the global coordinate system of the image to be processed to generate global sensitive region coordinates; Crop the corresponding global sensitive regions from the image to be processed according to the global sensitive region coordinates, and generate a repair region mask; Perform multi-scale convolution operations on the global sensitive regions to generate a multi-scale feature map containing global semantic information and local detail features; Perform self-attention mechanism processing on the multi-scale feature map, analyze the correlation weights between the pixel positions in the multi-scale feature map, generate an attention weight map, and multiply the attention weight map and the multi-scale feature map element by element to generate a context-aware feature map; Input the context-aware feature map into a repair network, and generate a repaired sensitive region image through alternately stacked residual convolution layers and dilated convolution layers; According to the repair region mask, perform Poisson fusion processing on the repaired sensitive region image and the corresponding positions in the image to be processed to generate the desensitized image.
[0156] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structure diagram can be as Figure 4 shown. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an 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 the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external client through a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the server side of an image sensitive text desensitization method.
[0157] In one embodiment, a computer device is provided. The computer device can be a client, and its internal structure diagram can be as Figure 5As shown in the figure. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Among them, 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 computer programs. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external server through a network connection. When the computer program is executed by the processor, it realizes the functions or steps on the user side of an image-sensitive text desensitization method 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 implemented: Extract multiple feature maps from the image to be processed through a residual convolutional network; Input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; Fuse the spatial attention mechanism in the feature maps of each level of the pyramid features to generate a spatial weight map corresponding to the feature map of each level, and multiply the spatial weight map element-wise with the corresponding feature map of each level to generate a corresponding optimized attention feature map; Based on the optimized attention feature map, generate candidate region coordinates through a region proposal network; Map the candidate region coordinates to the image to be processed to determine the local image of the corresponding region; Segment the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on the self-attention mechanism after linear projection and position encoding processing to extract a text sequence; Input the text sequence into a semantic classification model for sensitive word detection to generate a sensitive word detection result; According to the sensitive word detection result, perform local texture repair on the sensitive region of the image to be processed to generate a desensitized image.
[0158] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by the processor, the following steps are implemented: Extract multiple feature maps from the image to be processed through a residual convolutional network; Input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; Fuse the spatial attention mechanism in 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 multiply the spatial weight map with the corresponding feature map of each level element by element to generate a corresponding optimized attention feature map; Based on the optimized attention feature map, generate candidate region coordinates through a region proposal network; Map the candidate region coordinates to the image to be processed to determine the local image of the corresponding region; Divide the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on the self-attention mechanism after linear projection and position encoding processing to extract a text sequence; Input the text sequence into a semantic classification model for sensitive word detection to generate a sensitive word detection result; According to the sensitive word detection result, perform local texture repair on the sensitive area of the image to be processed to generate a desensitized image.
[0159] It should be noted that for the functions or steps that can be realized by the above computer-readable storage medium or computer device, reference can be made to the relevant descriptions on the server side and the user side in the foregoing method embodiments. To avoid repetition, they will not be described in detail here.
[0160] Those of ordinary skill in the art can understand that all or part of the processes of implementing the methods in the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, storage, database, or other medium used in the various embodiments provided in the present application can include non-volatile and / or volatile memories. The non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), or flash memory. The volatile memory can include random access memory (RAM) or an external cache. 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 (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0161] Those skilled in the art can clearly understand that, for the convenience and conciseness of description, only the above division of each functional unit and module is used as an example. In actual applications, the above functions can be allocated to different functional units and modules according to needs, that is, the internal structure of the device is divided into different functional units or modules to complete all or part of the functions described above.
[0162] It should be noted that if there are software tools or components of other companies in the embodiments of the present application, they are only used for example introduction and do not represent actual use. The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements on some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be included in the protection scope of the present invention.
Claims
1. An image-sensitive text desensitization method, characterized in that, It includes the following steps: Extract multiple feature maps from the image to be processed through a residual convolutional network; Input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; Fuse the spatial attention mechanism in the feature maps of each level of the pyramid features to generate a spatial weight map corresponding to the feature map of each level, and multiply the spatial weight map element-wise with the corresponding feature map of each level to generate a corresponding optimized attention feature map; Based on the optimized attention feature map, generate candidate region coordinates through a region proposal network; Map the candidate region coordinates to the image to be processed to determine the local image of the corresponding region; Segment the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on the self-attention mechanism after linear projection and position encoding processing to extract a text sequence; Input the text sequence into a semantic classification model for sensitive word detection to generate a sensitive word detection result; According to the sensitive word detection result, perform local texture repair on the sensitive region of the image to be processed to generate a desensitized image.
2. The image-sensitive text desensitization method according to claim 1, wherein, Input the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion, including: Input the multiple feature maps into a feature pyramid network, and the multiple feature maps are arranged in a hierarchical order from high resolution to low resolution; Perform lateral connection processing on the feature map of each level through the feature pyramid network, and unify the channel dimensions of the feature map of each level through convolution operations respectively to generate corresponding lateral connection feature maps; Construct a top-down path through the feature pyramid network, perform convolution operations on the lateral connection feature map of the lowest level to generate the pyramid feature corresponding to the lowest level; Starting from the second lowest level, in the order of increasing resolution, perform upsampling operations on the pyramid features generated in the previous level, add the upsampled pyramid features and the lateral connection feature maps of the current level element-wise, and perform convolution operations on the fusion result to generate the pyramid feature corresponding to the current level; The pyramid features corresponding to all levels constitute the pyramid features with multi-level semantic fusion.
3. The image-sensitive text desensitization method according to claim 1, wherein Extract multiple feature maps from the image to be processed through a residual convolutional network, including: Input the image to be processed into a residual convolutional network, and generate 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 the features of the input feature map through a convolutional layer in sequence, normalizes the features through a batch normalization layer, performs non-linear activation processing on the normalized features through an activation function layer, and adds the input feature map and the activated feature map element-wise through a skip connection to generate a residual feature map; After each residual block generates a residual feature map, adjust the channel weights of the residual feature map through a channel attention module. The channel attention module compresses the spatial dimension information through global pooling, generates weight coefficients for each channel through a fully connected layer, and multiplies the weight coefficients with the residual feature map channel-wise to generate a residual feature map with enhanced channels; In the residual blocks at different stages, downsampling is performed on the residual feature map after channel enhancement through a convolutional operation with a stride greater than 1, generating multiple hierarchical feature maps with decreasing resolutions.
4. The image-sensitive text desensitization method according to claim 1, wherein In each hierarchical feature map of the pyramid features, a spatial attention mechanism is fused to generate a spatial weight map corresponding to each hierarchical feature map, and the spatial weight map is multiplied element-wise with the corresponding hierarchical feature map to generate a corresponding optimized attention feature map, including: For each hierarchical feature map in the pyramid features, global average pooling and global max pooling are respectively performed in the channel dimension to generate two compressed feature maps with the same spatial dimensions; The two compressed feature maps are concatenated along the channel dimension into an intermediate feature map; The intermediate feature map is subjected to spatial information modeling through a convolutional layer to generate a single-channel spatial weight map; The spatial weight map is normalized to generate a normalized spatial weight map; The normalized spatial weight map is multiplied element-wise with the corresponding hierarchical feature map to generate an optimized attention feature map.
5. The image-sensitive text desensitization method according to claim 1, characterized in that Based on the optimized attention feature map, candidate region coordinates are generated through a region proposal network, including: At each spatial position of the optimized attention feature map, multiple scales and aspect ratios of anchor boxes are generated; The optimized attention feature map is processed through a sliding window by the convolutional layer of the region proposal network to predict the class score and bounding box offset of each anchor box; According to the bounding box offset, the center coordinates and size of the anchor box are adjusted to generate an adjusted candidate box; Sorted from high to low according to the class score, the top pre-set number of candidate boxes with the highest scores are retained; The retained candidate boxes are subjected to non-maximum suppression processing, and redundant candidate boxes with an intersection over union greater than a pre-set threshold are removed to generate the candidate region coordinates.
6. The image-sensitive text desensitization method according to claim 1, characterized in that, The candidate region coordinates are mapped to the image to be processed to determine the local image of the corresponding region, including: The downsampling stride of the feature pyramid network is obtained, and based on the downsampling stride, the abscissa of the candidate region center point of the candidate region coordinates in the image to be processed is determined. The abscissa of the candidate region center point is the abscissa of the candidate region in the feature map space multiplied by the downsampling stride and then added with half of the downsampling stride; Based on the downsampling stride, the ordinate of the candidate region center point of the candidate region coordinates in the image to be processed is determined. The ordinate of the candidate region center point is the ordinate of the candidate region in the feature map space multiplied by the downsampling stride and then added with half of the downsampling stride; Based on the downsampling stride, the actual width of the candidate region of the candidate region coordinates in the image to be processed is determined. The actual width of the candidate region is the width of the candidate region in the feature map space multiplied by the downsampling stride; Based on the downsampling stride, the actual height of the candidate region of the candidate region coordinates in the image to be processed is calculated. The actual height of the candidate region is the height of the candidate region in the feature map space multiplied by the downsampling stride; Perform boundary constraint processing on the abscissa of the center point of the candidate region, so that the abscissa 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. Perform boundary constraint processing on the ordinate of the center point of the candidate region, so that the ordinate 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; According to the actual width and actual height of the candidate region, determine the left and right boundary coordinates of the candidate region in the image to be processed, 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; According to the actual width and actual height of the candidate region, determine the upper and lower boundary coordinates of the candidate region in the image to be processed, 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 abscissa of the center point of the candidate region, the ordinate of the center point of the candidate region after constraint processing, and the adjusted actual width and actual height of the candidate region, crop the corresponding rectangular region from the image to be processed to generate a local image.
7. The image-sensitive text desensitization method according to claim 1, characterized in that According to the sensitive word detection result, perform local texture repair on the sensitive region of the image to be processed to generate a desensitized image, including: According to the confidence of the sensitive word position in the sensitive word detection result, determine the local sensitive region in the local image, and map the position of the local sensitive region to the global coordinate system of the image to be processed to generate the global sensitive region coordinates; According to the global sensitive region coordinates, crop the corresponding global sensitive region from the image to be processed and generate a repair region mask; Perform multi-scale convolution operations on the global sensitive region to generate a multi-scale feature map containing global semantic information and local detail features; Perform self-attention mechanism processing on the multi-scale feature map, analyze the correlation weights between the pixel positions in the multi-scale feature map, generate an attention weight map, and multiply the attention weight map and the multi-scale feature map element by element to generate a context-aware feature map; Input the context-aware feature map into a repair network, and generate a repaired sensitive region image through alternately stacked residual convolution layers and dilated convolution layers; According to the repair region mask, perform Poisson fusion processing on the repaired sensitive region image and the corresponding position in the image to be processed to generate the desensitized image.
8. An image-sensitive text desensitization device, characterized in that, The image sensitive text desensitization device includes: A residual feature extraction module for extracting multiple feature maps from the image to be processed through a residual convolution network; A multi-scale fusion module for inputting the multiple feature maps into a feature pyramid network for multi-scale fusion to generate pyramid features with multi-level semantic fusion; A spatial attention enhancement module for fusing a spatial attention mechanism in each level feature map of the pyramid features, generating a spatial weight map corresponding to each level feature map, and multiplying the spatial weight map and the corresponding level feature map element by element to generate a corresponding optimized attention feature map; A candidate region generation module, configured to generate candidate region coordinates based on the optimized attention feature map through a region proposal network; A coordinate mapping and cropping module, configured to map the candidate region coordinates to the image to be processed and determine a local image of the corresponding region; A self-attention text extraction module, configured to divide the local image into pixel blocks, and input the pixel blocks into an encoder-decoder based on a self-attention mechanism after linear projection and position encoding processing to extract a text sequence; A sensitive word recognition module, configured to input the text sequence into a semantic classification model for sensitive word detection and generate a sensitive word detection result; A local image restoration module, configured to perform local texture restoration on the sensitive region of the image to be processed according to the sensitive word detection result and generate a desensitized image.
9. A computer device, characterized in that, The computer device includes a memory, a processor, and an image sensitive text desensitization program stored on the memory and executable 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-7 are implemented.
10. A computer-readable storage medium, characterized in that, An image sensitive text desensitization program is stored on the storage medium. When the image sensitive text desensitization program is executed by a processor, the steps of the image sensitive text desensitization method according to any one of claims 1-7 are implemented.
Citation Information
Patent Citations
Image desensitization method and device, electronic equipment and storage medium
CN114758145A
Removing distracting objects from digital images
US20240171848A1
Cited By
Target cooperative control method and system based on deep learning
CN120370719A
Large model data labeling method and device based on multi-candidate arbitration and storage medium
CN120411661A
Large model data annotation method, device and storage medium based on multi-candidate arbitration
CN120411661B
Finance and tax text data verification method and system
CN120544212A
Digitalized batch repair method and system for ancient books
CN120765513A
