Method and device for generating training samples for a stamp removal model simulating real data

By generating simulated paper seal images through multi-channel color transformation and local blurring, the problem of poor performance of existing seal removal models in paper document recognition is solved. High-quality training data generation is achieved, improving the model's removal accuracy and generalization ability in real-world scenarios.

CN122157276APending Publication Date: 2026-06-05PICC INFORMATION TECH CO LTD +1

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
PICC INFORMATION TECH CO LTD
Filing Date
2026-02-25
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing technologies struggle to generate stamp data from real paper documents, resulting in poor performance of stamp removal models when recognizing paper documents. This is especially true when the stamp overlaps with background text, where the existing synthetic data differs significantly from real data, affecting the model's generalization ability and removal accuracy.

Method used

Simulated paper seal images are generated by multi-channel color transformation and local blurring. Combined with transparency channel information and scale transformation, and random angle rotation, a ternary training sample containing a real background image, a simulated paper seal image, and a corresponding mask image is generated to improve the generalization ability of the seal removal model.

Benefits of technology

It effectively simulates the characteristics of stamps in paper documents, improves the removal accuracy and generalization ability of the stamp removal model in real-world scenarios, generates high-quality training data, and enhances the model's recognition and removal performance in complex backgrounds.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122157276A_ABST
    Figure CN122157276A_ABST
Patent Text Reader

Abstract

The application discloses a seal removal model training sample generation method and device for simulating real data. The method acquires an electronic seal image, and generates a simulated paper seal image with ink gradation and rough edge characteristics based on the electronic seal image through multi-channel color transformation and local blur processing. Transparency channel information of the simulated paper seal image is extracted to generate a binary mask image corresponding to a seal area. According to the size of a target document image and a text area detection result, scale transformation and random angle rotation processing are performed on the simulated paper seal image. The processed simulated paper seal image is superimposed on the detected text area of the target document image to generate a ternary training sample containing a real background image, a simulated paper seal image and a corresponding mask image. The application can effectively simulate the real characteristics of seals in paper documents, and improve the generalization ability and processing precision of a seal removal model in a real scene.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a method and apparatus for generating training samples for a stamp removal model that simulates real data. Background Technology

[0002] When performing OCR recognition on document images, stamps in the image often interfere with text content recognition, leading to errors. Therefore, stamp removal preprocessing is necessary. Currently, available stamp data mainly relies on document scanning or converting electronic PDF files into images, all of which contain stamps. However, relying solely on stamped images is insufficient for model training; therefore, manually synthesized stamp data is typically used. Existing methods involve pasting stamp images onto document images, but this data more closely resembles electronic stamps, causing the model to fail when dealing with images of printed documents.

[0003] To improve the effect of seal removal, especially to remove seals with no or minimal text loss when the seal pattern overlaps with the background text, we need both images of the paper document without the seal and images of the document with the real seal. However, such data is difficult to obtain, so optimizing manually created seal data is essential. Summary of the Invention

[0004] One objective of this invention is to propose a method for generating training samples for a stamp removal model that simulates real data.

[0005] Another objective of this invention is to provide a device for generating training samples for a stamp removal model that simulates real data.

[0006] To achieve the above objectives, a first aspect of the present invention proposes a method for generating training samples for a stamp removal model that simulates real data, comprising:

[0007] S1. Acquire an electronic seal image, and based on the electronic seal image, generate a simulated paper seal image with ink smudging and rough edges through multi-channel color transformation and local blurring processing. S2, extract the transparency channel information of the simulated paper seal image and generate a binarized mask image of the corresponding seal area; S3, based on the size of the target document image and the text region detection results, perform scale transformation and random angle rotation processing on the simulated paper seal image; S4, the processed simulated paper seal image is superimposed onto the detected text region of the target document image to generate a ternary training sample containing a real background image, a simulated paper seal image and a corresponding mask image.

[0008] In one embodiment of the present invention, the multi-channel color transformation in S1 includes: S11, by adjusting the RGBA channel values ​​of the electronic seal image, seal images with different transparency and color distribution are generated, wherein the value range of the transparency channel α is [0.3, 0.8]. S12, based on the color space characteristics of the target document image, performs color space compensation processing on the generated seal image to ensure that the color fusion between the seal and the document background reaches the visual consistency standard of ΔE<3.

[0009] In one embodiment of the present invention, the S3 mesoscale transformation process includes: S31, Calculate the stamp scaling ratio based on the resolution of the target document image, using the following formula: ,in For document image resolution, The resolution of the electronic seal image; S32 uses a bicubic interpolation algorithm for image scaling to maintain the integrity of edge details in the stamp image during the transformation process.

[0010] In one embodiment of the present invention, the image overlay process in S4 includes: S41, using the Gaussian blur formula The seal image is locally blurred, where the σ value is dynamically adjusted according to the scanning quality of the document image, and the value range is [1.2, 3.5]. S42, uses a color space compensation algorithm to correct the brightness of the superimposed image, the formula is as follows: , where ΔB is the brightness difference between the document background and the stamp area.

[0011] In one embodiment of the present invention, it further includes: S5, performs data augmentation on the generated ternary training samples, including: S51, randomly add Gaussian noise, the noise intensity follows a normal distribution. ,in The value range is [0.01, 0.05]; S52 performs a morphological dilation operation on the stamp mask image, with a dilation kernel size of [size missing]. The square structuring element iterates 1-2 times.

