Binarization and normalization based patching for text removal

By combining the fusion mask of binary mask, edge mask and contour mask, the problem of difficult removal of rotated and diverse text in images in the existing technology is solved, and efficient text patching and background processing on mobile devices are achieved. Recovery,adaptation to low light and low contrast situations.

CN112840373BActive Publication Date: 2024-10-22HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201980049692.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Priority Date
2018-08-21
Filing Date
2019-08-01
Publication Date
2024-10-22
Estimated Expiration
2039-08-01

AI Technical Summary

Technical Problem

Existing technologies are difficult to effectively remove rotated text and diverse text in images, especially when processed on mobile devices. They are inefficient and consume high power, and existing binarization algorithms cannot separate text in low illumination or low contrast situations. and background inaccuracies, resulting in missing or incorrectly patched text information.

Method used

A fusion mask that combines binary mask, edge mask and contour mask is used to detect text edges through edge detection, morphological gradient and Sobel operator, combined with binarization method to enhance contrast, and ensure text through normalization processing Pixels are completely covered, using patching algorithms such as Telea to fill in the background.

Benefits of technology

It improves the accuracy and repair effect of text area mask, can effectively remove diverse text and restore image background, is suitable for mobile devices with low processing power and low battery, has fast processing speed and adapts to low-quality images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112840373B_ABST
    Figure CN112840373B_ABST
Patent Text Reader

Abstract

The fused mask is used as a combination of an edge mask, a contour mask, and a binary mask to extract text for inpainting. The edge mask finds a set of hierarchical closed edge contours of the text and fills the pixels marked as possible text in the closed edge contours as a contour mask. A binarization method is applied to the original image to convert the original image into a binary image and detect the stroke edges of the text in the binary image. The binary image is segmented based on the detected stroke edges of the text, and at least one binarization method is applied to each image partition to obtain a binary mask candidate as a foreground for inpainting. The fused mask is applied to the original image to extract the text, and an inpainting algorithm is used to inpaint the parts of the original image where the text is extracted.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] Cross-application of related applications

[0002] This application claims priority to and the benefit of U.S. Provisional Application No. 62 / 720,558, filed on August 21, 2018, entitled “Binarization and Normalization-Based Inpainting for Removing Text,” which is incorporated herein by reference. Technical Field

[0003] The disclosure herein relates to an image processing device and related methods, and more particularly, to a system and method for text region binarization and normalization-based patching, which are used to remove different types of text and restore the background of an image. Background Art

[0004] Digital inpainting is the process of applying algorithms to images to replace lost, deteriorated, or damaged parts of the image data. Inpainting can be used to replace lost blocks in image encoding and transmission, as well as to remove logos or text from images and videos and fill in missing details of the original image. Image inpainting has a wide range of applications, including photo restoration, film restoration, removal of text, subtitles, logos, stamps, scratches and other occlusions.

[0005] Sometimes, images may contain embedded text that is to be removed for aesthetics, translation, or other reasons. In these cases, the goal is to remove the unwanted text, restore the background of the image where the text resides, and refill the text area with the image background. However, the process becomes complicated when the text area is not horizontal and is rotated at a certain angle. In addition, the characters of the text area can have any text size, artistic fonts, or colors, further complicating the text removal and inpainting process. Existing processes are unable to effectively remove such text, and when applied on, for example, mobile devices, they are unable to perform text inpainting on multiple text areas of various text styles and angles efficiently and with low power consumption.

[0006] As just pointed out, one of the applications of patching is to remove text or objects from an image, such as text captions and logos. FIG. 1 shows another example, wherein the text "NOODLES" in image 102 is removed, and the background is patched in image 104. As shown, the patched image 104 is inconsistent. In a text translation application, it is desirable to remove the original text and replace it with the translated text. FIG. 2 shows a translator application, wherein patching is used to remove the original characters in image 202 to obtain a clean background 204 before rendering the translated text 206 (i.e., "Emergencyrefuge" in this case).

[0007] FIG3 shows a general inpainting framework for rendering an image as shown in FIG2. As shown in the figure, it is divided into two steps:

[0008] 1. Find a text mask (image segmentation) of the same size as the original image 300, where the text is marked in white and the background is marked in black (step 302). The text mask 303 distinguishes the pixels of the text foreground and background. An ideal mask will cover all pixels of the text. Techniques for separating the foreground and background include, for example, the adaptive thresholding technique described in US9,042,649.

[0009] 2. In step 304, the text mask is used together with the original image and a specific inpainting algorithm is applied, such as the open source image inpainting algorithm disclosed by Telea in "An image inpainting techniquebased on the fast-marching method" (Journal of Graphics Tools, 9.1 (2004), pp. 25-36) (https: / / docs.opencv.org / ref / master / df / d3d / tutorial_py_inpainting.html) to obtain the inpainted image. The algorithm starts with the region boundary and then gradually fills in all elements within the region boundary. A small neighborhood is required around the pixel on the neighborhood to be inpainted. The pixel is replaced with the normalized weighted sum of all known pixels in the neighborhood. Once a pixel is inpainted, it is moved to the next nearest pixel using the fast marching method. Other repair techniques include, for example, the image repair method described in CN102567955, which repairs the image by repeatedly determining the contour of the area to be repaired and successively repairing the unknown pixel points in the neighborhood of all set contour points of the area to be repaired layer by layer until the area to be repaired is filled, thereby generating an image repair result 306.

[0010] This method relies on the initialization of the starting point on the contour, which is not robust. A recursive scheme is also used to update the patching result, which will cause speed problems. Existing methods for finding text masks include using image binarization segmentation to convert the pixel image 402 into a binary image 404 with values ​​of 0 and 255, such as shown in Figure 4. Binarization is used to locally or globally find thresholds to segment the image. If the pixel value is greater than the threshold, the pixel value is set to 255; if the pixel value is less than the threshold, the pixel value is set to 0. However, most binarization algorithms have limitations due to the inaccurate separation of text from the background caused by low illumination or low contrast in the image. For example, Otsu's binarization method automatically performs clustering-based image thresholding to globally find thresholds, but its robustness is not enough to handle low illumination and low contrast in certain parts of the image.

