A method, apparatus, device and storage medium for removing a stamp.

By clustering and color-filling the stamp area in the LAB color space, the problem of poor text recognition accuracy caused by stamp interference is solved, and the stamp area is effectively removed and the accuracy of text recognition is improved.

CN116386048BActive Publication Date: 2025-12-02BEIJING SHANGYIN MICRO CORE TECH CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202310354894.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-04-04
Publication Date
2025-12-02
Estimated Expiration
2043-04-04

AI Technical Summary

Technical Problem

Existing technologies struggle to effectively remove the problem of poor text recognition accuracy caused by seal interference, especially when the seal covers the text. Existing training samples are unable to simulate complex seal interference scenarios, resulting in poor recognition performance of text recognition devices.

Method used

By acquiring the RGB image of the stamp area, converting it to the LAB color space, and using a clustering algorithm to divide the pixels into four clusters: red stamp body, red stamp edge, background, and black text, the non-overlapping pixels are found and filled with the set color to remove the non-overlapping parts of the stamp area.

Benefits of technology

By preserving the overlapping areas of the seal and text, the interference from the seal is reduced, improving the accuracy of text recognition. This effectively removes the seal area and enhances the text recognition performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116386048B_ABST
    Figure CN116386048B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, device, and storage medium for removing red stamps covering black text in a target file. Specifically, the RGB image of the stamp area in the target file is converted into a LAB image. Based on the color space characteristics of each pixel in the LAB image, the pixels are divided into four categories: red stamp body, red stamp edge, background, and black text. Based on the color space characteristics of the pixels, especially the A and L channel values, target pixels are determined among the pixels belonging to the red stamp. The set of target pixels corresponds to the non-overlapping part of the stamp and black text. The overlapping part is retained in the RGB image of the stamp area, and the non-overlapping part is filled with a set color. This preserves the text information and reduces stamp interference. Therefore, text recognition of the target file processed by this method can improve the accuracy of text recognition.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of image processing technology, and more specifically, to a method, apparatus, device and storage medium for removing stamps. Background Technology

[0002] When automating the review of contracts and other documents, the paper documents are typically scanned into electronic images first. Then, text recognition devices such as OCR are used to perform text recognition on the electronic documents, and the review is based on the results. Therefore, the accuracy of the text recognition determines whether the automated review task can be accomplished. However, in real-world scenarios, text on a page is often covered by stamps, and the area covered by the stamp may be the core content area of ​​the document. The overlapping text covered by the stamp may have complex textures and varying colors, and the interference from the stamp makes the text recognition effect poor and the accuracy low.

[0003] Although text recognition devices can be retrained using training samples with seal interference to improve their accuracy in recognizing text from electronic documents with seal interference, the situation of seal interference in real-world scenarios is complex and diverse, making it difficult to simulate a large number of training samples. Furthermore, the retraining of text recognition devices is also quite challenging. Therefore, it is difficult to solve the problem of poor text recognition accuracy caused by seal interference. Summary of the Invention

[0004] In view of the above problems, this application is made to provide a method, apparatus, device and storage medium for removing stamps from documents, reducing the interference of stamps on text recognition and improving the accuracy of text recognition.

[0005] The specific plan is as follows:

[0006] Firstly, a method for removing a seal is provided, the method comprising:

[0007] Obtain the RGB image of the stamp area in the target file;

[0008] The RGB image of the stamp area is converted to a color space to obtain a LAB image;

[0009] If the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, the pixels are clustered based on the color space characteristics of each pixel in the LAB image to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively.

[0010] In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the set L channel baseline value.

[0011] In the RGB image of the stamp area, the pixels corresponding to each target pixel are filled with a set color to obtain the target RGB image of the stamp area.

[0012] Secondly, a stamp removal device is provided, the device comprising:

[0013] The stamp image acquisition unit is used to acquire the RGB image of the stamp area in the target file;

[0014] The color space conversion unit is used to convert the RGB image of the stamp area to a color space to obtain a LAB image.

[0015] The pixel clustering unit is used to cluster each pixel in the LAB image based on the color space characteristics of each pixel in the LAB image when the maximum A channel value of each pixel is greater than a preset threshold, to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively.

[0016] The target pixel determination unit is used to find target pixels whose L channel value is greater than the set L channel reference value in the clusters corresponding to the cluster centers with the largest and second largest A channel values.