[0012] To achieve the above objectives, a second aspect of the present invention provides an apparatus for generating training samples for a stamp removal model that simulates real data, comprising: The image generation module is used to acquire electronic seal images and generate simulated paper seal images with ink smudging and rough edge features through multi-channel color transformation and local blurring processing. The mask generation module is used to extract the transparency channel information of the simulated paper seal image and generate a binary mask image of the corresponding seal area. The image transformation module is used to perform scale transformation and random angle rotation on the simulated paper seal image based on the size of the target document image and the text region detection results. The sample generation module is used to overlay the processed simulated paper seal image onto the detected text region of the target document image to generate a ternary training sample containing the real background image, the simulated paper seal image, and the corresponding mask image.

[0013] The method and apparatus of this invention can effectively simulate the real features of stamps in paper documents, improve the generalization ability and removal accuracy of the stamp removal model in real-world scenarios, and simultaneously achieve efficient and automated generation of training data.

[0014] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0015] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 A flowchart of a method for generating training samples for a stamp removal model that simulates real data, provided in an embodiment of the present invention; Figure 2 An architecture diagram of a method for generating training samples for a stamp removal model that simulates real data, provided in an embodiment of the present invention; Figure 3 This is a structural diagram of a device for generating training samples for a stamp removal model that simulates real data, provided in an embodiment of the present invention. Detailed Implementation

[0016] It should be noted that, unless otherwise specified, the embodiments and features described in the present invention can be combined with each other. The present invention will now be described in detail with reference to the accompanying drawings and embodiments.

[0017] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.

[0018] The following describes, with reference to the accompanying drawings, a method and apparatus for generating training samples for a stamp removal model that simulates real data, according to an embodiment of the present invention.

[0019] Example 1 This embodiment provides a method for generating training samples for a stamp removal model that simulates real data. For example... Figure 1 As shown, the method includes the following steps: S1. Acquire an electronic seal image, and based on this electronic seal image, generate a simulated paper seal image with ink smudging and rough edge features through multi-channel color transformation and local blurring processing. Specifically, this step aims to transform the original electronic seal image into a simulated paper seal image with features such as ink bleeding and rough edges through multi-channel color transformation and local Gaussian blurring, thereby improving the generalization ability of the seal removal model on real document images. In some implementations, this step first performs numerical transformation on the RGBA color channels of the electronic seal image to simulate the differences in different stamping materials and ink colors. Specifically, this is achieved by introducing random offsets into the RGB three channels. This allows the stamp color to no longer be limited to standard electronic image colors, but to more closely resemble the uneven color phenomena in paper documents caused by factors such as ink diffusion and differences in paper absorbency. The color transformation parameter range is usually set to [-15, 15] to ensure that the color change is visually natural and does not compromise the stamp's legibility.

[0020] Furthermore, to simulate the irregularity and local blurring effect of the edges of a paper seal, a local Gaussian blur algorithm is used to process the image. The kernel function of Gaussian blur is defined as:

[0021] in, The mean, The standard deviation controls the degree of fuzziness. In practical applications, The value range is usually [0.5, 2.0]. The blurring area is applied locally by randomly selecting sub-regions of the seal edge, rather than blurring the whole area, in order to preserve the clarity of the seal body while enhancing the irregularity of the edge.

[0022] In practical applications, this step is often used to generate datasets for training stamp removal models, especially when real paper stamp images are lacking. By simulating the characteristics of stamps in real-world scenarios, the model's ability to recognize and remove stamps from scanned or photographed documents can be significantly improved, thus solving the problem of performance degradation caused by significant differences between synthetic and real data in existing technologies.

[0023] Furthermore, S1 includes: S11. By adjusting the RGBA channel values ​​of the electronic seal image, seal images with different transparency and color distribution are generated, wherein the value range of the transparency channel α is [0.3, 0.8].

[0024] Specifically, in step S2, the present invention generates seal images with different transparency and color distributions by adjusting the RGBA color channel values ​​of the electronic seal image, thereby enhancing the diversity and realism of the seal image in simulated real-world scenarios. Specifically, this step introduces a transparency channel α (alpha channel) on top of the original RGB color space of the electronic seal image to achieve a visual fusion effect when the seal image is superimposed on a document image. The value range of the α channel is limited to [0.3, 0.8] to ensure that the seal has a certain degree of visibility without completely obscuring the text content in the document, thus more closely resembling the semi-transparent, partially covered characteristics of seals in paper documents due to uneven pressure, scanning, or blurred images.

[0025] This step first reads the original electronic seal image and converts its color format to RGBA mode to support independent operation of the transparency channel. Then, image processing algorithms are used to randomly sample or gradient-adjust the alpha channel, giving the seal image differentiated transparency in different areas. For example, a Gaussian or uniformly distributed random number generator can be used to modify the pixel values ​​of the alpha channel point by point, resulting in lower transparency in the center area of ​​the seal (e.g., 0.5) and higher transparency in the edge areas (e.g., 0.8), thus simulating the visual effect of blurred edges and a sharp center caused by uneven pressure during actual stamping.

[0026] Regarding parameter indicators, the α channel has a value range of [0.3, 0.8]. This range has been experimentally verified to effectively balance the visibility of the stamp and the legibility of the text. In addition, the color distribution can be adjusted based on the HSV color space. By changing the saturation (S) and lightness (V) values, the uneven color phenomenon caused by ink diffusion or paper reflection in paper documents can be simulated.

