Method and device for processing words in image, equipment and storage medium

By binarizing, eroding and expanding the scanned image, combined with the fusion technology of text mask diagram, the problem of poor text display effect is solved, and the clarity of text is improved.

CN119540065APending Publication Date: 2025-02-28GUANGZHOU ZHONO ELECTRONICS TECH CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202411599832.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-11
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the prior art, the text features in the original image are not obvious and the related denoising algorithm is not suitable for text-type images, resulting in poor display effects and unclear text in the scanned and output images.

Method used

By obtaining the image to be processed and the corresponding color mode, performing binarization, corrosion and expansion processing, extracting the text content and determining the target pixel position, generating a text mask image, and fusing the image to be processed with the intermediate image to obtain a text reinforced image.

Benefits of technology

It improves the problem of stroke interruption in text, filters out noise information around text, accurately extracts the location of text content, enhances the display effect of text, and improves text clarity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540065A_ABST
    Figure CN119540065A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a character processing method and device in an image, equipment and a storage medium, and the method comprises the steps: obtaining a to-be-processed image and a corresponding color mode, and carrying out the binarization processing of the to-be-processed image according to the color mode, and obtaining a binarized image; performing corrosion processing and first expansion processing on the binary image to obtain a first intermediate image; carrying out text content extraction on the first intermediate image, and determining a target pixel position corresponding to the text content; and generating a character mask image based on the target pixel position, and fusing the to-be-processed image and the first intermediate image according to the character mask image to obtain a character enhanced image. According to the scheme, the character display effect is effectively enhanced, and the character definition is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of computer technology, and in particular, to a method, apparatus, device and storage medium for processing text in an image. Background Art

[0002] With the popularization of automated office, scanners are widely used in modern office scenes, and printers with integrated scanners have become mainstream products in the printer market. Combined with the scanning function, the printer can directly transfer the paper document to a document or output it to the host computer in image format after scanning. Among them, corresponding to the documents and forms in office applications, the scanning and copying of certificates or handwritten manuscripts, the text in the scanned images often accounts for a large proportion.

[0003] In the related technology, since the text features in the original image are not obvious, for example, the contrast between the background color and the font is low, the quality of the original handwriting is poor, and the related denoising algorithm is not suitable for text images, for example, the denoising convolution window is too large or the sharpening intensity is insufficient, it is easy to cause the text display effect in the scanned output image to be poor and the text is not clear, which needs to be improved. Summary of the invention

[0004] The embodiments of the present application provide a method, apparatus, device and storage medium for processing text in an image, which solves the problem in the related art that the text features in the original image are not obvious and the related denoising algorithm is not suitable for text images, resulting in poor text display effect and unclear text in the scanned output image, thereby enhancing the display effect of text and improving the clarity of text.

[0005] In a first aspect, an embodiment of the present application provides a method for processing text in an image, the method comprising:

[0006] Acquire an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image;

[0007] Performing corrosion processing and first dilation processing on the binary image to obtain a first intermediate image;

[0008] Extracting text content from the first intermediate image and determining a target pixel position corresponding to the text content;

[0009] A text mask image is generated based on the target pixel position, and the image to be processed is fused with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0010] In a second aspect, an embodiment of the present application further provides a text processing device in an image, comprising:

[0011] An acquisition module, configured to acquire an image to be processed and a corresponding color mode;

[0012] A binarization module, configured to perform binarization processing on the image to be processed according to the color mode to obtain a binarized image;

[0013] An erosion and dilation processing module, configured to perform an erosion process and a first dilation process on the binary image to obtain a first intermediate image;

[0014] a text extraction module, configured to extract text content from the first intermediate image and determine a target pixel position corresponding to the text content;

[0015] The text enhancement module is configured to generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0016] In a third aspect, an embodiment of the present application further provides a text processing device in an image, the device comprising:

[0017] one or more processors;

[0018] a storage device configured to store one or more programs,

[0019] When the one or more programs are executed by the one or more processors, the one or more processors implement the text processing method in the image described in the embodiment of the present application.

[0020] In a fourth aspect, an embodiment of the present application further provides a non-volatile storage medium storing computer executable instructions, wherein the computer executable instructions, when executed by a computer processor, are configured to execute the text processing method in an image described in the embodiment of the present application.

[0021] In the embodiment of the present application, by acquiring the image to be processed and the corresponding color mode, the image to be processed is binarized according to the color mode to obtain a binarized image; the binarized image is corroded and expanded to obtain a first intermediate image; the text content is extracted from the first intermediate image to determine the target pixel position corresponding to the text content; a text mask image is generated based on the target pixel position, and the image to be processed and the first intermediate image are fused according to the text mask image to obtain a text enhanced image. In the above scheme, by converting the image to be processed into a binarized image, and corroding and expanding the first intermediate image to obtain the first intermediate image, the stroke interruption problem of the text can be improved, and the noise information around the text can be filtered out; by extracting the text content from the first intermediate image, determining the target pixel position corresponding to the text content in the first intermediate image, and generating the corresponding text mask image, the position of the text content in the image can be accurately extracted, providing reliable reference information for subsequent image fusion, and by fusion of the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image, the display effect of the text can be effectively enhanced and the text clarity can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 A flowchart of a method for processing text in an image provided by an embodiment of the present application;