[0017] The target pixel filling unit is used to fill the pixels corresponding to each target pixel in the RGB image of the stamp area with a set color to obtain the target RGB image of the stamp area.

[0018] Thirdly, a stamp removal device is provided, including: a memory and a processor;

[0019] The memory is used to store programs;

[0020] The processor is used to execute the program to implement each step of the above-described stamp removal method.

[0021] Fourthly, a storage medium is provided on which a computer program is stored, which, when executed by a processor, implements the various steps of the above-described seal removal method.

[0022] Using the above technical solution, this application can be applied to remove red stamps covering black text in a target file. Specifically, firstly, an RGB image of the stamp area in the target file is obtained; the RGB image of the stamp area is then converted to a color space to obtain a LAB image. The A channel in the LAB channel can highlight red features, and the L channel can highlight black features. Based on this, if the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, it can be characterized that a red stamp exists in the LAB image. Then, based on the color space characteristics of each pixel in the LAB image, each pixel is clustered to obtain four clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background, and the black text, respectively. It should be noted that the background refers to a class of pixels with high L channel values ​​and low A channel values, and the black text refers to a class of pixels with low L channel values, or pixels that are close to black. Then, in the clusters corresponding to the cluster centers with the largest and second largest A channel values, i.e., the clusters corresponding to the red stamp body and the red stamp edge, target pixels with L channel values ​​greater than a set L channel reference value are found. The target pixels are those that do not belong to the overlapping part of the red stamp and the black text. Finally, in the RGB image of the stamp area, the pixels corresponding to each of the target pixels are filled with a set color to obtain the target RGB image of the stamp area. This method can remove the non-overlapping parts in the RGB image of the stamp area while retaining the overlapping part of the stamp and the text, thus preserving the text information and reducing stamp interference. Therefore, applying the solution of this application to process the stamp area in the target file and then performing text recognition on the processed target file can improve the accuracy of text recognition for target files with stamp interference. Attached Figure Description

[0023] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings:

[0024] Figure 1 A schematic flowchart illustrating a stamp removal method provided in an embodiment of this application;

[0025] Figure 2 A schematic flowchart illustrating another seal removal method provided in this application embodiment;

[0026] Figure 3 A schematic flowchart illustrating another stamp removal method provided in this application embodiment;

[0027] Figure 4a An image of the stamped area where the text is covered by the stamp is shown;

[0028] Figure 4b The image shows the stamped area after the stamp has been removed;

[0029] Figure 5 This is a schematic diagram of the structure of a stamp removal device provided in an embodiment of this application;

[0030] Figure 6 This is a schematic diagram of the structure of the stamp removal device provided in an embodiment of this application. Detailed Implementation

[0031] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0032] This application discloses a method, apparatus, device, and storage medium for removing stamps, which can remove red stamps covering black text in a target document.

[0033] In the LAB color space, the L channel value represents brightness, ranging from black to white. The A channel value ranges from green to red, and the B channel value ranges from blue to yellow. Therefore, by using the A channel value of a pixel in a LAB image, red features can be highlighted; the L channel value can highlight black features; and the B channel value can highlight blue features. In practical scenarios, documents such as contracts and reports are typically white with black text, and stamps are usually red. The LAB color space can be used to distinguish between black text, white backgrounds, and red stamps in these documents, allowing for the removal of red stamps.

[0034] The proposed solution can be implemented based on a terminal with data processing capabilities, such as a computer, server, or cloud platform.

[0035] Figure 1 This is a schematic flowchart illustrating a stamp removal method according to an embodiment of this application, such as... Figure 1 As shown, the method may include the following steps:

[0036] Step S101: Obtain the RGB image of the stamp area in the target file.

[0037] The RGB image of the stamp region can refer to the RGB image of the target file containing the stamp, or it can refer to the RGB image of the stamp cropped from the RGB image of the target file. It should be noted that the number of pixels in the RGB image of the target file is much larger than the number of pixels in the RGB image of the stamp. Therefore, compared to performing subsequent steps on the RGB image of the target file, performing subsequent steps on the RGB image of the stamp can reduce the computational load and improve the efficiency of stamp removal.

[0038] Step S102: Perform color space conversion on the RGB image of the stamp area to obtain a LAB image.