[0027] In application scenarios, this step is mainly used to generate synthetic datasets for training the stamp removal model. By adjusting the alpha channel and color distribution, stamp images under different stamping methods (such as wet stamping, dry stamping, scanned documents, and photographed documents) can be simulated, thereby improving the model's generalization ability in complex backgrounds.

[0028] By introducing controllable transparency and color variations, the electronic seal image is made closer to the seal features in real paper documents, thereby improving the realism of the seal and document image superposition in subsequent steps and providing high-quality synthetic samples for training a highly robust seal removal model.

[0029] S12, based on the color space characteristics of the target document image, performs color space compensation processing on the generated seal image to ensure that the color fusion between the seal and the document background reaches the visual consistency standard of ΔE<3.

[0030] Specifically, in some implementations, performing color space compensation processing on the generated seal image based on the color space characteristics of the target document image is a key step in this invention to improve the integration of the seal with the document background. The core technical principle of this step lies in using color space mapping and correction algorithms to ensure that the electronic seal image maintains consistency with the target document image in terms of color distribution, brightness contrast, and hue shift, thereby meeting the visual consistency standard ΔE < 3. ΔE is a color difference metric defined by the CIE (International Commission on Illumination). The smaller the value, the smaller the color difference between the two images as perceived by the human eye. Generally, ΔE < 3 is considered a color difference that is difficult for the human eye to perceive.

[0031] In terms of specific implementation, this step first performs color space analysis on the target document image, extracting parameters such as its dominant hue distribution, average brightness value, and color temperature characteristics. Then, the electronic seal image is converted from its original color space (such as RGB or CMYK) to a color space consistent with the document image (such as sRGB or Adobe RGB), and color mapping adjustments are performed based on the document image's color histogram. Optionally, a color balance algorithm or hue, saturation, and brightness adjustments based on the HSV color space are used to achieve a more natural color transition. Furthermore, a color space compensation function is introduced to perform non-linear mapping on each pixel of the seal image, making its color distribution closer to the local color characteristics of the document image.

[0032] Key parameters involved in color compensation processing include: color space transformation matrix, hue shift angle ΔH (usually controlled within ±5°), saturation adjustment coefficient S_ratio (recommended range 0.8~1.2), and brightness adjustment coefficient L_ratio (recommended range 0.9~1.1). The compensated stamp image must meet the visual consistency standard of ΔE < 3, where ΔE is calculated using the following formula:

[0033] In practical applications, this step is primarily used to generate high-quality training datasets for stamp removal models, especially when simulating paper document stamping scenarios. It ensures that the stamp image's color blends seamlessly with the real document background, thereby improving the model's generalization ability and removal accuracy in real-world scenarios. This color compensation process effectively reduces problems such as abrupt stamp edges and color distortion caused by color mismatch, enhancing the realism and effectiveness of the training data.

[0034] S2, extract the transparency channel information of the simulated paper seal image, and generate a binarized mask image of the corresponding seal area.

[0035] Specifically, the system first extracts the alpha channel information from the processed simulated paper seal image. This alpha channel represents the transparency value of each pixel in the image, typically ranging from 0 to 255, where 0 represents complete transparency and 255 represents complete opacity. In this invention, the alpha channel extraction is achieved by performing channel separation operations on the image using standard image processing libraries (such as OpenCV and PIL). Specifically, functions like `split()` or `cv2.split()` can be used to split the RGBA image into four independent channels: red (R), green (G), blue (B), and transparency (A).