[0023] Figure 2 A schematic diagram of the effect of text obtained after the original text in the binary image is corroded according to an embodiment of the present application;

[0024] Figure 3 A schematic diagram of the effect of text obtained after a first expansion process is performed on text after corrosion processing provided in an embodiment of the present application;

[0025] Figure 4 A flowchart of a text processing method including a process of determining a target pixel position corresponding to text content provided in an embodiment of the present application;

[0026] Figure 5 A schematic diagram of the effect of text obtained after performing a second expansion process on the text after the first expansion process provided by an embodiment of the present application;

[0027] Figure 6 A flowchart of a text processing method provided in an embodiment of the present application, including a process of specifically performing text recognition to determine a target pixel position corresponding to text content;

[0028] Figure 7 A flowchart of another text processing method provided in an embodiment of the present application, including a specific process of performing text recognition to determine a target pixel position corresponding to text content;

[0029] Figure 8 A flowchart of a text processing method provided in an embodiment of the present application, including a process of fusing an image to be processed with a first intermediate image to obtain a text enhanced image;

[0030] Fig. 9 A flowchart of another text processing method provided in an embodiment of the present application, including a process of fusing an image to be processed with a first intermediate image to obtain a text enhanced image;

[0031] Fig.10 A structural block diagram of a text processing device in an image provided by an embodiment of the present application;

[0032] Fig.11 A schematic diagram of the structure of a text processing device in an image provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] The embodiments of the present application are further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the embodiments of the present application, rather than to limit the embodiments of the present application. It should also be noted that, for ease of description, only parts related to the embodiments of the present application are shown in the accompanying drawings, rather than all structures.

[0034] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than those illustrated or described here, and the objects distinguished by "first", "second", etc. are generally of one type, and the number of objects is not limited. For example, the first object can be one or more. In addition, "and / or" in the specification and claims represents at least one of the connected objects, and the character " / " generally indicates that the objects associated with each other are in an "or" relationship.

[0035] The text processing method in an image provided in the embodiment of the present application is used to enhance the text in the image to obtain a text-enhanced image, thereby enhancing the display effect of the text. Specific application scenarios may include: document scanning, document printing, etc. The several application scenarios listed above are only exemplary and explanatory. In actual applications, the text processing method in an image can also be used in the processing of text in images in other scenarios, and the embodiment of the present application does not limit this. The present application aims to provide a method for processing text in an image to solve the problem in the related art that the text display effect in the scanned output image is poor and the text is not clear because the text features in the original image are not obvious and the related denoising algorithm is not suitable for text images.

[0036] In the method for processing text in an image provided in the embodiment of the present application, the executor of each step can be a computer device, which refers to any electronic device with data calculation, processing and storage capabilities, such as mobile phones, PCs (Personal Computers), tablet computers and other terminal devices, and can also be scanners, printers and other devices, which are not limited in the embodiment of the present application.

[0037] Figure 1 This is a flowchart of a method for processing text in an image provided by an embodiment of the present application. The method for processing text in an image can be implemented using a text processing device in an image as an execution subject. Figure 1 As shown, the text processing method in the image specifically includes the following steps:

[0038] Step S101 : obtaining an image to be processed and a corresponding color mode, and performing binarization processing on the image to be processed according to the color mode to obtain a binary image.

[0039] Among them, the image to be processed can be obtained by scanning a paper document through a scanner, a copier or other equipment, or by taking a photo of a paper document, an object carrying text information, etc. through a camera sensor, or by reading from a memory built into the device, and this is not limited in this application. In one embodiment, the image to be processed can be an image in which the text is not obvious relative to the background or the background is relatively complex, such as an identity card, a license plate, a wall pattern, etc., or an image in which the text is relatively obvious relative to the background or the background is relatively simple, such as a text table, a document page, etc. In one embodiment, the image to be processed can be an original image corresponding to different color modes, such as a grayscale mode, an RGB mode, a CMYK mode, an HSV mode, etc. In one embodiment, the image to be processed can be converted to grayscale corresponding to different color modes to obtain a grayscale image, and then the grayscale image can be binarized to obtain a binary image. The specific process is as follows:

[0040] When the color mode is a grayscale mode, the image to be processed is binarized to obtain a binary image; when the color mode is a color mode, the image to be processed is converted to grayscale in the corresponding color mode to obtain a grayscale image, and the grayscale image is binarized to obtain a binary image.

[0041] Among them, the image in grayscale mode can be directly binarized, while the image in color mode needs to be grayscale-converted using the corresponding grayscale conversion algorithm to obtain a grayscale image, and then binarized to obtain a binary image. In one embodiment, the color mode can be the RGB mode. By weighted-averaging the pixel values of the red, green, and blue channels according to certain weights, the pixel values of the grayscale image can be obtained. In one embodiment, the color mode can be the CMYK mode. The image to be processed can be first converted from the CMYK mode to the RGB mode, and then the RGB-mode image can be grayscale-converted to obtain a grayscale image.