[0039] It should be noted that converting an RGB image to a LAB image requires the use of the XYZ color space. Specifically, the RGB image of the stamp area is converted into the corresponding XYZ image, and then the XYZ image is converted into a LAB image.

[0040] The number of pixels in an image is equal to the product of the image's height and width. Each pixel in an image has its own color space characteristics. That is, pixels in an RGB image have RGB color space characteristics, and pixels in a LAB image have LAB color space characteristics. For RGB color space characteristics, the value range of each channel is [0, 255]. For LAB color space characteristics, the value range of the L channel is [0, 100], and the value range of the A and B channels is [-128, 127].

[0041] Step S103: Determine whether the maximum A channel value of each pixel in the LAB image is greater than a preset threshold. If so, proceed to step S104.

[0042] It should be noted that if the maximum value of the A channel of each pixel in the LAB image exceeds a preset threshold, it can be characterized by the presence of red features in the LAB image. Since the LAB image is an image of a stamp area and the stamp is mostly red, it can be determined that there is a red stamp in the LAB image. If the maximum value of the A channel of each pixel in the LAB image does not exceed the preset threshold, it can be considered that there is no red stamp in the LAB image, and subsequent steps are not performed. For example, subsequent steps are not performed on the black stamp in the target file.

[0043] Step S104: Based on the color space features of each pixel in the LAB image, cluster each pixel to obtain 4 clusters and their cluster centers.

[0044] It should be noted that if three clusters are set, each representing the red stamp, black text, and background respectively, the color space characteristics of the pixels forming the edge of the red stamp are not obvious. They may be classified as either the red stamp or the black text, making it difficult to obtain accurate clusters and resulting in poor stamp removal. Therefore, the number of clusters is set to four, with each cluster representing the red stamp body, the red stamp edge, the background, and the black text respectively. The background can refer to pixels with high L channel values ​​and low A channel values, while the black text can refer to pixels with low L channel values ​​or pixels that are close to black.

[0045] Optionally, the K-means++ clustering algorithm can be applied to determine four cluster centers based on the distance between the color space features of each pixel, and to group pixels with similar features into one cluster.

[0046] Step S105: In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the set L channel reference value.

[0047] It should be noted that the cluster corresponding to the cluster center with the largest A-channel value represents the red stamp body, and the cluster corresponding to the cluster center with the second largest A-channel value represents the red stamp edge. A red stamp can be formed by the red stamp body and the red stamp edge. However, these two types of clusters may contain overlapping parts of the stamp and text. When removing the stamp, it is necessary to retain the overlapping parts of the stamp and text, and remove the non-overlapping parts to avoid missing text and reduce stamp interference. Since the L-channel value of a pixel represents brightness, the smaller the L-channel value, the closer the color of the pixel is to black, and the greater the probability that the pixel belongs to black text. Based on this, in the cluster representing the red stamp, the pixels with L-channel values ​​larger than the L-channel baseline value are the target pixels to be removed.

[0048] Step S106: In the RGB image of the stamp area, fill the pixels corresponding to each of the target pixels with a set color to obtain the target RGB image of the stamp area.

[0049] It should be noted that this application implements a stamp removal task by filling the non-overlapping areas of the stamp and text with a set color. Optionally, the set color can be set according to the background of the target file. For example, considering practical applications, the background of the target file to which the stamp is to be removed is usually white, and the set color can be white.

[0050] The above-described stamp removal method first obtains the RGB image of the stamp area in the target file; then, it performs color space conversion on the RGB image of the stamp area to obtain a LAB image. The A channel in the LAB image highlights red features, and the L channel highlights black features. Based on this, if the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, it indicates the presence of a red stamp in the LAB image. Then, based on the color space characteristics of each pixel in the LAB image, the pixels are clustered to obtain four clusters and their cluster centers. These clusters are used to represent the red stamp body, the red stamp edge, the background, and the black text, respectively. Finally, in the clusters corresponding to the cluster centers with the largest and second largest A channel values, i.e., those with red stamps... In the clusters corresponding to the red stamp body and the edge of the red stamp, target pixels with L channel values ​​greater than a set L channel reference value are found. These target pixels belong to the non-overlapping part of the red stamp and the black text. Finally, in the RGB image of the stamp area, the pixels corresponding to each target pixel are filled with a set color to obtain the target RGB image of the stamp area. This method can remove the non-overlapping part of the RGB image of the stamp area while preserving the overlapping part of the stamp and the text. This preserves the text information and reduces stamp interference. Therefore, applying the solution of this application to process the stamp area in the target file and then performing text recognition on the processed target file can improve the accuracy of text recognition for target files with stamp interference.