[0011] The binarization process may result in loss of text information, especially for pixels on edges. Typically, the edge sharpness between text and background is not ideal when there is a blurred transition region such as shown in the close-up image of image 502 at 504 in FIG. 5. Due to this limitation, the results 600 of existing binarization algorithms (such as the algorithms proposed by Niblack, Sauvola et al. and Wolf et al. described in FIG. 6) are suboptimal because text pixels are mislabeled or background is mislabeled as text. Descriptions of these algorithms can be found in Niblack, W., "An introduction to digital image processing" (1986, Prentice-Hall, Englewood Cliffs, NJ, 1986), pp. 115-116; Sauvola, J. et al., "Adaptive document binarization" (1997, Ulm, Germany, Fourth International Conference on Document Analysis and Recognition (Int. Conf. on Document Analysis and Recognition) Proceedings, pp. 147-152); and C. Wolf et al., "Text localization enhancement and binarization in multimedia documents" (2002, International Conference on Pattern Recognition (Int. Conf. on Pattern Recognition) Proceedings, Vol. 4, pp. 1037-1040). In addition, binarization is the process of segmenting an image but not determining the foreground and background of the image. If text is mistakenly marked as background, the real background will be patched with the text color.

[0012] Bhuvaneswari et al. disclosed another method for "Automatic Detection and Inpainting of Text Images" (International Journal of Computer Applications (0975-8887), Vol. 61, No. 7, 2013), in which the input image is adjusted to 400*400 pixels and the Niblack method is used for local threshold binarization. Then, the connected component method is used to find possible text areas, and two thresholds are set to remove non-text areas. The binary image of the expanded text area is the mask for inpainting. However, the limitation of this algorithm is that the Niblack method is a local threshold binarization method and has limitations in use. At the same time, the process of adjusting the input image to 400*400 pixels will cause the loss of text information, especially for text in long text lines. In addition, the criteria for setting thresholds to remove macros or large connected areas are not robust. The resulting binary mask for inpainting text areas is insufficient in many cases, especially in cases of low image quality or uneven lighting. Summary of the invention

[0013] Various examples are now described to introduce a series of concepts in a simplified form, which are further described in the detailed description below. This summary is not intended to identify key or essential features of the claimed subject matter, nor is it intended to be used to limit the scope of the claimed subject matter.

[0014] The system and method described herein address the limitations of the prior art by improving the accuracy of the mask of the text area of ​​the original image used to mark the text area for patching. The system and method described herein use binarization to extract the text area mask, thereby solving the above problems. In an exemplary embodiment, three masks based on normalization of black background and white characters: a binary mask, an edge mask, and a contour mask are combined into a fused mask. Alternatively, only two of the three masks can be combined into a fused mask (for example, the contour mask and the binary mask are combined into a fused mask). The advantages provided by each mask ensure that the text pixels in the original image are fully covered by the patch. The fused mask and the patching algorithm are applied to the input image to extract the entire background. Normalizing the image to a black background and white characters determines the text binary mask as the foreground of the patch, while the fused mask contains the edge features of the text and the text pixels inside, ensuring the accuracy of the text segmentation. At the same time, the processing is not complicated, so that the system and method can be used to implement text patching on mobile devices with relatively low processing power and battery life.

[0015] According to a first aspect of the present invention, a computer-implemented method is provided for finding a text mask in an original image to extract text for inpainting. The method comprises the following steps: applying edge detection by one or more processors to detect the edges of the text in the original image as an edge mask. Using the edge mask to find a set of hierarchical closed edge contours of the text, and filling the closed edge contours with pixels marked as possible text as a contour mask. Applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image. Segmenting the binary image based on the detected stroke edges of the text in the binary image. Applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for inpainting. Combining at least two of the edge mask, the contour mask and the binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining the original background of the original image without the text. Inpainting is performed on each portion of the original image where the text is extracted. The advantage provided by each mask combined into the fused mask is that it ensures that the text pixels in the original image are fully covered by the patch.

[0016] According to a second aspect of the present invention, there is provided an image processing device comprising: a non-transitory memory comprising instructions, and one or more processors communicating with the memory. The one or more processors execute the instructions to find a text mask in the original image to extract text for patching through the following steps: applying edge detection to detect the edges of the text in the original image as an edge mask; using the edge mask to find a set of hierarchical closed edge contours of the text, and filling the pixels marked as possible text in the closed edge contours as a contour mask; applying a binarization method to the original image to convert the original image into a binary image and detect the stroke edges of the text in the binary image; segmenting the binary image based on the detected stroke edges of the text in the binary image, and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for patching; combining at least two of the edge mask, the contour mask and the binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining the original background of the original image that does not contain the text; and patching in each part of the original image where the text is extracted. As with the first aspect, each mask combined into the fused mask provides the advantage of ensuring that the text pixels in the original image are fully covered by the patching.

[0017] According to a third aspect of the present invention, a non-transitory computer-readable medium is provided, which stores computer instructions to find a text mask in an original image to extract text for patching. When one or more processors execute the computer instructions, the one or more processors perform the following steps: applying edge detection to detect the edges of the text in the original image as an edge mask; using the edge mask to find a set of hierarchical closed edge contours of the text, and filling the pixels marked as possible text in the closed edge contours as a contour mask; applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image; segmenting the binary image based on the detected stroke edges of the text in the binary image, and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for patching; combining at least two of the edge mask, the contour mask, and the binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining the original background of the original image that does not contain the text; and patching the respective parts of the original image where the text is extracted. As in the first and second aspects, the advantage provided by each mask combined into the fused mask ensures that the text pixels in the original image are fully covered by the patching.

[0018] According to a fourth aspect of the present invention, there is provided an image processing device, comprising: a non-transitory memory including instructions, and one or more processors in communication with the memory, wherein the one or more processors execute the instructions to search for a text mask in an original image to extract text for patching. The instructions in the memory are organized into functional processing modules, which, when processed by the one or more processors, provide: a method for applying edge detection to detect the edges of text in the original image as an edge mask; a method for using the edge mask to find a set of hierarchical closed edge contours of the text and fill the closed edge contours with pixels marked as possible text as a contour mask; a method for applying a binarization method to the original image to convert the original image into a binary image and detect the stroke edges of the text in the binary image; a method for segmenting the binary image based on the detected stroke edges of the text in the binary image and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for patching; a method for combining at least two of the edge mask, the contour mask and the binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining the original background of the original image that does not contain the text; and a method for patching in each portion of the original image where the text is extracted. As with the first three aspects, the advantages provided by each mask combined into the fused mask ensure that the text pixels in the original image are fully covered by the patch.

