Method and system for separating seal from background in image

Through the multi-stage architecture of stamp detection, segmentation and extraction sub-networks, combined with spatial and contextual attention mechanisms, the problem of stamp and background separation in complex scenes is solved, achieving more precise separation effects and robustness.

CN118628753APending Publication Date: 2024-09-10SHANGHAI HEHE INFORMATION TECH DEV +3
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202311752588.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-18
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

It is difficult for the existing technology to effectively separate the stamp and the background in the image in complex scenes, especially when the stamp and the background text overlap or have similar colors, which makes the separation difficult.

Method used

Use the stamp detection sub-network to locate and crop the stamp area, predict the coarse-grained foreground mask through the stamp segmentation sub-network, combine the first and second stages of stamp extraction sub-networks for fine-grained separation, and use the spatial separation attention mechanism and context Attention mechanism to improve separation accuracy.

Benefits of technology

The complexity of each module is reduced, the separation effect is more accurate, the overlap between the stamp and the background can be effectively handled, and the robustness of stamp extraction and background repair effect are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118628753A
    Figure CN118628753A
Patent Text Reader

Abstract

The invention discloses a method for separating a seal from a background in an image. And positioning and cutting out a seal area in an input image by adopting the seal detection sub-network. Predicting a coarse-grained seal foreground mask from the seal region by adopting the seal segmentation sub-network; and the seal foreground mask refers to an image for distinguishing the foreground and background of the seal by adopting different values of a certain image parameter. A coarse-grained seal background, a fine-grained seal foreground mask and a seal foreground are obtained through prediction according to a seal area and a coarse-grained seal foreground mask by adopting a seal extraction first-stage sub-network. And a fine-grained seal background is obtained through prediction according to the coarse-grained seal background and the fine-grained seal foreground mask by adopting the seal extraction second-stage sub-network, wherein a spatial separation attention mechanism is adopted according to the seal foreground and the background distinguished by the fine-grained seal foreground mask. Seal foreground and background separation is divided into two stages, the learning difficulty of the neural network in each stage is reduced, and the final separation effect is more accurate.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to an image processing method, in particular to a method for separating a stamp and a background in an image. Background Art

[0002] Stamps are common elements in document images, which usually contain publisher information to prove identity and prevent forgery. In an image containing a stamp, the foreground refers to the stamp, and the background refers to the content other than the stamp. Separating stamps from backgrounds has important application value in many fields, such as forensic identification, official document processing, bank checks, etc. It can improve the efficiency and quality of automated processing, promote document identification, enhance readability and comprehension, and promote digital preservation and processing.

[0003] The position and size of a stamp in an image are often uncertain, the style and color of a stamp are complex and varied, the stamp may be deformed or distorted for various reasons, and the stamp and background may be mixed and superimposed together and difficult to distinguish, all of which pose challenges to separating the stamp and background in an image. Summary of the invention

[0004] The technical problem to be solved by the present invention is how to separate the stamp from the background in an image, especially in complex scenes, such as: the stamp overlaps with the background text, making it difficult to distinguish, the black stamp and the text are similar in color and difficult to distinguish, and the stamp style and color vary.

[0005] In order to solve the above technical problems, the present invention proposes a method for separating a stamp from a background in an image, comprising the following steps. Step S1: Using a stamp detection subnetwork to locate and crop the stamp area in the input image. Step S2: Using a stamp segmentation subnetwork to predict a coarse-grained stamp foreground mask from the stamp area; the stamp foreground mask refers to a map that uses different values ​​of a certain image parameter to distinguish the stamp foreground and background. Step S3: Using the stamp extraction first stage subnetwork to predict the coarse-grained stamp background, fine-grained stamp foreground mask, and stamp foreground based on the stamp area and the coarse-grained stamp foreground mask. Step S4: Using the stamp extraction second stage subnetwork to predict the fine-grained stamp background based on the coarse-grained stamp background and the fine-grained stamp foreground mask, wherein the stamp foreground and background distinguished by the fine-grained stamp foreground mask adopt a spatial separation attention mechanism.

[0006] Furthermore, in step S1, the stamp detection subnetwork adopts a neural network for image target detection.

[0007] Furthermore, in the step S1, after the stamp area is cropped, the stamp area is uniformly scaled to a fixed size.

[0008] Furthermore, in step S2, the stamp segmentation subnetwork adopts a neural network for image semantic segmentation, or for visual saliency detection, or for image translation.