[0051] In some embodiments provided in this application, step S104 above, which involves clustering each pixel based on the color space features of each pixel in the LAB image to obtain four clusters and their cluster centers, may include:

[0052] Step S11: Based on the distance between the color space features of each pixel in the LAB image, a clustering algorithm is used to determine four cluster centers.

[0053] Step S12: Based on the distance of each pixel in the LAB image to the color space features between the four cluster centers, determine the cluster center to which each pixel belongs, and obtain four clusters.

[0054] Optionally, between steps S11 and S12, a determination can be made regarding whether a red stamp exists in the LAB image. Specifically, it can be determined whether the maximum value of the A channel value among the four cluster centers is greater than a preset threshold. If so, it indicates that a red stamp exists in the LAB image, and subsequent steps are executed; otherwise, subsequent steps are not executed. For example, the preset threshold can be set to 20.

[0055] In some embodiments provided in this application, step S12 above, determining the cluster center to which each pixel belongs based on the distance of color space features between each pixel in the LAB image and the four cluster centers to obtain four clusters, may include the following steps:

[0056] Step S21: Obtain the feature matrix composed of the color space feature vectors of each pixel in the LAB image and the color space feature vectors of each of the four cluster centers.

[0057] The color space feature vector is a vector representation of the color space features, the feature matrix can be represented as X, and the color space feature vector of cluster center i can be represented as C. i , i = 0, 1, 2, 3.

[0058] Step S22: For each cluster center C i For i = 0, 1, 2, 3, matrix operations are used to determine the cluster centers C based on the feature matrix and the cluster centers. i The color space feature vector is used to calculate the distance between the color space features of each pixel in the LAB image and the cluster center.

[0059] Optionally, step S22 above can be implemented using the matrix operation tool NumPy. For example, the distance D of the color space features between each pixel in the LAB image and the cluster center i (i = 0, 1, 2, 3) is... i The calculation formula is: D i =np.sqrt(np.sum(np.power(XC) i ,2))).reshape((1,-1)), where np.power(XC i 2) The calculation calculates the color space features of each channel of the LAB image pixels and the cluster center C. i The sum of squares of the distances between the color space features of each channel is calculated using `np.sum()`, while `np.sqrt()` calculates the square root. The result is calculated from the distances between each pixel and the cluster center C. i An array of Euclidean distances of color space features is used to perform a .reshape() operation on the array to obtain a vector of [1,n] dimensions for subsequent vector fusion. The parameter n is the number of pixels in the LAB image.

[0060] It should be noted that although the distance between the color space features of each pixel and each cluster center in the LAB image can be calculated by performing a double loop traversal on all pixels and all cluster centers, this calculation method has high time complexity. By representing the color space features of each pixel as a feature matrix and then using matrix operations to perform the calculation task for all pixels, the calculation speed can be improved.

[0061] Step S23: For each pixel in the LAB image, find the target distance with the smallest value among the distances of the color space features between the pixel and the four cluster centers, and determine the cluster center corresponding to the target distance as the cluster center to which the pixel belongs, thus obtaining four clusters.

[0062] Optionally, step S23 above can be implemented using the matrix operation tool NumPy. Specifically, the formula for calculating the cluster center L corresponding to each pixel of the LAB image is: L = np.argsort(np.concatenate((D0,D1,D2,D3),axis=0),axis=0)[0], where np.concatenate((D0,D1,D2,D3),axis=0) means merging vectors D0, D1, D2 and D3 by row, np.argsort(,axis=0) means sorting vectors by column, and L is the cluster center corresponding to the target distance of each pixel, that is, the cluster center corresponding to the minimum distance.

[0063] For example, the clusters corresponding to the four cluster centers can be determined based on the A channel values ​​of the four cluster centers. As the A channel values ​​increase, the clusters corresponding to the four cluster centers are represented by the background, black text, red stamp edge, and red stamp body, respectively.

[0064] In some embodiments provided in this application, the stamp removal method may further include:

[0065] Among the four cluster centers, the second cluster center with the largest L channel value is found, and the background color of the target file is determined based on the color space characteristics of each pixel in the cluster corresponding to the second cluster center.

[0066] It should be noted that most document backgrounds tend to be white or gray, which are colors with high brightness values. Therefore, the background color can be determined based on the L channel value.

[0067] Optionally, the color of the second cluster center with the largest L channel value can be used as the background color.

[0068] Based on the above, filling the pixels corresponding to each target pixel point in the RGB image of the stamp area with a set color may include:

[0069] In the RGB image of the stamp area, the background color is used to fill the pixels corresponding to each of the target pixels.

[0070] It should be noted that using the background color determined by the clusters representing the background as the fill color can result in a more harmonious target RGB image, which is beneficial for subsequent text recognition.

[0071] Figure 2 This is a flowchart illustrating another stamp removal method according to an embodiment of this application, combined with... Figure 2 As shown, the method may include the following steps:

[0072] Step S201: Determine the target location of the stamp area in the RGB image of the target file.

[0073] The RGB image of the target file can be represented as an image array. For example, an image array representing the RGB image of the target file can be generated by decoding and converting the target file's base64 stream. Alternatively, it can be generated by reading the target file, which is an image or PDF file whose input path is a local file path. Specifically, the type of the target file can be determined based on its extension. For target files with extensions of jpg, jpeg, or png, the image can be read directly. For target files with extensions of pdf, the pages of the target file are split into corresponding images, and then each image is read to obtain an image array representing the RGB image of the target file.

[0074] Optionally, step S201 above can be implemented using a pre-trained stamp detection model. Before inputting the RGB image of the target file into the stamp detection model, the RGB image of the target file needs to be pre-processed. The pre-processing includes:

[0075] The first step is to scale the RGB image of the target file to a standard size, which is determined by the input size of the stamp detection model. For example, the standard size can be 608*608 pixels.

[0076] The second step is to standardize the scaled image. It should be noted that a standardized image has a more uniform distribution of color space features. Specifically, the formula for this standardization process is (X... i -μ) / σ,X iThe scaling factor is calculated by dividing each channel value of the RGB image by 255, μ is the mean calculated from the ImageNet dataset, and σ is the variance calculated from the ImageNet dataset. The reason for this standardization step is that image samples were standardized during the training of the stamp detection model. By reducing the color space feature distribution of the image from [0,255] to [-1,1], the distribution of color space features becomes more concentrated and uniform, which can improve the model's generalization ability.

[0077] The third step is to perform an array arrangement transformation on the standardized image, converting the height-width channel dimension order HWC to channel height-width CHW. The reason for performing this array arrangement transformation is that the stamp detection model can be a neural network model, for example, a YOLOv3 network with Darknet53 as the backbone network. In the input data of the neural network model, the channel dimension is generally located before the height and width.

[0078] By processing the RGB image of the target file using the seal detection model, the target category, target position coordinates, and target confidence score of the seal can be obtained. The target category can include round, elliptical, rectangular, and square seals. If the obtained target confidence score is greater than a set threshold, the target position coordinates of the seal are output, representing the target location; otherwise, the seal target is discarded. It should be noted that the seal detection model can detect at least one seal on a page, meaning that several target position coordinates can be output simultaneously.

[0079] Step S202: Crop the RGB image of the target file according to the target position to obtain the RGB image of the stamp area.

[0080] Steps S203-S207 are the same as steps S102-S106 described above, and will not be repeated here.

[0081] Step S208: Replace the RGB image of the stamp region in the RGB image of the target file with the target RGB image of the stamp region.

[0082] The above-described stamp removal method can achieve page-level stamp removal tasks. Specifically, for cases where there is at least one stamped area on the same page, steps S203-S208 can be performed on each stamped area separately, ultimately obtaining an image with all stamps removed. Inputting this object into an existing text recognition device can yield more accurate text recognition results.

[0083] In some embodiments provided in this application, step S201, determining the target location of the stamp area in the RGB image of the target file, may include the following steps:

[0084] Step S31: Standardize the RGB values ​​of each pixel in the RGB image of the target file to obtain the target file image.

[0085] The description of standardization processing can be found above.

[0086] Step S32: Determine the target location of the stamp area based on the target file image.