[0042] In one embodiment, after the image to be processed is grayscale-converted to obtain a grayscale image, the grayscale image can be filtered. Among them, for the filtering process, a relatively small convolution window can be used to filter out noise points of 1 or 2 pixels, moderately reducing the influence of image noise. In one embodiment, for the binarization conversion of the grayscale image, it can be binarized and segmented by using the Otsu method or the fixed threshold method, which is not limited in this application.

[0043] Step S102: Erode and first dilate the binary image to obtain a first intermediate image.

[0044] Among them, both the erosion process and the first dilation process are morphological operations based on set theory, and the image is processed through a structuring element. The erosion process can be to eliminate the boundary points of the connected domain and make the boundary shrink inward. Specifically, a matrix with a fixed size can be used as the structuring element and slide and translate on the image. When the structuring element is completely contained within the target area, the central pixel is retained; otherwise, the pixel is removed. In one embodiment, the binary image can be first eroded and then first dilated to obtain a first intermediate image. Specifically, Figure 2 is a schematic diagram of the effect of the text obtained after eroding the original text in the binary image provided by the embodiment of the present application. As Figure 2 shown, after eroding the character '中' in the binary image, small noise points around it can be removed, making the edge of the character '中' smoother. The first dilation process can be to merge the background points adjacent to the target area into the target area, causing the boundary of the target area to expand outward. Specifically, a matrix with a fixed size can be used as the structuring element and slide and translate on the image. When the structuring element intersects with the target area, the central pixel is set to the same foreground as the target area. Figure 3 is a schematic diagram of the effect of the text obtained after first dilating the text after the erosion process provided by the embodiment of the present application. As Figure 3As shown, the structural element sizes used for the corrosion treatment and the first dilation treatment are the same. Performing the first dilation treatment on the "middle" character after the corrosion treatment can restore the pixel reduction of the "middle" character caused by the corrosion treatment, achieving a moderate dilation to improve the problem of interrupted text strokes caused by scanning or handwritten font writing issues and enhancing the text quality. In one embodiment, the first intermediate image can also be filtered to soften the text edges.

[0045] Step S103: Extract the text content from the first intermediate image and determine the target pixel positions corresponding to the text content.

[0046] In one embodiment, the first intermediate image can be subjected to optical character recognition for text recognition, and the target pixel positions corresponding to each character can be located. In one embodiment, the first intermediate image can be subjected to contour extraction through an edge detection algorithm, and the multiple extracted contours can be recognized and judged to obtain the target pixel positions of the contours determined to be text. The target pixel positions can be the position information of a fixed-shaped area surrounding the text contour. For example, the target pixel positions can be the endpoint coordinate information of a rectangular area surrounding the text contour, or the center coordinate information and radius information of a circular area surrounding the text contour. This application does not make any limitations here.

[0047] Step S104: Generate a text mask image based on the target pixel positions, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhancement image.

[0048] Among them, the text mask image can be the same size as the first intermediate image, and is used to identify the pixel area of ​​the text content in the first intermediate image. In one embodiment, the text mask image can be a binary image containing only numerical values ​​of 0 or 1, wherein the area with a pixel value of 1 indicates that the pixel corresponding to the first intermediate image belongs to a specific area of ​​the text content, and the area with a pixel value of 0 indicates that it does not belong to the specific area. In one embodiment, the target pixel position can be the minimum circumscribed graphic area of ​​each character, and the text mask image can be used to identify the text position in the minimum circumscribed image area, or it can be used to identify the entire minimum circumscribed graphic area, so that the subsequent fusion processing can erase part of the background adjacent to the text, which is not limited in this application. In one embodiment, the text mask image can be a pixel position that identifies each character. According to the text mask image, the text content in the image to be processed can be replaced with the corresponding text content in the first intermediate image to obtain a text-enhanced image and improve the display quality of the text. In one embodiment, the text mask image may be a pixel position that identifies each minimum circumscribed graphic area surrounding the text. According to the text mask image, each minimum circumscribed graphic area surrounding the text in the image to be processed may be replaced with each corresponding minimum circumscribed graphic area surrounding the text in the first intermediate image to obtain a text-enhanced image. While improving the display quality of the text, the background around the text is weakened to achieve the purpose of highlighting the text. In one embodiment, taking the execution subject as a printer as an example, after obtaining the text-enhanced image, the processor may write it into the memory or external memory, and print the text-enhanced image. In one embodiment, taking a scanner as an example, after obtaining the text-enhanced image, the processor may encode the text-enhanced image and output a picture file in a standard format.