[0009] Furthermore, in step S2, after obtaining the coarse-grained stamp foreground mask of the original size, the stamp segmentation subnetwork uses the pixel reconstruction technology to reconstruct the coarse-grained stamp foreground mask into a larger size and then outputs it.

[0010] Furthermore, in step S3, the coarse-grained stamp foreground mask is first dilated and then used as the input of the first-stage stamp extraction sub-network.

[0011] Furthermore, in the steps S3 and S4, the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork both use a neural network for image processing and having an encoder and decoder structure; wherein the encoder is used to compress the image to extract image features, and the decoder is used to restore or reconstruct the extracted image features; the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork are either two parts of a neural network, or two neural networks; the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork are trained using the same training data set, and are jointly learned and optimized.

[0012] Furthermore, in step S3, the first stage sub-network of stamp extraction includes an encoder and three decoders, and the three decoders are used to predict the rough background, foreground mask and foreground respectively, and the three decoders share an encoder to extract image features.

[0013] Furthermore, in step S4, the second stage sub-network of stamp extraction also adopts a contextual attention mechanism.

[0014] The present invention also proposes a system for separating stamps from backgrounds in an image, including a stamp detection subnetwork, a stamp segmentation subnetwork, a stamp extraction first stage subnetwork, and a stamp extraction second stage subnetwork. The stamp detection subnetwork is used to locate and crop the stamp area in the input image. The stamp segmentation subnetwork is used to predict a coarse-grained stamp foreground mask from the stamp area. The stamp extraction first stage subnetwork is used to predict a coarse-grained stamp background, a fine-grained stamp foreground mask, and a stamp foreground based on the stamp area and the coarse-grained stamp foreground mask. The stamp extraction second stage subnetwork is used to predict a fine-grained stamp background based on the coarse-grained stamp background and the fine-grained stamp foreground mask, wherein a spatial separation attention mechanism is used for the stamp foreground and background distinguished by the fine-grained stamp foreground mask.

[0015] The technical effects achieved by the present invention are: the overall architecture of stamp detection, stamp segmentation, and stamp foreground and background separation is adopted to reduce the complexity of each module; the task of separating the stamp foreground and background is divided into two stages, which reduces the learning difficulty of the neural network in each stage and makes the final separation effect more accurate. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] Figure 1 It is a flow chart of the method for separating a stamp from a background in an image proposed by the present invention.

[0017] Figure 2 It is a schematic diagram of the structure of the system for separating the stamp from the background in the image proposed by the present invention.

[0018] Figure 3-Figure 10 It is a schematic diagram for illustrating the method of the present invention by using an example.

[0019] Explanation of the reference numerals in the figure: the system includes a stamp detection subnetwork 1, a stamp segmentation subnetwork 2, a stamp extraction first stage subnetwork 3, and a stamp extraction second stage subnetwork 4. DETAILED DESCRIPTION

[0020] See also Figure 1 , the method for separating the stamp from the background in an image proposed by the present invention includes the following steps.

[0021] Step S1: Use the stamp detection subnetwork to locate the stamp area in the input image, and crop the stamp area as the subsequent input. The stamp area is divided into foreground and background. The foreground refers to the stamp, and the background refers to the original image content where the stamp is placed. The foreground and the stamp are superimposed to form the stamp area.

[0022] The stamp detection subnetwork may adopt any neural network for image target detection, such as the YOLO series, the R-CNN series, the transformer-based DETR, and the like.

[0023] Optionally, in this step, after the stamp area is cropped, the stamp area is uniformly scaled (resized) to a fixed size, such as 256 pixels×256 pixels, to accommodate stamp areas of different sizes and different aspect ratios.

[0024] Step S2: Use the stamp segmentation subnetwork to predict a coarse-grained stamp foreground mask from the stamp area. This step only performs separation processing on the local area of ​​the detected stamp (i.e., the output of step S1), which effectively avoids false detection and missed detection of stamps, and helps to improve the network processing efficiency and the relative clarity of the stamp area. The stamp foreground mask is a picture of the same size as the input image. Each pixel in the stamp foreground mask uses different values ​​(e.g., 0, 255) of a certain image parameter (e.g., α channel) to distinguish whether the pixel belongs to the stamp foreground or background. For example, in the stamp foreground mask, the value of the α channel of a pixel is 0 (displayed as black), indicating that the pixel belongs to the background; the value of the α channel of a pixel is 255 (displayed as white), indicating that the pixel belongs to the stamp. The coarse-grained stamp foreground mask is a relatively rough stamp foreground and background separation result. For example, it cannot handle complex situations such as the overlap of the stamp foreground and background, but using it as a subsequent input can reduce the learning difficulty of subsequent separation tasks.