[0087] Figure 3 This is a flowchart illustrating another stamp removal method according to an embodiment of this application, combined with... Figure 3 As shown, the method may include the following steps:

[0088] Steps S301-S304 are the same as steps S101-S104 above, and will not be repeated here.

[0089] Step S305: Determine the L-channel reference value based on the color space characteristics of each pixel in the cluster corresponding to the first cluster center with the smallest L-channel value among the four cluster centers.

[0090] Specifically, among the four cluster centers, the first cluster center with the smallest L-channel value is found, and the maximum value of the L-channel value of each pixel in the cluster corresponding to the first cluster center is determined as the L-channel reference value.

[0091] Alternatively, the minimum value among the L-channel values ​​of the four cluster centers can be determined as the L-channel baseline value.

[0092] It should be noted that in the clusters representing black text, the L-channel values ​​of each pixel are mostly concentrated. Therefore, based on the L-channel values ​​of each pixel in the cluster corresponding to the first cluster center, the L-channel reference value that can reflect the L-channel values ​​of general black text in the target file can be determined. Specifically, the L-channel reference value can be the maximum L-channel value in the cluster representing black text, or it can be the median value of the L-channel values ​​of each pixel in the cluster representing black text, i.e., the L-channel value of the first cluster center.

[0093] It should be noted that in some target files, there may be some black text that is blurred, not clear enough, or has varying brightness. Therefore, when removing the stamp, some outlier pixels belonging to overlapping areas may not be preserved.

[0094] Step S306: In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the L channel reference value.

[0095] Other descriptions of step S306 can refer to step S105 above.

[0096] Step S307 is the same as step S106 described above, and will not be repeated here.

[0097] For example, Figure 4a The image shows an area of ​​text covered by a stamp. Figure 4b It is shown that the application of the solution of this application is used for Figure 4a The image of the stamped area shown is processed to obtain the image of the stamped area after the stamp is removed.

[0098] The stamp removal apparatus provided in the embodiments of this application is described below. The stamp removal apparatus described below can be referred to in correspondence with the stamp removal method described above.

[0099] See Figure 5 , Figure 5 This is a schematic diagram of the structure of a stamp removal device disclosed in an embodiment of this application.

[0100] like Figure 5 As shown, the device may include:

[0101] The seal image acquisition unit 11 is used to acquire the RGB image of the seal area in the target file;

[0102] Color space conversion unit 12 is used to perform color space conversion on the RGB image of the stamp area to obtain a LAB image;

[0103] The pixel clustering unit 13 is used to cluster each pixel in the LAB image based on the color space characteristics of each pixel in the LAB image when the maximum A channel value of each pixel is greater than a preset threshold, to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively.

[0104] The target pixel determination unit 14 is used to find each target pixel whose L channel value is greater than the set L channel reference value in the cluster corresponding to the cluster center with the largest and second largest A channel values.

[0105] The target pixel filling unit 15 is used to fill the pixels corresponding to each target pixel in the RGB image of the stamp area with a set color to obtain the target RGB image of the stamp area.

[0106] In some embodiments provided in this application, the process by which the pixel clustering unit 13 clusters each pixel based on the color space features of each pixel in the LAB image to obtain four clusters and their cluster centers may include:

[0107] Based on the distance between the color space features of each pixel in the LAB image, four cluster centers are determined using a clustering algorithm;

[0108] Based on the distance of each pixel in the LAB image to the color space features between it and the four cluster centers, the cluster center to which each pixel belongs is determined, resulting in four clusters.

[0109] In some embodiments provided in this application, the pixel clustering unit 13 determines the cluster center to which each pixel belongs based on the distance of color space features between each pixel in the LAB image and the four cluster centers, and obtains four clusters. This process may include:

[0110] Obtain a feature matrix composed of the color space feature vectors of each pixel in the LAB image and the color space feature vectors of each of the four cluster centers, wherein the color space feature vectors are vector representations of color space features;

[0111] For each cluster center, matrix operations are used to calculate the distance between each pixel in the LAB image and the cluster center based on the feature matrix and the color space feature vector of the cluster center;

[0112] For each pixel in the LAB image, among the distances in color space features between the pixel and the four cluster centers, find the target distance with the smallest value, and determine the cluster center corresponding to the target distance as the cluster center to which the pixel belongs, thus obtaining four clusters.