[0036] Furthermore, the extracted alpha channel image is binarized to generate a binary mask image of the stamp region. Binarization typically employs a thresholding method, mapping the transparency value of each pixel in the alpha channel to either 0 or 1 (or 0 and 255), thus clearly distinguishing the stamp region from the background region. In some implementations, adaptive thresholding (such as Otsu's thresholding) or fixed thresholding (such as setting a threshold of 127) can be used. Specifically, if the alpha value of a pixel is greater than the set threshold, it is marked as a stamp region (1 or 255); otherwise, it is marked as a background region (0).

[0037] The binarized mask image generated in this step has clear region division characteristics, and its resolution is consistent with the simulated seal image, typically 256×256 or 512×512 pixels, depending on the size of the document image and the size of the seal overlay area. The accuracy of the mask image directly affects the training effect of the subsequent seal removal model. Therefore, in this invention, by precisely controlling the extraction and binarization of the alpha channel, it is ensured that the mask image can accurately reflect the shape and boundary of the seal, thereby providing a high-quality supervision signal for the model.

[0038] In practical applications, this step is often used to generate a "ground truth" mask image from the training dataset. This mask image, along with the real document image and the image with the stamp, forms a triple input for training a deep learning-based stamp removal model. Using this mask image, the model can learn how to accurately recover the original background content from a document image with a stamp, especially in complex scenarios where the stamp overlaps with the text, showing a significant improvement.

[0039] This step, by extracting the alpha channel and performing binarization, achieves accurate segmentation of the stamp region, providing crucial labeled data for subsequent model training. This effectively improves the generalization ability and recognition accuracy of the stamp removal model on real paper document images.

[0040] S3, based on the size of the target document image and the text region detection results, perform scale transformation and random angle rotation processing on the simulated paper seal image.

[0041] Specifically, in some implementations, the simulated paper seal image is scaled and rotated at random angles to enhance its naturalness and diversity within the context of real document images. This step is technically based on the principles of image geometric transformation, using affine transformation to scale and rotate the seal image in a plane, thereby simulating the varying sizes and random angles of seals during the actual stamping process.

[0042] In the specific implementation, the appropriate scaling ratio of the seal image is first calculated based on the resolution of the target document image and the text region detection results (such as the text region coordinates [x1, x2, y1, y2] obtained through the object detection model). Typically, the diameter of the seal is set to 5% to 15% of the document image width, i.e., the seal size... satisfy ,in This represents the width of the document image. Optionally, bilinear interpolation or bicubic interpolation algorithms can be used for image scaling to preserve the sharpness and edge details of the stamp image.

[0043] Furthermore, after scaling, the seal image is rotated at a random angle. Rotation angle: Usually in The image is randomly selected within a range to simulate the slight tilting that a stamp might cause due to uneven pressure or paper bending during actual stamping. The rotation operation is based on the image center point and uses a rotation matrix. Perform coordinate transformations to ensure that the stamp can still be correctly superimposed on the target document image after rotation.

[0044] In practical applications, this step is mainly used to generate diverse synthetic stamp images to improve the robustness of the stamp removal model under different sizes and angles. Its technical effect lies in introducing scale transformation and random rotation to make the synthetic stamp images closer to the distribution characteristics of stamps in real paper documents, thereby enhancing the generalization ability of the training data and improving the model's stamp removal accuracy and stability in real-world scenarios.

[0045] Furthermore, S3 includes: S31, Calculate the stamp scaling ratio based on the resolution of the target document image, using the following formula: ,in For document image resolution, The resolution of the electronic seal image.

[0046] Specifically, the system performs scaling transformation on the processed electronic seal image based on the resolution of the target document image to ensure that the size of the seal on the document image matches the size of the seal on the paper document in the actual application scenario. The technical implementation of this step is based on an image scaling algorithm, the core of which lies in calculating the scaling factor of the seal based on the resolution ratio, thereby achieving spatial alignment and visual consistency between the seal image and the document image.

[0047] Specifically, this step first obtains the resolution of the target document image. It is usually expressed in pixels, for example or (Such as the common scanning resolution of A4 paper). Simultaneously, acquire the original resolution of the electronic seal image. ,For example or Through the formula The system calculates the scaling ratio of the seal image. This is used for subsequent image scaling operations.

[0048] In some implementations, this scaling operation can employ bilinear interpolation or bicubic interpolation algorithms to resize the image while preserving image quality. For example, when , hour, This means the stamp image needs to be enlarged approximately 4.17 times to match the resolution of the document image. Furthermore, this step also needs to consider the stamp's position within the document image to ensure that the stamp does not extend beyond the document boundaries or affect critical text areas after being overlaid.

[0049] In practical applications, this step is primarily used to generate a synthetic image that matches the size of the stamp in a real paper document, thereby improving the generalization ability of the stamp removal model in real-world scenarios. Through precise resolution matching, it effectively avoids model misjudgment or recognition failure caused by stamps that are too large or too small. Technically, this step provides a standardized image size basis for subsequent random rotation and overlay of stamps.

[0050] S32 uses a bicubic interpolation algorithm for image scaling to maintain the integrity of edge details in the stamp image during the transformation process.

[0051] Specifically, in the technical solution of this invention, a local Gaussian blur algorithm is used to locally blur the processed electronic seal image to simulate the blurring of seal edges and uneven color caused by factors such as uneven stamping pressure, scanning resolution limitations, or blurry photography in paper documents. This step is a key step in realizing the transformation of seal images from electronic features to paper-based features, and has significant technical value.

[0052] Local Gaussian blurring algorithms apply a Gaussian filter to specific regions of an image, weighting the pixel values ​​in that region according to a Gaussian distribution to blur the edges or local areas of a stamp. Specifically, the algorithm first determines the regions to be blurred based on the edge contour information of the stamp image, typically the pixels at the stamp's edge and their neighborhood. Then, it performs a convolution operation on these regions using a Gaussian kernel, where the kernel's size and standard deviation are... It is a key parameter affecting the degree of blur. In some implementations, the size of the Gaussian kernel can be set to... or Standard deviation Available arrive The values ​​were randomly selected to simulate the blurring effect under different stamping pressures and scanning qualities.

[0053] The core formula involved in this step is:

[0054] in, Indicates the position of the Gaussian function The weight value at that point, The mean (usually set to 0). The standard deviation determines the intensity of the blur. The Gaussian kernel weight matrix calculated using this formula is used to perform convolution operations on local regions of the image, thereby achieving an edge blurring effect.

[0055] In application scenarios, this step is typically performed after the stamp image has undergone color transformation and edge roughening to further enhance its similarity to a real paper stamp. For example, in scenarios simulating stamping on scanned or photographed documents, local Gaussian blurring can effectively restore the edge distortion caused by uneven paper or uneven stamping pressure.

[0056] By introducing local Gaussian blur, the synthesized stamp image is made to look more like the stamp in a real paper document, thereby improving the generalization ability and recognition accuracy of the stamp removal model in practical applications. Especially in complex scenarios where the stamp and text overlap, it can significantly reduce the error rate of text information loss.

[0057] S4, the processed simulated paper seal image is superimposed onto the detected text region of the target document image to generate a ternary training sample containing a real background image, a simulated paper seal image and a corresponding mask image.

[0058] Specifically, overlaying the simulated paper seal image, after multi-stage image processing, onto the detected text regions in the target document image is a crucial step in constructing the ternary training samples (real background image, simulated seal image, and seal mask image). This step is technically implemented based on the text region coordinates [x_1, x_2, y_1, y_2] output by the object detection model. An image fusion algorithm precisely embeds the simulated seal image into the densely texted areas of the document image, thereby generating a more realistic document image with a seal.

[0059] In some implementations, this overlay process employs an alpha channel-based image synthesis method. Specifically, the simulated seal image has been processed with local Gaussian blur and random angle rotation to acquire the blurriness and random positional characteristics of a paper seal. During overlay, the target position and size of the seal image within the document image are first determined based on the text region coordinates output by the target detection model. Subsequently, the alpha channel of the seal image is extracted and used as a mask, which is then pixel-level weighted and fused with the RGB channels of the document image, using the following formula:

[0060] in, This represents the pixel values ​​of the overlaid document image. These are the pixel values ​​of the original document image. To simulate the pixel values ​​of a seal image, This is the alpha channel value of the stamp image, ranging from [0, 1], used to control the transparency and coverage of the stamp image on the document image.

[0061] Furthermore, in practical applications, this step needs to consider the resolution of the document image, the aspect ratio of the stamp image, and the alignment of the overlapping areas. Typically, the document image resolution is... The stamp image is scaled according to the text area size of the document image to ensure that the stamp size matches the actual stamping action. During the overlay process, affine or perspective transformations can be optionally introduced to simulate the projection effect of the stamp at different angles and positions, enhancing the diversity of the dataset.

[0062] By precisely overlaying simulated paper seal images onto the text regions of document images, the generated seal-included images realistically reflect the interaction between seals and text in paper documents, thus providing high-quality training samples for subsequent seal removal models. Simultaneously, this method avoids the problem of overly regular seals and inconsistencies with real-world scenarios in traditional artificially synthesized seals, significantly improving the model's generalization ability and removal accuracy on real document images.

[0063] Furthermore, S4 includes: S41, using the Gaussian blur formula The seal image is locally blurred, where the σ value is dynamically adjusted according to the scanning quality of the document image, and the value range is [1.2, 3.5].

[0064] Specifically, in the technical solution of this invention, a Gaussian blur algorithm is used to locally blur the electronic seal image to simulate the real characteristics of seal edges blurring and uneven coloring caused by scanning or photographing in paper documents. This step is technically implemented based on the Gaussian distribution function, whose mathematical expression is:

[0065] in, This represents the coordinate offset of a pixel in an image. The mean of the Gaussian distribution is usually set to 0, which indicates that blurring is performed with the current pixel as the center. The standard deviation controls the degree of blur, with a value ranging from [1.2, 3.5]. This parameter is dynamically adjusted based on the scanning quality of the document image to ensure that the generated blur effect is closer to the real scene. In some implementations, The input document image can be analyzed and automatically set using image quality assessment algorithms (such as PSNR or SSIM) to achieve adaptive blur processing.

[0066] In terms of implementation, this step employs a convolution operation, performing a convolution operation between a Gaussian kernel and a local region of the stamp image. The size of the Gaussian kernel is typically [missing information]. ,in for The integer part is used to ensure coverage of the main blurring area. In a specific implementation, the `GaussianBlur` function in OpenCV or PyTorch can be used to set the `ksize` and `sigmaX` parameters to achieve local blurring of the stamp image.

[0067] In practical applications, this step primarily targets overly sharp or clear areas of the electronic seal image, making it more closely resemble the blurred effect caused by uneven pressure, ink diffusion, or insufficient scanning resolution in paper documents. Furthermore, this blurring process only applies to localized areas of the seal image, rather than blurring the entire image, thus preserving the overall structural features of the seal and preventing seal recognition failure due to excessive blurring.

[0068] This step can significantly improve the realism of the synthesized seal image and enhance the generalization ability and recognition accuracy of the seal removal model when faced with paper document images, thereby solving the problem that the model fails in real-world scenarios due to the overly idealized seal image in existing technologies.

[0069] S42, uses a color space compensation algorithm to correct the brightness of the superimposed image, the formula is as follows: , where ΔB is the brightness difference between the document background and the stamp area.

[0070] Specifically, in some implementations, a local Gaussian blur algorithm is used to perform pixel-level blurring on the processed electronic seal image to simulate the blurring and color unevenness of the seal edges caused by factors such as uneven stamping pressure, scanning resolution limitations, or out-of-focus photography in paper documents. This algorithm applies a weighted average filter to local areas of the image based on a Gaussian distribution function, thereby enhancing its visual consistency in real-world scenarios without destroying the overall structure of the seal. Specifically, the kernel function of Gaussian blur is defined as:

[0071] in, This represents the offset of a pixel in the spatial domain. This is the mean, usually set to 0, indicating that the center pixel is the symmetrical point; The standard deviation controls the degree of blurring, and its value is generally between [1, 3] to simulate different degrees of blurring effects. In practical applications, this algorithm uses a sliding window mechanism to perform convolution operations on local regions of the stamp image, and the window size is usually set to... or To balance computational efficiency with the realism of the fuzzy effect.

[0072] Furthermore, this step plays a crucial role in the image processing workflow. By introducing local blurring, the synthesized stamp image more closely resembles the natural degradation characteristics of stamps in paper documents, thereby improving the generalization ability of subsequent stamp removal models. In specific implementation, the blurring operation can be selectively applied to the edge regions of the stamp image to simulate the local blurring phenomenon caused by uneven contact of the stamp on the paper. This technique, combined with the color unevenness enhancement processing in S3, jointly constructs a realistic stamp image, providing high-quality input for subsequent image overlay and training data generation.

[0073] Furthermore, it also includes: S5 performs data augmentation on the generated ternary training samples.

[0074] Specifically, in some implementations, a local Gaussian blur algorithm is used to blur local pixels of the processed electronic seal image to simulate the blurry edges and uneven colors of the seal caused by factors such as uneven stamping pressure, scanning resolution limitations, or blurry photography in paper documents. This step is based on the principle of Gaussian filtering, and its core lies in applying Gaussian blur to local areas of the image, rather than performing global blurring on the entire image. This enhances the visual realism of the seal in real-world scenarios while preserving its overall shape and positional information.

[0075] Specifically, the local Gaussian blur algorithm first determines the regions to be blurred based on the edge contour information of the seal image. In some implementations, this region can be extracted using edge detection algorithms (such as Canny edge detection) or by masking based on the alpha channel information of the seal. Then, a Gaussian blur operation is applied to these regions, with the blur degree determined by the standard deviation of the Gaussian kernel. and mean Control. The mathematical expression for Gaussian blur is:

[0076] in, Represents the coordinates of a pixel. The mean of the Gaussian distribution is usually set to 0. The standard deviation determines the intensity of the fuzziness. In this invention, The value range is typically set to [1.0, 3.0] to simulate different degrees of blurring. Furthermore, the size of the Gaussian kernel is usually set to... or This ensures that the edges are naturally blurred without compromising the overall structure of the seal.

[0077] In practical applications, this step is particularly suitable for simulating localized blurring of stamps in paper documents caused by uneven stamping pressure, differences in scanning equipment performance, or shooting angle issues. By introducing local Gaussian blur, the generated stamp image is closer to the real scene, thereby improving the generalization ability and recognition accuracy of the stamp removal model in practical applications.

[0078] Furthermore, this step works closely with subsequent image overlay and mask generation steps, providing a crucial image feature enhancement method for generating high-quality training samples. Its technical effect lies in significantly improving the realism of the synthesized seal images, solving the problem in existing technologies where the model fails on real paper document images due to overly clear and well-defined seal images.

[0079] S51, randomly add Gaussian noise, the noise intensity follows a normal distribution. ,in The value range is [0.01, 0.05].

[0080] Specifically, this invention employs a local Gaussian blur algorithm to perform local pixel blurring on the processed electronic seal image to simulate the blurring of seal edges and uneven color caused by factors such as uneven stamping pressure, scanning resolution limitations, or blurry photography in paper documents. This step is technically based on the principle of Gaussian filtering, and its core lies in applying Gaussian blur to specific areas of the image, rather than globally blurring the entire image. This preserves the overall structure of the seal while enhancing its visual realism in real-world scenarios.

[0081] In its specific implementation, the local Gaussian blur module first determines the pixel range to be blurred based on a preset blur region mask, typically the edge of the stamp or a local area. Then, a Gaussian blur kernel is applied to these areas for convolution. The mathematical expression for Gaussian blur is:

[0082] in, Indicates the position of the Gaussian function The weight value at that point, The mean (usually set to 0). The standard deviation determines the degree of fuzziness. In this invention, The value range is [0.01, 0.05] to ensure the blurring effect is visually natural without compromising the seal's legibility. The size of the blur kernel is typically set to [value missing]. or To balance computational efficiency with fuzzy effects.

[0083] In practical applications, this step typically runs within an image processing engine or deep learning framework, such as OpenCV or TensorFlow, supporting batch processing and parameter tuning. By introducing local Gaussian blur, this invention effectively improves the adaptability of the synthesized stamp image in real-world scenarios, providing higher-quality simulated data for subsequent stamp removal model training, thereby enhancing the model's robustness and generalization ability when processing paper document images.

[0084] S52 performs a morphological dilation operation on the stamp mask image, with a dilation kernel size of [size missing]. The square structuring element iterates 1-2 times.

[0085] Specifically, the alpha channel of the generated seal image is extracted and binarized to obtain a seal mask image for subsequent model training. This step employs channel separation and thresholding techniques from image processing. The specific operation is as follows: First, the alpha channel is extracted from the original RGBA format of the seal image after scaling and random rotation in S6. This channel represents the transparency information of the seal area in the image. In some implementations, the alpha channel value typically ranges from 0 to 255, where 0 represents complete transparency and 255 represents complete opacity. By extracting the alpha channel, the shape and boundary information of the seal can be preserved while its color information is removed, thus providing a basis for subsequent mask generation.

[0086] Subsequently, the extracted alpha channel image is binarized, converting it into a single-channel binary image containing only 0 and 255. Binarization typically employs thresholding methods, such as the Otsu algorithm or a fixed threshold method. In this invention, a fixed threshold method may be optionally used, setting pixels in the alpha channel greater than a set threshold (e.g., 127) to 255 (representing the stamp area), and pixels less than or equal to the threshold to 0 (representing the background area). Further, to enhance the connectivity and integrity of the mask image, morphological dilation can be performed on the binarized image. The square structuring element iterates 1-2 times. This operation improves the matching accuracy between the mask image and the actual stamp area by expanding the boundary of the stamp area and compensating for edge breaks or discontinuities that may occur during image synthesis.

[0087] This step is crucial for constructing the training dataset for the stamp removal model. By generating high-quality stamp mask images, the model can be provided with clear stamp region annotations, thus learning the distinguishing features between the stamp and background text more effectively during training. These mask images, along with real document images and images with stamps, constitute triple training samples used for supervised learning tasks such as image inpainting, image segmentation, or image generation.

[0088] This step, by accurately extracting and processing the alpha channel of the seal, ensures that the shape and position of the seal mask image are highly consistent with the synthesized seal image, providing a reliable supervision signal for the model. Simultaneously, the morphological dilation operation enhances the robustness of the seal region to some extent, helping the model maintain high recognition and removal accuracy even when faced with blurred or irregular seals, thereby improving overall training efficiency and model generalization ability.

[0089] The stamp removal model training sample generation method of this invention, which simulates real data, processes electronic stamp images through random color transformation and local Gaussian blur module, so as to realize the purpose of simulating paper document stamp images using electronic stamp images. It can quickly and efficiently obtain stamp image training data that is closer to the real scene, enhance the stamp removal model's effect on real document images, and solve the problem that the model fails to remove stamps from paper documents due to the difficulty in obtaining real data.

[0090] Example 2 This invention also provides an architecture diagram for generating training samples for a stamp removal model that simulates real data. By performing various image processing operations on the original electronic stamp image, it achieves the goal of simulating a stamp in a paper image using the electronic stamp image. Furthermore, it can generate a stamp mask image and a document image with the stamp based on the processed stamp image and document image, enabling the rapid and efficient creation of stamp removal datasets. For example... Figure 2 As shown, the specific process may include the following steps: S101. Generate electronic seal images through software or algorithms, or obtain real document images from paper documents through scanning and photographing methods.

[0091] S102. By transforming the RGBA color channel values, generate different color seal images with transparency information alpha channel based on the electronic seal image in S101.

[0092] S103. Based on the original color of the electronic seal, add features such as rough edges and uneven colors to the image generated in S102 through a random color transformation algorithm.

[0093] S104. Apply local pixel blurring to the image in S103 using a local Gaussian blurring algorithm to simulate the effect of a blurred stamp image. The formula is as follows:

[0094] S105. Based on the actual document image size in S101, scale the image generated in S104 to ensure that the seal size is appropriate.

[0095] S106. Rotate the image generated in S105 at a random angle to simulate the randomness of the position in manual stamping.

[0096] S107. Extract the alpha channel of the image generated in S106, and perform binarization on the single-channel image to obtain the stamp mask image.

[0097] S108. Use an object detection model to detect the text region of the real document and obtain the text region coordinates [x1,x2, y1, y2].

[0098] S109. Overlay the seal generated in S106 onto the detection result area in S108 to generate the seal document image.

[0099] S110. Match the real document image in S101, the stamp mask image in S107, and the stamp document image in S109 to generate a stamp-removed training dataset.

[0100] The stamp removal model training sample generation method of this invention, which simulates real data, processes electronic stamp images through random color transformation and local Gaussian blur module, so as to realize the purpose of simulating paper document stamp images using electronic stamp images. It can quickly and efficiently obtain stamp image training data that is closer to the real scene, enhance the stamp removal model's effect on real document images, and solve the problem that the model fails to remove stamps from paper documents due to the difficulty in obtaining real data.

[0101] Example 3 This invention also provides a device 10 for generating training samples for a stamp removal model that simulates real data, such as... Figure 3 As shown, the device 10 includes: The image generation module 100 is used to acquire an electronic seal image and generate a simulated paper seal image with ink smudging and rough edge features through multi-channel color transformation and local blurring processing. The mask generation module 200 is used to extract the transparency channel information of the simulated paper seal image and generate a binarized mask image of the corresponding seal area. The image transformation module 300 is used to perform scale transformation and random angle rotation processing on the simulated paper seal image based on the size of the target document image and the text region detection results. The sample generation module 400 is used to overlay the processed simulated paper seal image onto the detected text region of the target document image to generate a ternary training sample containing a real background image, a simulated paper seal image, and a corresponding mask image.

[0102] Furthermore, the image generation module is also used for: By adjusting the RGBA channel values ​​of the electronic seal image, seal images with different transparency and color distribution are generated, where the value range of the transparency channel α is [0.3, 0.8]. Based on the color space characteristics of the target document image, color space compensation processing is performed on the generated seal image to ensure that the color blending between the seal and the document background is satisfactory. Visual consistency standards.

[0103] Furthermore, the image transformation module is also used for: The stamp scaling ratio is calculated based on the resolution of the target document image, using the following formula: ,in For document image resolution, The resolution of the electronic seal image; A bicubic interpolation algorithm is used for image scaling to maintain the integrity of edge details in the stamp image during the transformation process.

[0104] Furthermore, the sample generation module is also used for: Using Gaussian blur formula The seal image is locally blurred, where the σ value is dynamically adjusted according to the scanning quality of the document image, and the value range is [1.2, 3.5]. Brightness correction is performed on the superimposed image using a color space compensation algorithm, the formula being: , where ΔB is the brightness difference between the document background and the stamp area.

[0105] Furthermore, it also includes: The data augmentation module is used to perform data augmentation processing on the generated ternary training samples, including: Randomly add Gaussian noise, the noise intensity of which follows a normal distribution. ,in The value range is [0.01, 0.05]; Perform morphological dilation on the stamp mask image, with a dilation kernel size of [size missing]. The square structuring element iterates 1-2 times.

[0106] The stamp removal model training sample generation device of this invention simulates real data and processes electronic stamp images through random color transformation and local Gaussian blur module. It achieves the purpose of simulating paper document stamp images using electronic stamp images. It can quickly and efficiently obtain stamp image training data that is closer to the real scene, enhance the stamp removal model's effect on real document images, and solve the problem that the model fails to remove stamps from paper documents due to the difficulty in obtaining real data.

[0107] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

[0108] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0109] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.