[0025] The stamp segmentation subnetwork may adopt any neural network for image semantic segmentation, or for visual saliency detection, or for image translation. Examples of neural networks that may be used for image semantic segmentation are Deeplabv3+ and Mask2former. Examples of neural networks that may be used for visual saliency detection are Selfreformer. Examples of neural networks that may be used for image translation are pix2pix.

[0026] Optionally, after obtaining the coarse-grained stamp foreground mask of the original size, the stamp segmentation subnetwork uses the pixel shuffle technology to reconstruct the coarse-grained stamp foreground mask into a larger size, and the stamp segmentation subnetwork outputs the reconstructed coarse-grained stamp foreground mask of the larger size. The original size is, for example, 256 pixels × 256 pixels, and the larger size is, for example, 512 pixels × 512 pixels, which helps to improve the clarity of the processing result. Recombination of pixel maps is an existing technology for recombining multiple small-sized feature maps into a large-sized feature map. The existing neural network for image semantic segmentation does not use the recombination of pixel maps technology, and usually uses upsampling to enlarge the scale of the prediction result, which has a poor amplification effect on the contour edges of thinner stamps and thinner text contours. Recombination of pixel maps was proposed in the field of image super-resolution. It obtains a high-scale result by rearranging low-scale multi-channel data, and there is no information loss compared to the upsampling operation.

[0027] Step S3: The first stage sub-network of stamp extraction is used to predict the coarse-grained stamp background, fine-grained stamp foreground mask, and stamp foreground according to the stamp area and the coarse-grained stamp foreground mask. The stamp area is used as the main input, and the coarse-grained stamp foreground mask is used as the auxiliary input, which is used to reduce the complexity of the task of separating and repairing the stamp foreground and background. Among them, the coarse-grained stamp background is a relatively rough stamp background, and the fine-grained stamp foreground mask is a relatively accurate stamp foreground and background separation result.

[0028] The first stage sub-network of stamp extraction can adopt any neural network used for image processing and having an encoder and a decoder structure, wherein the encoder is used to compress the image to extract image features, and the decoder is used to restore or reconstruct the extracted image features.

[0029] The first stage sub-network of stamp extraction contains an encoder and three decoders. These three decoders are used to predict the rough background, foreground mask and foreground respectively. These three decoders share one encoder to extract image features. Specifically, each decoder contains multiple layers, wherein the first several layers (shallow layers) are used to process the image features extracted by the encoder, and the latter several layers (deep layers) are used to implement their respective functions according to the processed image features. The first several layers of the three decoders used to process image features share parameters, and the parameters come from the image features extracted by the same encoder. The structural design of this neural network can reduce the system processing time and speed up the processing speed. The joint learning of different decoders can improve the learning effect, and maximize resource sharing to avoid duplication and waste of modules.

[0030] Optionally, in this step, the coarse-grained stamp foreground mask is first dilated before being used as the input of the first-stage stamp extraction subnetwork. Dilation refers to a morphological transformation in image processing that expands the edge range of the object according to the degree of dilation. The dilation operation is used to ensure that the coarse-grained stamp foreground mask input to the first-stage stamp extraction subnetwork completely contains the stamp foreground. Even if the edges of the coarse-grained stamp foreground output by the stamp segmentation subnetwork are not so complete and precise, the dilation operation can repair them, which reduces the input requirements of the first-stage stamp extraction subnetwork and improves the robustness of the first-stage stamp extraction subnetwork.

[0031] Step S4: The stamp extraction second stage sub-network is used to predict the fine-grained stamp background according to the coarse-grained stamp background and the fine-grained stamp foreground mask. The stamp extraction second stage self-network adopts a spatial seprated attention mechanism according to the stamp foreground and background distinguished by the fine-grained stamp foreground mask. The spatial seprated attention mechanism refers to distinguishing the attention to the spatial regions of the stamp foreground and background, so that the stamp extraction second stage sub-network pays attention to the information at a specific position in the image, rather than simply applying global attention to the entire image. This enables the stamp extraction second stage sub-network to better understand the relationship between different regions and improve the quality of the processed image. Specifically, it can better handle the separation of the overlapping areas of the stamp foreground and background. The fine-grained stamp background is a more accurate stamp background. The fine-grained stamp foreground mask output by the stamp extraction first stage sub-network, the stamp foreground, and the fine-grained stamp background output by the stamp extraction second stage sub-network are used as the final output of the entire method.