[0049] In the above, by obtaining the image to be processed and the corresponding color mode, the image to be processed is binarized according to the color mode to obtain a binarized image; the binarized image is corroded and expanded to obtain a first intermediate image; the text content is extracted from the first intermediate image to determine the target pixel position corresponding to the text content; a text mask map is generated based on the target pixel position, and the image to be processed and the first intermediate image are fused according to the text mask map to obtain a text enhanced image. In the above scheme, by converting the image to be processed into a binarized image, and corroding and expanding the first intermediate image to obtain the first intermediate image, the stroke interruption problem of the text can be improved, and the noise information around the text can be filtered out at the same time; by extracting the text content from the first intermediate image, determining the target pixel position corresponding to the text content in the first intermediate image, and generating the corresponding text mask map, the position of the text content in the image can be accurately extracted, providing reliable reference information for subsequent image fusion, and by fusion of the image to be processed with the first intermediate image according to the text mask map to obtain a text enhanced image, the display effect of the text can be effectively enhanced and the text clarity can be improved.

[0050] Figure 4 This is a flowchart of a text processing method provided by an embodiment of the present application, which includes a process of determining target pixel positions corresponding to text content. As Figure 4 shown, the specific steps are as follows:

[0051] Step S201: Obtain the image to be processed and the corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binarized image.

[0052] Step S202: Perform erosion processing and first dilation processing on the binarized image to obtain a first intermediate image.

[0053] Step S203: Perform second dilation processing on the first intermediate image to obtain a second intermediate image.

[0054] Among them, since the strokes of the text may be relatively thin and the overall contour is not obvious, the second dilation processing can further dilate the moderately dilated text in the first intermediate image, which helps to extract the contour of the text in the subsequent positioning. Figure 5 This is a schematic diagram of the effect of the text obtained after performing second dilation processing on the text after the first dilation processing provided by an embodiment of the present application. As Figure 5 shown, performing second dilation processing on the "中" after the first dilation processing can thicken the display of the "中" character and achieve the purpose of excessive dilation, so as to facilitate the extraction of the outer contour of the text.

[0055] Step S204: Perform edge extraction on the second intermediate image to obtain at least one outer contour, and generate a minimum bounding rectangle corresponding to each outer contour.

[0056] Among them, since the second intermediate image may contain both text content and non-text content at the same time, the obtained outer contour may be the outer contour of the text or the outer contour of non-text, and it is necessary to further identify whether it is text subsequently. In one embodiment, the findContours() function of OpenCV can be used to find contours in the second intermediate image to obtain at least one outer contour. In one embodiment, the Canny operator, Sobel operator, Prewitt operator, etc. can be used to perform edge extraction on the second intermediate image to obtain at least one outer contour, and this application does not make any limitations here. In one embodiment, after obtaining at least one outer contour, the minAreaRect(cnt) function of OpenCV can be used to generate a minimum bounding rectangle corresponding to each outer contour, further identifying multiple local pixel regions that may be text and achieving the purpose of segmenting the text. Among them, the text in the minimum bounding rectangle can be one or more.

[0057] Step S205 , extracting the pixel position corresponding to the minimum circumscribed rectangle, performing text recognition on the local image corresponding to the pixel position in the first intermediate image, and determining the target pixel position corresponding to the text content.

[0058] Among them, after the minimum enclosing rectangle corresponding to the outer contour is generated, the pixel position corresponding to the minimum enclosing rectangle can be extracted, and the pixel position can be represented by different position description information, for example, it can be the coordinates of the four endpoints of the minimum enclosing rectangle, and for example, it can be the coordinates of the center point, width, height and rotation angle of the minimum enclosing rectangle, which is not limited in this application. Since the image content in the minimum enclosing rectangle is not necessarily text content, after obtaining the pixel position corresponding to each minimum enclosing rectangle, text recognition can be performed on the local image corresponding to the pixel position in the first intermediate image, and the target pixel position corresponding to the text content can be screened out from the existing pixel positions. Optionally, text recognition can be based on comparing character template images in a preset database to determine whether it is text, or it can be based on a preset text recognition model to determine whether it is text, which is not limited in this application.

[0059] Step S206: Generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0060] As described above, by performing a second dilation process on the first intermediate image to obtain a second intermediate image, it is helpful to more accurately extract the outer contour of the text content; by performing edge extraction on the second intermediate image to obtain at least one outer contour, and generating a minimum circumscribed rectangle corresponding to each outer contour, the text content can be effectively divided into multiple text units, and the text unit can contain one or more characters and provide accurate position information; by extracting the pixel position corresponding to the minimum circumscribed rectangle, performing text recognition on the local image of the corresponding pixel position in the first intermediate image, and determining the target pixel position corresponding to the text content, non-text content can be effectively excluded, and the target pixel position corresponding to the text content is retained, providing accurate position information for subsequent text enhancement processing.

[0061] Figure 6 The present invention provides a flowchart of a text processing method including a process of performing text recognition to determine the target pixel position corresponding to the text content. Figure 6 As shown, the specific steps include:

[0062] Step S301: Obtain an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image.

[0063] Step S302: Perform corrosion processing and first dilation processing on the binary image to obtain a first intermediate image.

[0064] Step S303: Perform a second dilation process on the first intermediate image to obtain a second intermediate image.