[0019] In a first implementation of any of the aforementioned aspects, the original image is converted into a grayscale image before applying the edge detection.

[0020] In a second implementation of any of the aforementioned aspects, applying the edge detection includes applying at least one of a morphological gradient edge detection algorithm or a Sobel operator edge detection algorithm to the original image to detect the edge of the text in the original image.

[0021] In a third implementation of any of the aforementioned aspects, the use of the edge mask to find a set of hierarchical closed edge contours of the text includes applying the morphological gradient edge detection algorithm to the original image to create a morphological gradient contour mask, applying the Sobel operator edge detection algorithm to the grayscale image to create a Sobel contour mask, and combining the morphological gradient contour mask with the Sobel contour mask to create the contour mask.

[0022] In a fourth implementation of any of the preceding aspects, a connected component method is applied to fill pixels defined by the contour mask to fill the closed edge contour.

[0023] In a fifth implementation of any of the aforementioned aspects, applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image includes at least one of the following: binarizing the brightness channel in the chroma, brightness and saturation color space of the original image to enhance the contrast of the original image; binarizing the contrast-limited adaptive histogram equalization of the LAB color space binarization to enhance the contrast of the original image; binarizing the brightness channel of the LAB color space by applying principal component analysis binarization to enhance the contrast of the original image; and selecting the best binary image from the binary images generated by each binarization method.

[0024] In a sixth implementation of any one of the aforementioned aspects, applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image includes at least one of the following: taking the inverse value of the binarized brightness channel in the chroma, brightness and saturation color space of the original image; taking the inverse value of the binarized contrast-limited adaptive histogram equalization of the LAB color space binarization; taking the inverse value of the principal component analysis binarization; and selecting the optimal binary image from the binary images generated by each binarization method and each inverse binarization method.

[0025] In a seventh implementation of any of the aforementioned aspects, segmenting the binary image based on the detected stroke edges of the text in the binary image includes: segmenting the binary image into sub-images through horizontal and vertical histogram projections, and binarizing the sub-images.

[0026] In an eighth implementation of any of the aforementioned aspects, normalizing the binary image includes: setting the text as pixels of a first color, setting the background as pixels of a second color, and selecting the best binary mask from the at least one binary mask candidate.

[0027] The method can be performed by the device, the instructions on the computer-readable medium can be processed by the device, and other features of the method and the instructions on the computer-readable medium are generated by the functions of the device. At the same time, the description and implementation provided for each aspect are also applicable to other aspects and corresponding implementations. Different embodiments can be implemented in hardware, software or any combination thereof. At the same time, any example in the above examples can be combined with any one or more examples in the above other examples to create new embodiments within the scope of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] The drawings are not necessarily drawn to scale, where like numerals may describe similar components in different views. The drawings generally illustrate, by way of example and not limitation, various embodiments discussed herein.

[0029] Figure 1 shows an example where the text "NOODLES" is removed and the background is inpainted;

[0030] FIG2 shows a translator application where inpainting is used to remove original characters to obtain a clean background before rendering the translated text;

[0031] FIG3 shows a general inpainting framework for image rendering in conventional methods;

[0032] FIG4 shows an image binarization segmentation method for finding a text mask by converting a pixel image into a binary image with values ​​of 0 and 255;

[0033] Figure 5 shows how the binarization process may lead to loss of text information, especially for pixels on the edge of the image;

[0034] FIG6 shows the results of the existing binarization algorithm, where text pixels are incorrectly labeled or background is mislabeled as text;

[0035] Figure 7 An example embodiment for generating a fused mask for inpainting is shown;

[0036] Figure 8 shows a detailed flow chart for generating a fusion mask for creating a patched image in an example embodiment;

[0037] Fig. 9 shows the morphological gradient provided as the difference between the dilated image and the binarized eroded image;

[0038] Fig.10 Shows how morphological gradients can more accurately detect text edge pixels, but fail when the text and background are in low contrast;

[0039] Fig.11 The steps for implementing a contour mask in an example embodiment are shown;

[0040] Fig.12 shows a contour mask generated from an edge image;

[0041] Fig.13 Shows why a contour mask is needed in addition to a binary mask;

[0042] Fig.14 shows a process for generating a binary mask in an example embodiment;

[0043] Fig.15The figure shows a binary image obtained by processing a grayscale image using a Contrast Limited Adaptive Histogram Equalization (CLAHE) algorithm;

[0044] Fig.16 shows the input image after binarization of L in HLS compared with other methods;

[0045] Fig.17 An example of binarizing an input image using principal component analysis (PCA) is shown, compared to other methods that only set thresholds and segment text boundaries;

[0046] Fig.18 Examples of low contrast or low illumination and the resulting binary images are shown;

[0047] Fig.19 A vertical histogram projection is shown, which projects the black-white variation of each column and finds the starting column of the stroke edge;

[0048] Fig. 20 A horizontal histogram projection is shown, which projects the sum of pixel values ​​for each row and finds the starting row of the stroke edge;

[0049] Fig.21 is an example showing the benefit of binarization after segmentation;

[0050] Fig. 22 The calculated edge mask, contour mask and binary mask are combined to provide a fused mask;

[0051] Fig.23 The results of using a traditional binary mask are shown in Figure 2. Figure 7-22 Comparison of the results of the fused masks generated in the related description;

[0052] Fig.24 Other examples of technical benefits of applying fusion masks are shown;

[0053] Fig.25 The normalization process is shown, where the foreground is marked as white and the most similar mask is selected by comparing the binary mask candidates with the contour mask;

[0054] Fig.26 Shows the results when the text is mislabeled as background, and, in contrast, when the text is correctly labeled as foreground;

[0055] Fig. 27shows a comparison between the text removal and repair techniques described herein and conventional text removal and repair techniques used in conventional translator applications; and

[0056] Fig.28 According to an exemplary embodiment, the above-mentioned Figure 7-27 A block diagram of a circuit for generating a fused mask for image inpainting. DETAILED DESCRIPTION

[0057] It should be understood at the outset that although the following provides an illustrative implementation of one or more embodiments, Figure 7-28 The disclosed systems and / or methods may be implemented using any number of techniques, whether currently known or in existence. The present invention should in no way be limited to the illustrative embodiments, drawings, and techniques illustrated below, including the exemplary designs and embodiments illustrated and described herein, but may be modified within the scope of the appended claims along with their full scope of equivalents.