Claims

1. A method for generating training samples for a stamp removal model that simulates real data, characterized in that, include: S1. Acquire an electronic seal image, and based on the electronic seal image, generate a simulated paper seal image with ink smudging and rough edges through multi-channel color transformation and local blurring processing. S2, extract the transparency channel information of the simulated paper seal image and generate a binarized mask image of the corresponding seal area; S3, based on the size of the target document image and the text region detection results, perform scale transformation and random angle rotation processing on the simulated paper seal image; S4, the processed simulated paper seal image is superimposed onto the detected text region of the target document image to generate a ternary training sample containing a real background image, a simulated paper seal image and a corresponding mask image.

2. The method as described in claim 1, characterized in that, The multi-channel color transformation in S1 includes: S11, by adjusting the RGBA channel values ​​of the electronic seal image, seal images with different transparency and color distribution are generated, wherein the value range of the transparency channel α is [0.3, 0.8]. S12, based on the color space characteristics of the target document image, performs color space compensation processing on the generated seal image to ensure that the color fusion between the seal and the document background reaches the visual consistency standard of ΔE<3.

3. The method as described in claim 1, characterized in that, The S3 mesoscale transformation process includes: S31, Calculate the stamp scaling ratio based on the resolution of the target document image, using the following formula: ,in For document image resolution, The resolution of the electronic seal image; S32 uses a bicubic interpolation algorithm for image scaling to maintain the integrity of edge details in the stamp image during the transformation process.