[0065] Step S304: extract edges of the second intermediate image to obtain at least one peripheral contour, and generate a minimum circumscribed rectangle corresponding to each peripheral contour.

[0066] Step S305, extracting the pixel position corresponding to the minimum circumscribed rectangle, comparing the local image of the corresponding pixel position in the first intermediate image with the character template image in the preset database, and determining whether the local image contains text characters.

[0067] Among them, the character template image can be a binary image of commonly used text characters, and can be used as a reference image to determine whether the local image contains text characters. In one embodiment, the local image can be scaled to the same size as the character template image, and the scaled local image and the character template image are compared pixel by pixel to determine the percentage of pixels with the same pixel value. The percentage of the number of pixels can be used to characterize the similarity between the local image and the character template image, and the local image whose pixel percentage reaches a preset ratio threshold is determined to contain text characters. In one embodiment, the first feature vector corresponding to each character template image is stored in the preset database. Correspondingly, the local image can be converted into a second feature vector, and the cosine similarity or Euclidean distance of the first feature vector and the second feature vector is calculated to determine the similarity between the local image and the character template image, and the local image whose similarity reaches a preset similarity threshold is determined to contain text characters. Of course, there can be other methods for similarity comparison between local images and character template images, which are not limited in this application.

[0068] Step S306: determine the pixel position corresponding to the partial image containing the text character as the target pixel position.

[0069] Among them, determining the pixel position corresponding to the local image containing text characters as the target pixel position can effectively exclude the pixel position of non-text content, so as to avoid subsequent enhancement of non-text content and affect the text enhancement effect.

[0070] Step S307: Generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0071] As mentioned above, by comparing the local image of the corresponding pixel position in the first intermediate image with the character template image in the preset database, it is possible to effectively identify whether the local image contains text characters. By determining the pixel position corresponding to the local image containing the text characters as the target pixel position, the pixel position of the non-text content can be accurately eliminated, which is conducive to the subsequent precise enhancement of the display effect of the text content.

[0072] Figure 7 Another flowchart of a text processing method provided by an embodiment of the present application includes a specific process of performing text recognition to determine the target pixel position corresponding to the text content. Figure 7 As shown, the specific steps include:

[0073] Step S401: Obtain an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image.

[0074] Step S402: Perform corrosion processing and first dilation processing on the binary image to obtain a first intermediate image.

[0075] Step S403: Perform a second dilation process on the first intermediate image to obtain a second intermediate image.

[0076] Step S404: extract edges of the second intermediate image to obtain at least one peripheral contour, and generate a minimum circumscribed rectangle corresponding to each peripheral contour.

[0077] Step S405 , extracting the pixel position corresponding to the minimum circumscribed rectangle, inputting the local image corresponding to the pixel position in the first intermediate image into a preset text recognition model, and determining whether the local image contains text characters.

[0078] Among them, the preset text recognition model can be a CTPN (Connectionist Text Proposal Network) model, an EAST (Efficient and Accurate Scene Text Detection) model, a CRNN (Convolutional Recurrent Neural Network) model, etc., which are not limited in this application. Specifically, standard text images and other non-text images can be used as training data sets to train the preset text recognition model, and back propagation and optimization calculations are performed based on the calculated loss function value and the preset learning rate. The network parameters corresponding to the preset text recognition model are cyclically updated until the loss converges to obtain a trained preset text recognition model. Based on the trained preset text recognition model, it is possible to accurately determine whether a local image contains text characters.

[0079] Step S406: determine the pixel position corresponding to the partial image containing the text character as the target pixel position.

[0080] Step S407: Generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0081] As described above, by judging whether a local image contains text characters based on a preset text recognition model, the local image containing text characters can be accurately identified, the target pixel position corresponding to the text content can be effectively screened out, and the interference of non-text content on subsequent text enhancement can be eliminated.

[0082] Figure 8 A flowchart of a text processing method provided in an embodiment of the present application includes a process of fusing an image to be processed with a first intermediate image to obtain a text enhanced image. Figure 8 As shown, the specific steps include:

[0083] Step S501: Obtain an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image.

[0084] Step S502: Perform corrosion processing and first dilation processing on the binary image to obtain a first intermediate image.

[0085] Step S503: extract text content from the first intermediate image and determine the target pixel position corresponding to the text content.

[0086] Step S504: Generate a text mask image based on the target pixel position, and extract the first local text from the first intermediate image according to the text mask image.

[0087] The text mask image may be a pixel position identifying each text, and based on the text mask image, the first partial text may be extracted from the first intermediate image, and the first partial text includes each text in the first intermediate image.

[0088] Step S505: Perform pixel-weighted fusion on the second partial text corresponding to the text mask image in the image to be processed and the first partial text to obtain a text-enhanced image.