[0058] The following is a detailed description in conjunction with the accompanying drawings, which are part of the description and show, by way of illustration, specific embodiments in which the present invention may be implemented. These embodiments have been described in sufficient detail to enable those skilled in the art to practice the methods described herein, and it should be understood that other embodiments may be utilized and that structural, logical, and electrical changes may be made without departing from the scope of the present invention. Therefore, the exemplary embodiments described below are not intended to be limiting, and the scope of the present invention is defined by the appended claims.

[0059] The functions or algorithms described herein can be implemented by software in one embodiment. The software can include computer executable instructions stored on a computer-readable medium or a computer-readable storage device (e.g., one or more non-transient memories or other types of local or network storage devices based on hardware). In addition, these functions correspond to modules, which can be software, hardware, firmware, or any combination thereof. Multiple functions can be performed in one or more modules as needed, and the described embodiments are merely schematic. The software can be executed on a digital signal processor, an ASIC, a microprocessor, or other types of processors running on a computer system, such as a personal computer, a server, or other computer systems, thereby converting the computer system into a specifically programmed machine.

[0060] As described above, the systems and methods described herein extract an accurate mask for the text area to be inpainted based on normalizing the pixels of the background to pixels of one color (e.g., black) and normalizing the pixels of the foreground to pixels of another color (e.g., white) by using a binary mask, an edge mask, and a contour mask. At least two of the masks are combined into a fused mask, which is a combination of mask groups. The fused mask is a binary image with a pixel value of 0 or 255 at each pixel, where the pixel of a specific row and column will have a value of 255 if it is 255 in any mask. The value is 0 only if it is 0 in all fused masks. The fused mask is applied to the input image to extract the original background, thereby applying the inpainting algorithm. This method is also applicable even to images of low quality (e.g., handwritten text) or low illumination or non-uniform (e.g., fonts outlined in different colors or backgrounds of more than one color) or italic text.

[0061] Figure 7 An example embodiment for generating a fusion mask for inpainting is shown. In this example, edge detection 702 is applied to an original image 700 to convert a color image into a grayscale image, and the edges of the text are detected to form an edge mask. Based on the edge mask, a closed edge contour is found at 704, and white pixels marked as possible text are filled in the closed edge contour. Using a binarization method 706, a projection histogram is selected to detect stroke edges in a binary image. The image is segmented based on the stroke edges, and several binarization methods can be applied to each sub-image at 706 to obtain a binary mask. A normalization step is applied at 708 to set the text portion to white pixels for the binarization result and the background to black pixels for the binarization result. The best binary mask is selected from the candidate binary images. Of course, the normalization can also set the text portion to black pixels for the binarization result and the background to white pixels for the binarization result. At 710, at least two of the edge mask, the contour mask and the binary mask are combined into a fused mask, where the functions of each mask are to complement each other. Then, at 712, the fused mask is used together with a patching algorithm.

[0062] Figure 8 A detailed flow chart for generating a fusion mask for creating a patched image in an example embodiment is shown. Figure 8 As shown, the fused mask may have three components: an edge mask, a contour mask, and a binary mask, although any two of the three masks may be combined into the fused mask in an example embodiment. The process includes acquiring an input image at 802 and converting the input image to a grayscale image at 804. The system then generates an edge mask, a contour mask, and a binary mask to generate a fused mask as described below.

[0063] Edge Mask

[0064] In one example embodiment, two edge detectors are implemented: morphological gradient and Sobel operator. Morphological gradient finds the edges of text at 806 by determining the difference between the dilated image 902 (the expanded shape in the input image 900) and the eroded image 904 (the reduced shape in the input image 900). Fig. 9 As shown, the dilated image 902 may include additional pixels around the edge of the text, while the eroded image 904 includes a reduction in pixels around the edge of the text. The difference between the dilated image and the eroded image is that the text boundary image 906 is binarized to provide a morphological gradient 908, as shown in FIG. Fig. 9 shown.

[0065] On the other hand, the Sobel operator is applied to the grayscale image at 808 to detect edges in the horizontal and vertical directions. The Sobel operator is a discrete differential operator used to calculate an approximation of the gradient of the image intensity function. The Sobel operator is often used in edge detection algorithms to create an image that emphasizes edges.

[0066] Both edge detectors (Morphological Gradient 806 and Sobel operator 808) are robust enough to be used in images with low illumination and measurable noise. Fig.10 As shown, the morphological gradient 806 more accurately detects text edge pixels from the input image 1000, as shown in image 1002, but fails to detect when the contrast between the text and the background is low. However, as shown in image 1004, the Sobel operator 808 is a good supplement in this case.

[0067] As described below, contour masking and normalization are both based on edge masks.

[0068] Contour Mask

[0069] Fig.11The steps of implementing the contour mask in the exemplary embodiment are shown. As shown, the process of the contour mask starts from edge detection 1100. In the exemplary embodiment, morphological gradient edge detection 1102 and Sobel edge detection 1104 are applied to the grayscale image as described above. The closed text contours of each level are extracted from the morphological gradient edge image and the Sobel edge image using the findContour() algorithm in OpenCV. The algorithm realizes the topological structure analysis of the digitized binary image by tracking the boundary. Then, the pixels defined by the contours of the morphological gradient edge image and the Sobel edge image are filled using the connected component method by the drawContour() algorithm in OpenCV. These processes produce a morphological gradient contour mask 1106 and a Sobel contour mask 1108. At 1110, two types of contour masks 1106 and 1108 are combined into a final contour mask.

[0070] Contours are a type of shape descriptor that is useful for text detection. Fig.12 As shown, the text outline and the pixels within the filled outline are found to generate an outline mask 1200 from the edge image 1202. The outline mask 1200 can be used to repair the artificial font characters. Fig.13 In FIG. 1 , the binarization or edge detection of the input image 1300 only segments the boundaries of the text, as shown in 1302. However, contour filling as shown in 1304 solves this problem. In the contour mask 1304, the text pixels are marked as white, the background pixels are marked as black, and the contour mask 1304 finds most of the text pixels.

[0071] Reference again Figure 8 A contour mask is generated from the output of the morphological gradient process 806 and the Sobel edge process 808 by binarization of the corresponding edge masks at 810 and 812 and filling of the corresponding contours at 814 and 816. The corresponding filled contours are combined into a contour mask at 818. In an example embodiment, the contour mask is normalized to a black background with white text.

[0072] Binary mask