4. The method as described in claim 1, characterized in that, The image overlay process in S4 includes: S41, using the Gaussian blur formula The seal image is locally blurred, where the σ value is dynamically adjusted according to the scanning quality of the document image, and the value range is [1.2, 3.5]. S42, uses a color space compensation algorithm to correct the brightness of the superimposed image, the formula is as follows: , where ΔB is the brightness difference between the document background and the stamp area.

5. The method as described in claim 1, characterized in that, Also includes: S5, performs data augmentation on the generated ternary training samples, including: S51, randomly add Gaussian noise, the noise intensity follows a normal distribution. ,in The value range is [0.01, 0.05]; S52 performs a morphological dilation operation on the stamp mask image, with a dilation kernel size of [size missing]. The square structuring element iterates 1-2 times.

6. A device for generating training samples for a stamp removal model that simulates real data, characterized in that, include: The image generation module is used to acquire electronic seal images and generate simulated paper seal images with ink smudging and rough edge features through multi-channel color transformation and local blurring processing. The mask generation module is used to extract the transparency channel information of the simulated paper seal image and generate a binary mask image of the corresponding seal area. The image transformation module is used to perform scale transformation and random angle rotation on the simulated paper seal image based on the size of the target document image and the text region detection results. The sample generation module is used to overlay the processed simulated paper seal image onto the detected text region of the target document image to generate a ternary training sample containing the real background image, the simulated paper seal image, and the corresponding mask image.