[0113] In some embodiments provided in this application, the process by which the seal image acquisition unit 11 acquires the RGB image of the seal area in the target file may include:

[0114] In the RGB image of the target file, determine the target location of the stamp area;

[0115] The RGB image of the target file is cropped according to the target location to obtain the RGB image of the stamp area;

[0116] Based on the above, the device may further include an image restoration unit, which, after obtaining the target RGB image of the stamp area, replaces the RGB image of the stamp area in the RGB image of the target file with the target RGB image of the stamp area.

[0117] In some embodiments provided in this application, the process by which the seal image acquisition unit 11 determines the target location of the seal area in the RGB image of the target file may include:

[0118] The RGB values ​​of each pixel in the RGB image of the target file are standardized to obtain the target file image.

[0119] Based on the target file image, determine the target location of the stamp area.

[0120] In some embodiments provided in this application, the stamp removal device may further include an L-channel reference value determination unit, which is used to determine the minimum value among the L-channel values ​​of the four cluster centers as the L-channel reference value, or to find the first cluster center with the smallest L-channel value among the four cluster centers, and determine the maximum value among the L-channel values ​​of each pixel in the cluster corresponding to the first cluster center as the L-channel reference value.

[0121] In some embodiments provided in this application, the stamp removal device may further include a fill color determination unit, which is used to find the second cluster center with the largest L channel value among the four cluster centers, and determine the background color of the target file according to the color space characteristics of each pixel in the cluster corresponding to the second cluster center.

[0122] Based on the above, the process by which the target pixel filling unit 15 fills the pixels corresponding to each target pixel in the RGB image of the stamp area using a set color may include:

[0123] In the RGB image of the stamp area, the background color is used to fill the pixels corresponding to each of the target pixels.

[0124] The seal removal device provided in this application embodiment can be applied to seal removal equipment, such as terminals: mobile phones, computers, etc. Optionally, Figure 6 The hardware structure block diagram of the stamp removal device is shown, with reference to... Figure 6 The hardware structure of the stamp removal device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4;

[0125] In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4;

[0126] Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention.

[0127] Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device;

[0128] The memory stores a program, which the processor can call. The program is used for:

[0129] Obtain the RGB image of the stamp area in the target file;

[0130] The RGB image of the stamp area is converted to a color space to obtain a LAB image;

[0131] If the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, the pixels are clustered based on the color space characteristics of each pixel in the LAB image to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively.

[0132] In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the set L channel baseline value.

[0133] In the RGB image of the stamp area, the pixels corresponding to each target pixel are filled with a set color to obtain the target RGB image of the stamp area.

[0134] Optionally, the refined and extended functions of the program can be found in the description above.

[0135] This application embodiment also provides a storage medium that can store a program suitable for execution by a processor, the program being used for:

[0136] Obtain the RGB image of the stamp area in the target file;

[0137] The RGB image of the stamp area is converted to a color space to obtain a LAB image;

[0138] If the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, the pixels are clustered based on the color space characteristics of each pixel in the LAB image to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively.

[0139] In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the set L channel baseline value.

[0140] In the RGB image of the stamp area, the pixels corresponding to each target pixel are filled with a set color to obtain the target RGB image of the stamp area.

[0141] Optionally, the refined and extended functions of the program can be found in the description above.

[0142] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0143] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0144] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for removing a stamp, characterized in that, include: Obtain the RGB image of the stamp area in the target file; The RGB image of the stamp area is converted to a color space to obtain a LAB image; If the maximum A channel value of each pixel in the LAB image is greater than a preset threshold, the pixels are clustered based on the color space characteristics of each pixel in the LAB image to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively. In the clusters corresponding to the cluster centers with the largest and second largest values ​​in the A channel, find the target pixels whose L channel values ​​are greater than the set L channel baseline value. The cluster corresponding to the cluster center with the largest A channel value represents the red stamp body, and the cluster corresponding to the cluster center with the second largest A channel value represents the red stamp edge. The red stamp is composed of the red stamp body and the red stamp edge. In the RGB image of the stamp area, the pixels corresponding to each target pixel are filled with a set color to obtain the target RGB image of the stamp area.