[0073] Most binarization methods have threshold limits. It is best to provide a threshold that can be used in a variety of different environments to handle a variety of different situations, because sometimes one binarization produces better results than other binarizations, and vice versa. Therefore, three different Otsu-based binarization methods and candidate lists are provided for consideration as the final binary mask in the example embodiment. Of course, more than three binarization methods can also be implemented to handle all input image situations.

[0074] Fig.14The process of generating a binary mask in an exemplary embodiment is shown. Fig.14 As shown, at 1402, an input image 1400 is provided to one or more binarization algorithms. In an example embodiment, three different binarization options are provided for use under different conditions.

[0075] The first binarization method consists in the application of the CLAHE algorithm binarization applied to the L channel of the LAB color space (L refers to lightness, A refers to the green-red color components, and B refers to the blue-yellow color components). The CLAHE process uses image enhancement for preprocessing. First, histogram equalization is applied only on the L channel to enhance the contrast of the color image while maintaining brightness and avoiding amplifying noise. Then, the enhanced color image is thresholded by the Otsu global binarization algorithm. Fig.15 A binary image 1500 is shown which results from processing a grayscale image 1502 using the CLAHE algorithm.

[0076] The second binarization method involves binarization of the L channel of the HLS color space. Since the L channel represents black and white in color, it is very sensitive to light changes or shadows in the image. In this way, this binarization method is very robust in low-contrast images. Fig.16 An input image 1600 after binarization of L in HLS at 1602 is shown compared to other methods at 1604 .

[0077] The third binarization method provides binarization using PCA of LAB color space. PCA finds the major and minor axes in LAB color space and finds the mean of the image. PCA is very sensitive to color space but not to brightness. The PCA binarization method is particularly useful for those fancy characters. Fig.17 An example of binarizing an input image 1700 using PCA is shown at 1702. As shown at 1704, other methods only set a threshold and segment the boundaries of the text, while PCA selects the dominant values ​​and correctly segments the text pixels.

[0078] Reference again Fig.14 , after binarizing the input image at 1402, stroke edge detection by horizontal histogram projection and vertical histogram projection is applied at 1404. Although binarization is effective in most cases, the binarization process may still fail when the background is complex or a part of the input image has low contrast. Fig.18 Examples of low contrast or low illumination at 1800 and 1802 and the resulting binary images at 1804 and 1806 are shown. Stroke edge detection at 1404 aims to detect edges where illumination or contrast changes are apparent.

[0079] like Fig.19 As shown, the black and white changes of each column in the image 1900 are projected by vertical histogram projection, and the starting column of the stroke edge 1902 is found in the histogram 1904. Fig. 20 As shown, the sum of the pixel values ​​of each row in the input image 2000 is projected by horizontal histogram projection, and the starting row of the stroke edge 2002 is found in the histogram 2004.

[0080] After the stroke edges of the image are detected at 1404, the original image is segmented into sub-images at 1406, and the corresponding binarization methods are applied to each of them. In this way, although it works with the global binarization method, the result benefits from the advantages of local binarization. In addition, the method automatically sets the window size and is robust enough to be adjusted for different situations. Fig.21 2104 and 2106 provide inferior results when binarized before segmentation than when binarized after segmentation as shown at 2108 and 2110.

[0081] Each binarization result and its inverse binary image are provided in a binary mask candidate list for selection at 1408. The best binary image in the candidate list is evaluated using the techniques described below and selected as the binary mask.

[0082] Reference again Figure 8 , detect stroke edges at 820, segment by horizontal and vertical projections of the L channel in the HLS binary image at 822, and calculate 6 binarization candidates at 822 to generate a binary image 824. The 6 binarization candidates in the example embodiment include CLAHE in LAB color space binarization and its inverse calculated at 826, PCA in LAB color space binarization and its inverse calculated at 828, and the L channel of HLS color space binarization and its inverse calculated at 830. At 832, each binary image and its inverse binary image are compared with the contour mask to identify the binary image with the smallest difference. At 834, the binary image with the smallest difference is normalized to provide a binary image with white characters and a black background.

[0083] Fusion Mask

[0084] The fused mask is implemented by combining any two or more of the edge mask, contour mask, and binary mask determined as described above at 836 . Fig. 22The calculated edge mask 2200, contour mask 2202 and binary mask 2204 are shown in combination to provide a fused mask 2206. The advantage provided by each mask is to ensure that the text pixels in the original image are completely covered. The resulting fused mask is then expanded and applied to the original image to apply a patching algorithm at 838, such as the aforementioned Telea patching algorithm. The patching algorithm searches for pixels on the outer edge of the text area and then fills the background image into the text area. The resulting image 840 does not contain all the text, and the text portion of the image is filled with background image data.

[0085] In general, the above combination Figure 7-22 The described embodiments are robust enough to handle a variety of different raw images, including handwritten images, fonts with additional outlines in different font colors, and backgrounds with more than one color. Fig.23 As shown, the fused mask marks all possible text pixels for inpainting. On the other hand, the conventional binary mask 2300 may mislabel the text pixels of the original image 2302, especially along the edges. As shown at 2304, it guides the inpainting to fill the background with a mixture of background and text colors. Figure 7-22 The resulting fused mask 2306 completely removes the text and restores the background, as shown at 2308.

[0086] Fig.24 Other examples of technical benefits of applying a fused mask to images 2402 and 2404 are shown. As shown at 2406 and 2408, the fused mask is robust to removal of all types of text.

[0087] As mentioned above, the normalization of the binarization result is the process of calculating the similarity between the contour mask and the binary mask candidates and then selecting the best binary image. Fig.25 As shown, the process requires using each binary mask candidate determined at 822 and comparing the calculated binary mask 2500 and the inverse binary mask 2502 with the contour mask 2504 to determine the most similar mask for selection at 2506. This normalization not only selects the binary mask, but also determines the text as the foreground labeled white and the background labeled black because the contour mask is the standard. If the text pixels are incorrectly labeled, the repair will be performed in the opposite way. For example, if Fig.26 As shown, when the text in the original image 2600 is mislabeled as the background at 2602, the background is filled with the text color at 2604. However, when the text in the original image 2600 is correctly labeled as the foreground at 2606, the background is filled with the background color at 2608.

[0088] Fig. 27A comparison between the text removal and repair techniques described herein and conventional text removal and repair techniques used in conventional translator applications is shown. Examples 2700 and 2702 both include artificial characters. As shown in 2704 and 2706, the results of the conventional translator application still have text residues, while the results using the text removal and repair techniques described herein have no text residues (2708 and 2710).