7. The apparatus as claimed in claim 6, characterized in that, The image generation module is also used for: By adjusting the RGBA channel values ​​of the electronic seal image, seal images with different transparency and color distribution are generated, where the value range of the transparency channel α is [0.3, 0.8]. Based on the color space characteristics of the target document image, color space compensation processing is performed on the generated seal image to ensure that the color blending between the seal and the document background is satisfactory. Visual consistency standards.

8. The apparatus as claimed in claim 6, characterized in that, The image transformation module is also used for: The stamp scaling ratio is calculated based on the resolution of the target document image, using the following formula: ,in For document image resolution, The resolution of the electronic seal image; A bicubic interpolation algorithm is used for image scaling to maintain the integrity of edge details in the stamp image during the transformation process.

9. The apparatus as claimed in claim 6, characterized in that, The sample generation module is also used for: Use Gaussian blur formula The seal image is locally blurred, where the σ value is dynamically adjusted according to the scanning quality of the document image, and the value range is [1.2, 3.5]. Brightness correction is performed on the superimposed image using a color space compensation algorithm, the formula being: , where ΔB is the brightness difference between the document background and the stamp area.

10. The apparatus as claimed in claim 6, characterized in that, Also includes: The data augmentation module is used to perform data augmentation processing on the generated ternary training samples, including: Randomly add Gaussian noise, the noise intensity of which follows a normal distribution. ,in The value range is [0.01, 0.05]; Perform morphological dilation on the stamp mask image, with a dilation kernel size of [size missing]. The square structuring element iterates 1-2 times.