[0089] In one embodiment, the pixel weight of the second partial text in the image to be processed corresponding to the text mask image can be set to 0, which is equivalent to directly replacing the second partial text in the image to be processed with the first partial text on the basis of retaining the original background of the image to be processed, so as to obtain a text-enhanced image, thereby achieving the purpose of enhancing the text display effect in the image to be processed. In one embodiment, the pixel weights corresponding to the first partial text and the second partial text can be set as the first pixel weight and the second pixel weight, respectively, for example, the first pixel weight is 80%, and the second pixel weight is 20%, and on the basis of retaining the original background of the image to be processed, based on the first pixel weight and the second pixel weight, the first partial text and the second partial text are weightedly fused to obtain a text-enhanced image, so as to reasonably fuse the text content of the first intermediate image and the image to be processed, and enhance the text display effect in the image to be processed.

[0090] As described above, by performing pixel-weighted fusion of the second local text corresponding to the text mask image in the image to be processed with the first local text, the text features of the image to be processed with unclear edges or unclear text information can be effectively improved, the text display effect can be enhanced, and the text clarity can be improved.

[0091] Fig. 9 A flowchart of another text processing method provided in an embodiment of the present application, including a process of fusing an image to be processed with a first intermediate image to obtain a text enhanced image. Fig. 9 As shown, the specific steps include:

[0092] Step S601: Obtain an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image.

[0093] Step S602: Perform corrosion processing and first dilation processing on the binary image to obtain a first intermediate image.

[0094] Step S603: extract text content from the first intermediate image and determine the target pixel position corresponding to the text content.

[0095] Step S604: Generate a text mask image based on the target pixel position, and extract the first partial text and the first background surrounding the first partial text from the first intermediate image according to the text mask image.

[0096] Among them, the text mask image can be a map that identifies the pixel positions of each minimum circumscribed graphic area surrounding the text. Based on the text mask image, the first local text and the first background surrounding the first local text can be extracted from the first intermediate image. The first local text includes each text in the first intermediate image, and the first background can be the background pixel part of the minimum circumscribed graphic area surrounding the text.

[0097] Step S605 , replacing the second partial text and the second background surrounding the second partial text in the image to be processed corresponding to the text mask image with the first partial text and the first background surrounding the first partial text, to obtain a text enhanced image.

[0098] Among them, since the first intermediate image is a binary image, when the pixel value of the first partial text is 0, the pixel value of the first background is 255, that is, the first background is pure white. Therefore, the second partial text and the second background surrounding the second partial text corresponding to the text mask image in the image to be processed are replaced with the first partial text and the first background surrounding the first partial text, which can weaken the background around the text and eliminate the influence of the original background, so as to achieve the purpose of highlighting the text.

[0099] As mentioned above, by replacing the second partial text and the second background surrounding the second partial text in the corresponding text mask image in the image to be processed with the first partial text and the first background surrounding the first partial text, the display effect of the text can be enhanced while eliminating the influence of the original background around the text and improving the recognition of the text.

[0100] Fig.10 This is a structural block diagram of a text processing device in an image provided by an embodiment of the present application. The device is configured to execute the text processing method in an image provided by the above embodiment and has the corresponding functional modules and beneficial effects of the execution method. Fig.10 As shown, the device specifically includes:

[0101] An acquisition module 101 is configured to acquire an image to be processed and a corresponding color mode;

[0102] A binarization module 102 is configured to perform binarization processing on the image to be processed according to the color mode to obtain a binarized image;

[0103] The erosion and dilation processing module 103 is configured to perform an erosion process and a first dilation process on the binary image to obtain a first intermediate image;

[0104] The text extraction module 104 is configured to extract text content from the first intermediate image and determine a target pixel position corresponding to the text content;

[0105] The text enhancement module 105 is configured to generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0106] In the above, by obtaining the image to be processed and the corresponding color mode, the image to be processed is binarized according to the color mode to obtain a binarized image; the binarized image is corroded and expanded to obtain a first intermediate image; the text content is extracted from the first intermediate image to determine the target pixel position corresponding to the text content; a text mask map is generated based on the target pixel position, and the image to be processed and the first intermediate image are fused according to the text mask map to obtain a text enhanced image. In the above scheme, by converting the image to be processed into a binarized image, and corroding and expanding the first intermediate image to obtain the first intermediate image, the stroke interruption problem of the text can be improved, and the noise information around the text can be filtered out at the same time; by extracting the text content from the first intermediate image, determining the target pixel position corresponding to the text content in the first intermediate image, and generating the corresponding text mask map, the position of the text content in the image can be accurately extracted, providing reliable reference information for subsequent image fusion, and by fusion of the image to be processed with the first intermediate image according to the text mask map to obtain a text enhanced image, the display effect of the text can be effectively enhanced and the text clarity can be improved.

[0107] In a possible embodiment, the text extraction module 104 is further configured to:

[0108] Performing a second dilation process on the first intermediate image to obtain a second intermediate image;

[0109] Perform edge extraction on the second intermediate image to obtain at least one peripheral contour, and generate a minimum circumscribed rectangle corresponding to each peripheral contour;

[0110] The pixel position corresponding to the minimum circumscribed rectangle is extracted, and text recognition is performed on the local image corresponding to the pixel position in the first intermediate image to determine the target pixel position corresponding to the text content.