[0089] The technique described in this paper aims to extract a mask for inpainting by applying multiple features of the text image and selecting the best binary segmentation among a set of candidates. The fused mask is a combination of any two or more of the edge mask, contour mask, and binary mask to accurately mark the pixels for inpainting. The normalization process selects the optimal binary mask that is most similar to the contour mask and guarantees that the text pixels are marked as foreground. The resulting mask for inpainting the text area is suitable for many situations, especially in cases of low image quality or uneven lighting. The resulting image inpainting can have applications for removing unwanted areas in an image or restoring useful background information. Such applications include translator applications, image restoration related applications such as healing image tools on mobile platforms, and other applications for video inpainting or reduced reality. Due to the fast processing speed, it is particularly useful for real-time mobile platforms.

[0090] Fig.28 According to an exemplary embodiment, the above-mentioned Figure 7-27 A block diagram of a circuit for generating a fusion mask for image patching. It is not necessary to use all components in various embodiments. An example computing device in the form of a computer 2800 may include a processing unit 2802, a memory 2803, a removable memory 2810, and a non-removable memory 2812. Although the example computing device is shown and described as a computer 2800, the computer 2800 may have different forms in different embodiments. For example, the computer 2800 may be a smart phone, a tablet computer, a smart watch, or other computing device. Devices such as smart phones, tablet computers, and smart watches are generally referred to as mobile devices or user devices. In addition, although the various data storage elements are shown as part of the computer 2800, the memory may also or alternatively include a cloud-based storage accessed via a network (e.g., the Internet or a server-based storage). At the same time, the method described herein can be implemented in a pipeline on a processing thread, or multiple processors and / or multiple processing threads can be used as appropriate.

[0091] Memory 2803 may include volatile memory 2814 and nonvolatile memory 2808. Computer 2800 may also include or have access to a computing environment that includes various computer-readable media, such as volatile memory 2814 and nonvolatile memory 2808, removable memory 2810, and non-removable memory 2812. Computer storage includes random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM) or electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CDROM), digital versatile disc (DVD) or other optical disk storage, magnetic cassettes, magnetic tape, disk storage or other magnetic storage devices, or any other medium capable of storing computer-readable instructions.

[0092] The computer 2800 may include or have access to a computing environment including an input interface 2806 for receiving an input image for processing, an output interface 2804 for providing the processed image to a display 2805, and a communication interface 2816. The display 2805 may include a display device, such as a touch screen, which may also be used as an input device. The input interface 2806 may include a touch screen, a touch pad, a mouse, a keyboard, a camera, one or more device-specific buttons, one or more sensors integrated in the computer 2800 or coupled to the computer 2800 via a wired or wireless data connection, and one or more of other input devices. The computer 2800 may be operated in a network environment using a communication connection to connect to one or more remote computers, such as a database server. The remote computer may include a personal computer (PC), a server, a router, a network PC, a peer device, or other common DFD network switches, etc. The communication connection may include a local area network (LAN), a wide area network (WAN), a cellular network, Wi-Fi, Bluetooth, or other networks. According to one embodiment, various components of the computer 2800 are connected to a system bus 2820.

[0093] Computer readable instructions stored on a computer readable medium may be executed by a processing unit 2802 of a computer 2800, such as a program 2818. In some embodiments, the program 2818 includes software that, when executed by the processing unit 2802, performs image processing operations according to any of the embodiments included herein. Hard disks, CD-ROMs, and RAM are some examples of items that include non-transitory computer readable media (e.g., storage devices). The terms computer readable media and storage devices do not include carrier waves because they are considered too short-lived. Storage may also include network storage, such as a storage area network (SAN). The computer program 2818 may include instruction modules that, when processed, cause the processing unit 2802 to perform one or more methods or algorithms described herein.

[0094] In an exemplary embodiment, the computer 2800 includes: an edge detection module, which applies edge detection to detect the edge of the text in the original image as an edge mask; an edge mask module, which uses the edge mask to find a set of hierarchical closed edge contours of the text and fills the pixels marked as possible text in the closed edge contours as a contour mask; a binarization module, which applies a binarization method to the original image to convert the original image into a binary image and detect the stroke edges of the text in the binary image; a segmentation module, which segments the binary image based on the detected stroke edges of the text in the binary image, and applies at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for patching; a combination module, which combines at least two of the edge mask, the contour mask and the binary mask into a fused mask, performs a fused mask on the original image to extract the text in the original image, and obtains the original background of the original image that does not contain the text; and a patching module, which is used to patch each part of the original image where the text is extracted. In some embodiments, the computer 2800 may include other modules or additional modules for performing any step or combination of steps in the embodiments. In addition, any additional or alternative embodiments or aspects of the method (as shown in any drawings or described in any claims) are also contemplated to include similar modules.

[0095] Although several embodiments are described in detail above, other modifications may be made. For example, the logic flows depicted in the accompanying drawings need not be in the particular order or sequential order shown to achieve the desired results. Other steps may be provided or deleted from the flow, and other components may be added to or removed from the system. Other embodiments may be within the scope of the appended claims.

[0096] It should also be understood that software including one or more computer executable instructions that facilitate performing the processes and operations described above in connection with any or all of the steps of the present invention can be installed in and sold with one or more computing devices consistent with the present invention. Alternatively, the software can be acquired and loaded into one or more computing devices, including acquiring the software through a physical medium or distribution system, including, for example, acquiring the software from a server owned by the creator of the software or from a server that is not owned by the creator of the software but is used by the creator of the software. The software can be stored on a server for distribution, for example, over the Internet.

[0097] At the same time, it will be appreciated by those skilled in the art that the present invention is not limited in its application to the construction details and component arrangements shown in the description or in the accompanying drawings. The embodiments herein may be other embodiments and can be practiced or implemented in various ways. At the same time, it should be understood that the wording and terminology used herein are for descriptive purposes and should not be considered restrictive. The usage of "including", "comprising" or "having" and its variants in this article is intended to include the items listed thereafter and their equivalents and other items. In addition, the terms "connected" and "coupled" and their variants are not limited to physical or mechanical connections or couplings. In addition, terms such as top, bottom, bottom and top are relative and are used to assist in explanation, but are not restrictive.