2. The method according to claim 1, characterized in that, Based on the color space features of each pixel in the LAB image, the pixels are clustered to obtain four clusters and their cluster centers, including: Based on the distance between the color space features of each pixel in the LAB image, four cluster centers are determined using a clustering algorithm; Based on the distance of each pixel in the LAB image to the color space features between it and the four cluster centers, the cluster center to which each pixel belongs is determined, resulting in four clusters.

3. The method according to claim 2, characterized in that, Based on the distance of each pixel in the LAB image to the four cluster centers in terms of color space features, the cluster center to which each pixel belongs is determined, resulting in four clusters, including: Obtain a feature matrix composed of the color space feature vectors of each pixel in the LAB image and the color space feature vectors of each of the four cluster centers, wherein the color space feature vectors are vector representations of color space features; For each cluster center, matrix operations are used to calculate the distance between each pixel in the LAB image and the cluster center based on the feature matrix and the color space feature vector of the cluster center; For each pixel in the LAB image, among the distances in color space features between the pixel and the four cluster centers, find the target distance with the smallest value, and determine the cluster center corresponding to the target distance as the cluster center to which the pixel belongs, thus obtaining four clusters.

4. The method according to claim 1, characterized in that, The step of obtaining the RGB image of the stamp area in the target file includes: In the RGB image of the target file, determine the target location of the stamp area; The RGB image of the target file is cropped according to the target location to obtain the RGB image of the stamp area; After obtaining the target RGB image of the stamp area, the method further includes: Replace the RGB image of the stamp region in the RGB image of the target file with the target RGB image of the stamp region.

5. The method according to claim 4, characterized in that, Determining the target location of the stamp area in the RGB image of the target file includes: The RGB values ​​of each pixel in the RGB image of the target file are standardized to obtain the target file image. Based on the target file image, determine the target location of the stamp area.

6. The method according to any one of claims 1-5, characterized in that, After clustering each pixel, and before finding target pixels whose L-channel values ​​are greater than a set L-channel reference value, the method further includes: Among the four cluster centers, the first cluster center with the smallest L channel value is found, and the maximum value of the L channel value of each pixel in the cluster corresponding to the first cluster center is determined as the L channel reference value. Alternatively, the minimum value among the L-channel values ​​of the four cluster centers can be determined as the L-channel baseline value.

7. The method according to any one of claims 1-5, characterized in that, The method also includes: Among the four cluster centers, the second cluster center with the largest L channel value is found, and the background color of the target file is determined based on the color space characteristics of each pixel in the cluster corresponding to the second cluster center. The step of filling the pixels corresponding to each target pixel point with a set color in the RGB image of the stamp area includes: In the RGB image of the stamp area, the background color is used to fill the pixels corresponding to each of the target pixels.

8. A stamp removal device, characterized in that, include: The stamp image acquisition unit is used to acquire the RGB image of the stamp area in the target file; The color space conversion unit is used to convert the RGB image of the stamp area to a color space to obtain a LAB image. The pixel clustering unit is used to cluster each pixel in the LAB image based on the color space characteristics of each pixel in the LAB image when the maximum A channel value of each pixel is greater than a preset threshold, to obtain 4 clusters and their cluster centers. The clusters are used to represent the red stamp body, the red stamp edge, the background and the black text, respectively. The target pixel determination unit is used to find each target pixel whose L channel value is greater than the set L channel reference value in the clusters corresponding to the cluster centers with the largest and second largest A channel values. The cluster corresponding to the cluster center with the largest A channel value represents the red stamp body, and the cluster corresponding to the cluster center with the second largest A channel value represents the red stamp edge. The red stamp is composed of the red stamp body and the red stamp edge. The target pixel filling unit is used to fill the pixels corresponding to each target pixel in the RGB image of the stamp area with a set color to obtain the target RGB image of the stamp area.

9. A stamp removal device, characterized in that, include: Memory and processor; The memory is used to store programs; The processor is configured to execute the program to implement each step of the stamp removal method as described in any one of claims 1-7.

10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements each step of the seal removal method as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Image processing device, image processing method and information processing device

    CN107403405A

  • Shadow removal andimage segmentation of moving fish based on improved K-means clustering

    CN109035254A

  • Nevus flammeus color card generation method based on gray segmentation and Lab color clustering

    CN113034467A

  • Seal removing method, device and equipment and storage medium

    CN114936965A