[0032] The stamp extraction second stage sub-network can adopt any neural network for image processing and having an encoder and decoder structure. The stamp extraction first stage sub-network and the stamp extraction second stage sub-network are either two parts of a neural network or two neural networks. The stamp extraction first stage sub-network and the stamp extraction second stage sub-network are trained using the same training data set and are jointly learned and optimized.

[0033] Preferably, in order to achieve a better background restoration effect, this step also introduces a contextual attention (also called contextual attention) mechanism in the second-stage subnetwork of stamp extraction. Contextual attention calculates the similarity between the features of the target position and the features of other surrounding positions, and weightedly fuses the context features according to their importance, so that the second-stage subnetwork of stamp extraction pays more attention to the areas that contribute greatly to the target position in the context information, and uses the information of the surrounding areas to repair the target position, which helps to better preserve the local structure and texture consistency of the generated image. The target position refers to the missing area to be restored, that is, the area where there are traces of erasure after the stamp is erased in the input image.

[0034] The contextual attention mechanism and the spatial analysis attention mechanism are two different technologies. The spatial separation attention mechanism is used to process information at the edges of the foreground and background during image fusion. It uses channel attention and spatial attention. The model can focus on important pixels and channels based on the content and contextual information of the image, so as to better fuse the image. The contextual attention mechanism is used for image inpainting tasks. It learns contextual information about the background from the non-missing areas in the image and uses this information to restore the missing areas. Specifically, the contextual attention mechanism first extracts features through a neural network; then uses the feature representation of the non-missing area to calculate the weight matrix, which describes the correlation between each pixel and other pixels; then the weights are applied to the feature representation to transfer the information of the non-missing area to the missing area.

[0035] See also Figure 2 The system for separating stamps from backgrounds in an image proposed by the present invention includes a stamp detection subnetwork 1, a stamp segmentation subnetwork 2, a stamp extraction first stage subnetwork 3, and a stamp extraction second stage subnetwork 4. Figure 2 The system shown corresponds to Figure 1 The method shown.

[0036] The stamp detection subnetwork 1 is used to locate and crop the stamp area in the input image.

[0037] The stamp segmentation subnetwork 2 is used to predict a coarse-grained stamp foreground mask from the stamp area.

[0038] The stamp extraction first stage sub-network 3 is used to predict the coarse-grained stamp background, the fine-grained stamp foreground mask and the stamp foreground according to the stamp area and the coarse-grained stamp foreground mask.

[0039] The stamp extraction second stage sub-network 4 is used to predict the fine-grained stamp background based on the coarse-grained stamp background and the fine-grained stamp foreground mask. The stamp extraction second stage sub-network 4 adopts a spatial separation attention mechanism based on the stamp foreground and background distinguished by the fine-grained stamp foreground mask.

[0040] Compared with the existing stamp extraction method or stamp foreground and background separation method, the method for separating stamps from backgrounds in an image proposed by the present invention has the following beneficial effects. First, the overall architecture of stamp detection, stamp segmentation, and stamp foreground and background separation is adopted to reduce the complexity of each module. Second, the task of separating the foreground and background of the stamp is divided into two stages (step S3-step S4), which can reduce the learning difficulty of the neural network in each stage and make the final separation effect more accurate. Specifically, step S2 is used to indicate the approximate pixel position of the stamp, which is convenient for subsequent foreground and background separation. This step does not perform foreground and background separation. Step S3 and step S4 are two stages of the same separation task. The first stage is used to obtain preliminary foreground and background separation results, and the second stage is used to refine the foreground and background separation results of the first stage. Black stamps, gray stamps, etc. are similar to the color of text, and it is difficult to distinguish the two by traditional methods. The typical scenario solved by the present invention through two-stage foreground and background separation is the separation of black stamps, gray stamps and text background overlap. Third, the output of the stamp segmentation subnetwork is expanded before being used as the input of the first-stage stamp extraction subnetwork, so that the first-stage stamp extraction subnetwork has lower requirements for input accuracy and higher robustness. Fourth, in the first-stage stamp extraction subnetwork, each decoder shares an encoder, which has higher feature utilization efficiency, and uses multi-task learning to promote each other, which can reduce processing time and simplify the model architecture. Fifth, the second-stage stamp extraction subnetwork uses a spatial attention mechanism combined with a fine-grained stamp foreground mask, which can effectively solve the separation of the stamp foreground and background when they overlap. In addition, the second-stage stamp extraction subnetwork removes the erasure traces in the image after erasing the stamp by refining the background details, thereby repairing the stamp background. The optional contextual attention mechanism provides further repair effects.