[0111] In a possible embodiment, the text extraction module 104 is further configured to:

[0112] Comparing the local image at the corresponding pixel position in the first intermediate image with the character template image in the preset database to determine whether the local image contains text characters;

[0113] The pixel position corresponding to the partial image containing the text character is determined as the target pixel position.

[0114] In a possible embodiment, the text extraction module 104 is further configured to:

[0115] Inputting the local image corresponding to the pixel position in the first intermediate image into a preset text recognition model to determine whether the local image contains text characters;

[0116] The pixel position corresponding to the partial image containing the text character is determined as the target pixel position.

[0117] In a possible embodiment, the text enhancement module 105 is further configured to:

[0118] Extracting a first partial text from the first intermediate image according to the text mask image;

[0119] The second partial text corresponding to the text mask image in the image to be processed is pixel-weighted fused with the first partial text to obtain a text-enhanced image.

[0120] In a possible embodiment, the text enhancement module 105 is further configured to:

[0121] extracting a first partial text and a first background surrounding the first partial text from the first intermediate image according to the text mask image;

[0122] The second partial text and the second background surrounding the second partial text corresponding to the text mask image in the image to be processed are replaced with the first partial text and the first background surrounding the first partial text to obtain a text enhanced image.

[0123] In a possible embodiment, the binarization module 102 is further configured as follows:

[0124] When the color mode is a grayscale mode, the image to be processed is binarized to obtain a binary image;

[0125] When the color mode is a color mode, the image to be processed is subjected to grayscale conversion processing corresponding to the color mode to obtain a grayscale image, and the grayscale image is subjected to binarization processing to obtain a binarized image.

[0126] Fig.11 A schematic diagram of a text processing device in an image provided by an embodiment of the present application is shown in FIG. Fig.11 As shown, the device includes a processor 201, a memory 202, an input device 203 and an output device 204; the number of processors 201 in the device can be one or more. Fig.11 A processor 201 is taken as an example; the processor 201, memory 202, input device 203 and output device 204 in the device can be connected by a bus or other means. Fig.11In the example, the connection through the bus is taken as an example. The memory 202, as a computer-readable storage medium, can be configured to store software programs, computer executable programs and modules, such as program instructions / modules corresponding to the text processing method in the image in the embodiment of the present application. The processor 201 executes various functional applications and data processing of the device by running the software programs, instructions and modules stored in the memory 202, that is, realizes the above-mentioned text processing method in the image. The input device 203 can be configured to receive input digital or character information, and generate key signal input related to the user settings and function control of the device. The output device 204 may include a display device such as a display screen. Optionally, the word processing device may be a printer or a scanner, the input device may include a data acquisition module, such as a CIS sensor, for acquiring the image to be processed, and the output device may include a data output module for printing a text-enhanced image or encoding the text-enhanced image by running an image encoding algorithm, and outputting the encoded image file to the terminal device.

[0127] The text processing device in the image provided above can be used to execute the text processing method in the image provided by any of the above embodiments, and has corresponding functions and beneficial effects.

[0128] An embodiment of the present application also provides a non-volatile storage medium containing computer executable instructions. When the computer executable instructions are executed by a computer processor, they are configured to execute a method for processing text in an image described in the above embodiment, which includes: obtaining an image to be processed and a corresponding color mode, and binarizing the image to be processed according to the color mode to obtain a binary image; performing corrosion processing and a first dilation processing on the binary image to obtain a first intermediate image; extracting text content from the first intermediate image to determine the target pixel position corresponding to the text content; generating a text mask image based on the target pixel position, and fusing the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

[0129] Storage medium - any of various types of memory devices or storage devices. The term "storage medium" is intended to include: installation media, such as CD-ROM, floppy disk or tape device; computer system memory or random access memory, such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; non-volatile memory, such as flash memory, magnetic media, or optical storage; registers or other similar types of memory elements, etc. Storage media may also include other types of memory or combinations thereof. In addition, the storage medium may be located in the first computer system in which the program is executed, or may be located in a different second computer system, which is connected to the first computer system via a network (such as the Internet). The second computer system can provide program instructions to the first computer for execution. The term "storage medium" may include two or more storage media residing in different locations (e.g., in different computer systems connected via a network). The storage medium may store program instructions (e.g., embodied as a computer program) that can be executed by one or more processors.

[0130] Of course, the storage medium containing computer executable instructions provided in the embodiment of the present application is not limited to the above-mentioned text processing method in the image, and the computer executable instructions can also execute related operations in the text processing method in the image provided in any embodiment of the present application.

[0131] It is worth noting that in the embodiment of the text processing device in the above image, the various units and modules included are only divided according to functional logic, but are not limited to the above division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not configured to limit the protection scope of the embodiments of the present application.