[0098] The components of the illustrative devices, systems, and methods employed in accordance with the described embodiments may be implemented at least in part in digital electronic circuitry, analog electronic circuitry, or in computer hardware, firmware, software, or a combination thereof. For example, these components may be implemented as a computer program product, such as tangibly embodied in an information carrier or machine-readable storage device as a computer program, program code, or computer instructions for execution by or to control the operation of a data processing apparatus such as a programmable processor, a computer, or multiple computers.

[0099] Computer programs can be written in any form of programming language, including compiled languages ​​or interpreted languages, and can be deployed in any form, including as stand-alone programs or as modules, components, subroutines, or other units suitable for use in a computing environment. Computer programs can be deployed on one or more computers for execution, or they can be distributed on multiple sites and interconnected through a communication network. At the same time, programmers in the field of the technology described herein can easily understand that the functional programs, codes, and code paragraphs used to implement the technology described herein are included in the scope of the claims. The method steps associated with the illustrative embodiments can be performed by one or more programmable processors to execute computer programs, codes, or instructions to perform functions (e.g., by operating on input data and / or generating output). The method steps can also be performed by a dedicated logic circuit, and the device for performing the method can be implemented as a dedicated logic circuit, such as a field programmable gate array (FPGA) or an application-specific integrated circuit (ASIC), etc.

[0100] The various illustrative logic blocks, modules, and circuits described herein may be implemented or executed by a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination designed to perform the functions described herein. The general purpose processor may be a microprocessor, and optionally, the general purpose processor may also be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented by a combination of computing devices, such as a digital signal processor and a microprocessor, a plurality of microprocessors, one or more microprocessors in conjunction with a digital signal processor core, or any other similar configuration.

[0101] For example, processors suitable for executing computer programs include general and special microprocessors, and any one or more processors of any digital computer. Typically, the processor will receive instructions and data from ROM or RAM or both. The elements required for the computer are a processor for executing instructions and one or more memory devices for storing instructions and data. Typically, the computer will also include or be operably coupled to receive or transmit data from or to one or more large-capacity storage devices (such as magnetic, magneto-optical disks or optical disks) for storing data or both simultaneously. Information carriers suitable for embodying computer program instructions and data include all forms of non-volatile memory, including, for example, semiconductor memory devices, for example, EPROM or ROM, EEPROM, flash memory devices, data storage disks (such as magnetic disks, built-in hard disks or removable disks, magneto-optical disks, CD-ROMs and DVD-ROMs). The processor and memory can be supplemented by a dedicated logic circuit, or incorporated into a dedicated logic circuit.

[0102] Those skilled in the art will appreciate that information and signals may be represented using any of a variety of different technologies and methods. For example, the data, instructions, commands, information, signals, bits, symbols, and chips described above may be represented by voltage, current, electromagnetic waves, magnetic fields or particles, optical fields or particles, or any combination thereof.

[0103] As used herein, "machine-readable medium" refers to a device capable of temporarily or permanently storing instructions and data, and may include, but is not limited to, RAM, ROM, buffer memory, flash memory, optical media, magnetic media, cache memory, other types of storage (e.g., EEPROM), and / or any suitable combination thereof. The term "machine-readable medium" should be understood to include a single medium or multiple media (e.g., a centralized or distributed database, or associated caches and servers) that can store processor instructions. The term "machine-readable medium" should also be considered to include any medium or combination of multiple media capable of storing instructions executed by one or more processors 2802, which, when executed by one or more processors 2802, causes the one or more processors 2802 to perform any one or more methods described herein. Accordingly, "machine-readable medium" refers to a single storage device or device, as well as a "cloud-based" storage system or storage network including multiple storage devices or devices. Because signals are considered too transient, the term "machine-readable medium" used herein does not include such signals themselves.

[0104] In addition, without departing from the scope of the present invention, the techniques, systems, subsystems and methods described and illustrated as discrete or separate in the various embodiments may be combined or integrated with other systems, modules, techniques or methods. Other items shown or discussed as coupled or directly coupled or communicating with each other may also be coupled or communicated indirectly via an interface, device or intermediate component, either electrically, mechanically or otherwise. Other variations, substitutions and altered examples may be determined by those skilled in the art without departing from the spirit and scope of the disclosure herein.

[0105] Although the present invention has been described with reference to specific features and embodiments of the present invention, it is apparent that various modifications and combinations of the present invention may be made without departing from the present invention. The specification and drawings are to be regarded only as illustrations of the present invention as defined by the appended claims and any and all modifications, variations, combinations or equivalents falling within the scope of the present invention are contemplated.

Claims

1. A computer-implemented method for finding a text mask in an original image to extract text for inpainting, characterized in that include: applying edge detection by one or more processors to detect edges of text in the original image as an edge mask; The one or more processors use the edge mask to find a set of hierarchical closed edge contours of the text, and fill the pixels marked as possible text in the set of hierarchical closed edge contours as a contour mask; Applying a binarization method to the original image by the one or more processors to convert the original image into a binary image and detecting stroke edges of the text in the binary image; Segmenting the binary image based on the detected stroke edges of the text in the binary image by the one or more processors, and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for inpainting; combining, by the one or more processors, at least two of the edge mask, the contour mask, and the at least one binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining an original background of the original image that does not contain the text; and Inpainting is performed by the one or more processors on respective portions of the original image from which the text is extracted.

2. The method according to claim 1, characterized in that Also includes: The original image is converted to a grayscale image before applying the edge detection.

3. The method according to claim 2, characterized in that Applying the edge detection includes applying at least one of a morphological gradient edge detection algorithm or a Sobel operator edge detection algorithm to the original image to detect the edge of the text in the original image.

4. The method according to claim 3, characterized in that The method of using the edge mask to find a set of hierarchical closed edge contours of the text includes applying the morphological gradient edge detection algorithm to the original image to create a morphological gradient contour mask, applying the Sobel operator edge detection algorithm to the grayscale image to create a Sobel contour mask, and combining the morphological gradient contour mask with the Sobel contour mask to create the contour mask.

5. The method according to any one of claims 1 to 4, characterized in that Also included is applying a connected component method to fill pixels defined by the contour mask to fill the set of hierarchical closed edge contours.

6. The method according to claim 5, characterized in that The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image comprises at least one of the following: Binarizing the brightness channel in the chroma, brightness and saturation color space of the original image to enhance the contrast of the original image; Binarizing the contrast-limited adaptive histogram equalization of the LAB color space binarization to enhance the contrast of the original image; The brightness channel of the LAB color space is binarized by applying principal component analysis binarization to enhance the contrast of the original image.