[0041] See also Figure 3-Figure 10 This is an example to illustrate the method of separating a stamp from a background in an image proposed by the present invention. For a clearer demonstration, Figure 4-Figure 10 The stamp area is enlarged. Figure 7 , Fig.10 There is a large light-colored area in the image, and a dashed box is added to indicate the edge of the stamp area. Figure 3 is the input image in step S1; Figure 4 is the stamp area output by step S1; Figure 5 is the coarse-grained stamp foreground mask output by step S2; Figure 6 It is the image after dilation of the coarse-grained stamp foreground mask; Figure 7-Figure 9 They are the coarse-grained stamp background, fine-grained stamp foreground mask, and stamp foreground outputted in step S3; Fig.10 is the fine-grained stamp background output by step S4. Figure 3 , Figure 8-Figure 10 It can be found that the present application can achieve satisfactory separation effect for the stamp and background separation task of this example.

[0042] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A method for separating a stamp from a background in an image, characterized in that: The method comprises the following steps: Step S1: Use the stamp detection subnetwork to locate and crop the stamp area in the input image; Step S2: using the stamp segmentation sub-network to predict a coarse-grained stamp foreground mask from the stamp area; the stamp foreground mask refers to a map that uses different values ​​of a certain image parameter to distinguish the stamp foreground and background; Step S3: The first stage sub-network of stamp extraction is used to predict the coarse-grained stamp background, the fine-grained stamp foreground mask, and the stamp foreground according to the stamp area and the coarse-grained stamp foreground mask; Step S4: The second stage sub-network of stamp extraction is used to predict the fine-grained stamp background according to the coarse-grained stamp background and the fine-grained stamp foreground mask, wherein the stamp foreground and background distinguished by the fine-grained stamp foreground mask are distinguished by a spatial separation attention mechanism.

2. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S1, the stamp detection subnetwork adopts a neural network for image target detection.

3. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In the step S1, after the stamp area is cut out, the stamp area is uniformly scaled to a fixed size.

4. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S2, the stamp segmentation subnetwork adopts a neural network for image semantic segmentation, or for visual saliency detection, or for image translation.

5. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S2, after obtaining the coarse-grained stamp foreground mask of the original size, the stamp segmentation sub-network uses the pixel reconstruction technology to reconstruct the coarse-grained stamp foreground mask into a larger size and then outputs it.

6. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S3, the coarse-grained stamp foreground mask is first dilated and then used as the input of the first-stage stamp extraction sub-network.

7. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S3-step S4, the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork both use a neural network for image processing and have an encoder and decoder structure; wherein the encoder is used to compress the image to extract image features, and the decoder is used to restore or reconstruct the extracted image features; the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork are either two parts of a neural network, or two neural networks; the stamp extraction first stage subnetwork and the stamp extraction second stage subnetwork are trained using the same training data set, and are jointly learned and optimized.

8. The method for separating a stamp from a background in an image according to claim 7, characterized in that: In step S3, the first stage sub-network of stamp extraction includes an encoder and three decoders, and the three decoders are used to predict the rough background, foreground mask and foreground respectively, and the three decoders share an encoder to extract image features.

9. The method for separating a stamp from a background in an image according to claim 1, characterized in that: In step S4, the second stage sub-network of stamp extraction also adopts a contextual attention mechanism.

10. A system for separating a stamp from a background in an image, characterized in that: Including stamp detection sub-network, stamp segmentation sub-network, stamp extraction first stage sub-network, stamp extraction second stage sub-network; The stamp detection subnetwork is used to locate and crop the stamp area in the input image; The stamp segmentation subnetwork is used to predict a coarse-grained stamp foreground mask from the stamp area; The first stage sub-network of stamp extraction is used to predict the coarse-grained stamp background, the fine-grained stamp foreground mask and the stamp foreground according to the stamp area and the coarse-grained stamp foreground mask; The second stage sub-network of stamp extraction is used to predict the fine-grained stamp background based on the coarse-grained stamp background and the fine-grained stamp foreground mask, wherein the stamp foreground and background distinguished by the fine-grained stamp foreground mask adopts a spatial separation attention mechanism.

Citation Information

Cited By

  • Remote sensing image aircraft target detection method and device based on visual saliency detection

    CN119762993A

  • Medical image analysis system based on mixed detection mask large model

    CN119863433A