[0132] It should be noted that the numbering of each step in this scheme is only used to describe the overall design framework of this scheme, and does not represent the necessary order relationship between the steps. On the basis that the overall implementation process conforms to the overall design framework of this scheme, it belongs to the protection scope of this scheme, and the order of precedence in the form of text when describing is not an exclusive limitation on the specific implementation process of this scheme. It should be understood by those skilled in the art that the embodiments of the present application can be provided as methods, systems, or computer program products. In a typical configuration, a computing device includes one or more processors (CPU), an input / output interface, a network interface, and a memory. The memory may include non-permanent memory in a computer-readable medium, a random access memory (RAM) and / or a non-volatile memory in the form of a read-only memory (ROM) or a flash memory (fl ash RAM). The memory is an example of a computer-readable medium.

[0133] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0134] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A method for processing text in an image, characterized in that: include: Acquire an image to be processed and a corresponding color mode, and perform binarization processing on the image to be processed according to the color mode to obtain a binary image; Performing corrosion processing and first dilation processing on the binary image to obtain a first intermediate image; Extracting text content from the first intermediate image and determining a target pixel position corresponding to the text content; A text mask image is generated based on the target pixel position, and the image to be processed is fused with the first intermediate image according to the text mask image to obtain a text enhanced image.

2. The method for processing text in an image according to claim 1, characterized in that: The extracting text content from the first intermediate image and determining a target pixel position corresponding to the text content includes: Performing a second dilation process on the first intermediate image to obtain a second intermediate image; Performing edge extraction on the second intermediate image to obtain at least one peripheral contour, and generating a minimum circumscribed rectangle corresponding to each of the peripheral contours; The pixel position corresponding to the minimum circumscribed rectangle is extracted, and text recognition is performed on the local image corresponding to the pixel position in the first intermediate image to determine the target pixel position corresponding to the text content.

3. The method for processing text in an image according to claim 2, characterized in that: The performing text recognition on the local image corresponding to the pixel position in the first intermediate image to determine the target pixel position corresponding to the text content includes: Comparing the local image corresponding to the pixel position in the first intermediate image with a character template image in a preset database to determine whether the local image contains text characters; The pixel position corresponding to the partial image containing the text character is determined as the target pixel position.

4. The method for processing text in an image according to claim 2, characterized in that: The performing text recognition on the local image corresponding to the pixel position in the first intermediate image to determine the target pixel position corresponding to the text content includes: Inputting a partial image corresponding to the pixel position in the first intermediate image into a preset text recognition model to determine whether the partial image contains text characters; The pixel position corresponding to the partial image containing the text character is determined as the target pixel position.

5. The method for processing text in an image according to claim 1, characterized in that: The step of fusing the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image includes: extracting a first partial text from the first intermediate image according to the text mask image; The second local text corresponding to the text mask image in the image to be processed is pixel-weighted fused with the first local text to obtain a text-enhanced image.

6. The method for processing text in an image according to claim 1, characterized in that: The step of fusing the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image includes: extracting a first partial text and a first background surrounding the first partial text from the first intermediate image according to the text mask image; The second partial text corresponding to the text mask image and the second background surrounding the second partial text in the image to be processed are replaced with the first partial text and the first background surrounding the first partial text to obtain a text enhanced image.

7. The method for processing text in an image according to claim 1, characterized in that: The step of binarizing the image to be processed according to the color mode to obtain a binarized image includes: When the color mode is a grayscale mode, binarization is performed on the image to be processed to obtain a binary image; In the case where the color mode is a color mode, the image to be processed is subjected to grayscale conversion processing corresponding to the color mode to obtain a grayscale image, and the grayscale image is subjected to binarization processing to obtain a binarized image.

8. A device for processing text in an image, characterized in that: include: An acquisition module, configured to acquire an image to be processed and a corresponding color mode; A binarization module, configured to perform binarization processing on the image to be processed according to the color mode to obtain a binarized image; An erosion and dilation processing module, configured to perform an erosion process and a first dilation process on the binary image to obtain a first intermediate image; a text extraction module, configured to extract text content from the first intermediate image and determine a target pixel position corresponding to the text content; The text enhancement module is configured to generate a text mask image based on the target pixel position, and fuse the image to be processed with the first intermediate image according to the text mask image to obtain a text enhanced image.

9. A device for processing text in an image, the device comprising: one or more processors; A storage device configured to store one or more programs, when the one or more programs are executed by the one or more processors, enables the one or more processors to implement the text processing method in an image according to any one of claims 1-7.

10. The text processing device in an image according to claim 9, characterized in that: Also includes: An input device and an output device, wherein the input device and the output device are respectively connected to the processor, the input device is used to collect image data, and the output device is used to output text-enhanced images.

11. A non-volatile storage medium storing computer executable instructions, wherein the computer executable instructions are configured to execute the text processing method in an image according to any one of claims 1 to 7 when executed by a computer processor.

Citation Information

Patent Citations

  • Character detection method and device, apparatus and computer readable storage medium

    CN110097046A

  • Optical character recognition method based on neural network

    CN112348007A

  • Handwritten character sample generation method and device, electronic equipment and storage medium

    CN112990205A

  • Text segmentation method and device, electronic equipment and storage medium

    CN113033563A

  • QR code identification method and device

    CN113505773A