7. The method according to claim 6, characterized in that The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image further comprises: The best binary image is selected from the binary images generated by each binarization method.

8. The method according to claim 6, characterized in that The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image comprises at least one of the following: Taking the inverse value of the binarized brightness channel in the chroma, brightness and saturation color space of the original image; Taking the inverse value of the binarized contrast-limited adaptive histogram equalization of the LAB color space binarization; Take the inverse of the principal component analysis binarization.

9. The method according to claim 8, characterized in that The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image further comprises: The best binary image is selected from the binary images generated by each binarization method and each inverse binarization method.

10. The method according to any one of claims 1 to 4 and 6 to 9, characterized in that: The segmenting of the binary image based on the detected stroke edges of the text in the binary image includes: segmenting the binary image into sub-images through horizontal and vertical histogram projections, and binarizing the sub-images.

11. The method according to any one of claims 1 to 4 and 6 to 9, characterized in that: Also includes: The binary image is normalized by the one or more processors to set the text as pixels of a first color, set the original background as pixels of a second color, and select an optimal binary mask from the at least one binary mask candidate.

12. An image processing device, characterized in that: include: A non-transitory memory including instructions; as well as One or more processors in communication with the memory, wherein the one or more processors execute the instructions to find a text mask in the original image to extract text for inpainting by: Applying edge detection to detect edges of text in the original image as an edge mask; Finding a set of hierarchical closed edge contours of the text using the edge mask, and filling pixels marked as possible text in the set of hierarchical closed edge contours as contour masks; Applying a binarization method to the original image to convert the original image into a binary image and detecting stroke edges of the text in the binary image; Segmenting the binary image based on the detected stroke edges of the text in the binary image, and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for inpainting; Combining at least two of the edge mask, the contour mask and the at least one binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining an original background of the original image that does not contain the text; as well as Inpainting is performed on portions of the original image where the text is extracted.

13. The device according to claim 12, characterized in that The one or more processors also execute the instructions to convert the original image to a grayscale image before applying the edge detection.

14. The device according to claim 13, characterized in that The one or more processors also execute the instructions to apply the edge detection by applying at least one of a morphological gradient edge detection algorithm or a Sobel operator edge detection algorithm to the original image to detect the edge of the text in the original image.

15. The device according to claim 14, characterized in that The one or more processors also execute the instructions to use the edge mask to find a set of hierarchical closed edge contours of the text by the following steps: applying the morphological gradient edge detection algorithm to the original image to create a morphological gradient contour mask, applying the Sobel operator edge detection algorithm to the grayscale image to create a Sobel contour mask, and combining the morphological gradient contour mask with the Sobel contour mask to create the contour mask.

16. The device according to any one of claims 12 to 15, characterized in that The one or more processors also execute the instructions to apply a connected components method to fill pixels defined by the contour mask to fill the set of hierarchical closed edge contours.

17. The device according to claim 16, characterized in that The one or more processors further execute the instructions to apply the binarization method to the original image to convert the original image into the binary image and detect the stroke edges of the text in the binary image through at least one of the following steps: Binarizing the brightness channel in the chroma, brightness and saturation color space of the original image to enhance the contrast of the original image; Binarizing the contrast-limited adaptive histogram equalization of the LAB color space binarization to enhance the contrast of the original image; The brightness channel of the LAB color space is binarized by applying principal component analysis binarization to enhance the contrast of the original image.

18. The device according to claim 17, characterized in that The one or more processors further execute the instructions to apply the binarization method to the original image to convert the original image into the binary image and detect the stroke edges of the text in the binary image through the following steps: The best binary image is selected from the binary images generated by each binarization method.

19. The device according to claim 17, characterized in that The one or more processors further execute the instructions to apply the binarization method to the original image through at least one of the following steps to convert the original image into the binary image and detect the stroke edges of the text in the binary image: Taking the inverse value of the binarized brightness channel in the chroma, brightness and saturation color space of the original image; Taking the inverse value of the binarized contrast-limited adaptive histogram equalization of the LAB color space binarization; Take the inverse of the principal component analysis binarization.

20. The device according to claim 17, characterized in that The one or more processors further execute the instructions to apply the binarization method to the original image through the following steps to convert the original image into the binary image and detect the stroke edges of the text in the binary image: The best binary image is selected from the binary images generated by each binarization method and each inverse binarization method.

21. The device according to any one of claims 12 to 15 and 17 to 20, characterized in that The one or more processors also execute the instructions to segment the binary image based on the detected stroke edges of the text in the binary image by the following steps: segmenting the binary image into sub-images by horizontal and vertical histogram projections, and binarizing the sub-images.

22. The device according to any one of claims 12-15, 17-20, characterized in that The one or more processors also execute the instructions to normalize the binary image to set the text as pixels of a first color, set the original background as pixels of a second color, and select an optimal binary mask from the at least one binary mask candidate.

23. A non-transitory computer readable medium storing computer instructions to find a text mask in an original image to extract text for inpainting, characterized in that When one or more processors execute the computer instructions, the one or more processors perform the following steps: Applying edge detection to detect edges of text in the original image as an edge mask; Finding a set of hierarchical closed edge contours of the text using the edge mask, and filling pixels marked as possible text in the set of hierarchical closed edge contours as contour masks; Applying a binarization method to the original image to convert the original image into a binary image and detecting stroke edges of the text in the binary image; Segmenting the binary image based on the detected stroke edges of the text in the binary image, and applying at least one binarization method to each image partition to obtain at least one binary mask candidate as a foreground for inpainting; Combining at least two of the edge mask, the contour mask and the at least one binary mask into a fused mask, applying the fused mask to the original image to extract the text in the original image, and obtaining an original background of the original image that does not contain the text; as well as Inpainting is performed on portions of the original image where the text is extracted.

24. The computer-readable medium of claim 23, wherein: The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image comprises at least one of the following: Binarizing the brightness channel in the chroma, brightness and saturation color space of the original image to enhance the contrast of the original image; Binarizing the contrast-limited adaptive histogram equalization of the LAB color space binarization to enhance the contrast of the original image; The brightness channel of the LAB color space is binarized by applying principal component analysis binarization to enhance the contrast of the original image.

25. The computer-readable medium of claim 23, wherein: The step of applying a binarization method to the original image to convert the original image into a binary image and detecting the stroke edges of the text in the binary image further comprises: The best binary image is selected from the binary images generated by each binarization method.