A method, device and equipment for determining binary text image and storage medium
By alternating between grayscale processing and gradient information matrix minimization, the problem of identifying multiple defects in color document images is solved, improving the recognition efficiency and accuracy of binarized text images, and making it suitable for practical applications.
Patent Information
- Application Number
- CN202211353542.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-01
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-11-01
AI Technical Summary
Existing technologies struggle to effectively identify character outlines when processing color document images containing various image defects, resulting in low recognition efficiency and accuracy. Furthermore, the use of multiple tools increases complexity and raises the barrier to entry for users.
By acquiring text images and performing grayscale processing, detecting text contour gradient information, determining the contour gradient information matrix, and performing alternating minimization processing to reduce the difference in grayscale values inside and outside the text, and finally performing binarization processing to remove image defects.
It enables convenient removal of defects such as stains, uneven lighting, and shadows from images, improving the recognition efficiency and accuracy of binarized text images, and is suitable for practical applications.
Smart Images

Figure CN115909352B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and in particular to a method, apparatus, device, and storage medium for determining binarized text images. Background Technology
[0002] In OCR (Optical Character Recognition), directly extracting characters from color images is relatively difficult. Because color images contain a vast amount of information, the outlines of characters are hard to discern, necessitating image binarization. Binary images play a crucial role in digital image processing, significantly reducing the amount of information in the original image and highlighting the outlines of the target, thereby improving the efficiency and accuracy of recognition. Researchers across various disciplines frequently encounter document images containing large amounts of textual information, such as books, papers, and various printed documents. These document images often suffer from various defects, such as stains, ink bleeds, degradation over time in ancient historical materials, uneven lighting caused by multiple light sources (sunlight, indoor / outdoor lighting), and shadows caused by obstructions. These problems have diverse characteristics. In previous processing methods, each problem was handled by a dedicated algorithm. However, when dealing with images with multiple defects, the previous processing introduces uncertainty into the next step, and the use of multiple tools increases complexity and the user's learning curve, hindering practical application. Summary of the Invention
[0003] In view of this, in order to solve at least one of the above-mentioned technical problems, the object of the present invention is to provide a convenient method, apparatus, device and storage medium for determining binary text images.
[0004] The technical solution adopted in the embodiments of the present invention is as follows:
[0005] A method for determining a binarized text image, comprising:
[0006] Acquire a text image and perform grayscale processing on the text image to obtain a grayscale image;
[0007] Detect the text outline gradient information of the grayscale image;
[0008] The contour gradient information matrix is determined based on the text contour gradient information and the gradient threshold.
[0009] The target text image is obtained by performing alternating minimization processing based on the contour gradient information matrix and the grayscale image; the alternating minimization processing is used to reduce the difference between the grayscale values inside and outside the text.
[0010] The target text image is binarized to obtain a binarized text image.
[0011] Furthermore, the step of performing grayscale processing on the text image to obtain a grayscale image includes:
[0012] Calculate the first product of the preset first weighting factor and the first channel value of the text image;
[0013] Calculate the second product of the preset second weighting factor and the second channel value of the text image;
[0014] Calculate the third product of the preset third weighting factor and the third channel value of the text image;
[0015] The grayscale image is obtained by summing the first product, the second product, and the third product.
[0016] Furthermore, detecting the text outline gradient information of the grayscale image includes:
[0017] Determine detection points from the text in the grayscale image;
[0018] Starting from the detection point, detection is performed along each width direction of the text according to the rotation angle to obtain the text contour gradient information.
[0019] Furthermore, the text contour gradient information includes a one-dimensional contour corresponding to each width direction. Determining the contour gradient information matrix based on the text contour gradient information and a gradient threshold includes:
[0020] A pixel group is determined in a one-dimensional contour corresponding to the same width direction; the pixel group includes a first pixel and a second pixel, and the first pixel is adjacent to the second pixel.
[0021] When the difference between the first pixel and the second pixel of the pixel group is greater than the gradient threshold, or when the difference between the first pixel and the second pixel of the pixel group is less than the negative gradient threshold, the contour gradient information matrix is constructed based on the first pixel.
[0022] Further, the step of alternating minimization processing based on the contour gradient information matrix and the grayscale image to obtain the target text image includes:
[0023] A smooth image is obtained by Fourier transforming the adaptive parameters, the unit vector of the rotation angle starting from the detection point, the grayscale image, and the contour gradient information matrix.
[0024] The adaptive parameters, the gradient threshold, and the smoothed image are updated according to the objective function until a preset termination condition is reached, thereby obtaining the target text image.
[0025] Further, the step of updating the adaptive parameters, the gradient threshold, and the smoothed image according to the objective function until a preset termination condition is reached to obtain the target text image includes:
[0026] The gradient threshold and the adaptive parameters are updated based on the minimum value of the objective function; the objective function is determined based on the sum of a first factor and a second factor; the first factor is the product of the square of a first difference and the adaptive parameter, where the first difference is the difference between the differential gradient of adjacent pixels in the same width direction and the contour gradient information matrix; the second factor is the difference between the smoothed image and the grayscale image; the adaptive parameters are used to adjust the similarity between the differential gradient and the corresponding elements in the contour gradient information matrix.
[0027] The smoothed image is used as a new grayscale image. The step of detecting the text contour gradient information of the grayscale image is returned until a new smoothed image is obtained and the gradient threshold and the adaptive parameters are updated to complete one update iteration.
[0028] Repeat the update iteration until the preset termination condition is met, and use the smoothed image of the last update iteration as the target text image.
[0029] Furthermore, the binarization process of the target text image to obtain a binarized text image includes:
[0030] The target text image is binarized using a binarization algorithm to obtain a binarized text image.
[0031] This invention also provides a device for determining a binarized text image, comprising:
[0032] The acquisition module is used to acquire text images and perform grayscale processing on the text images to obtain a grayscale image;
[0033] The detection module is used to detect the text outline gradient information of the grayscale image;
[0034] The determining module is used to determine the contour gradient information matrix based on the text contour gradient information and the gradient threshold.
[0035] The first processing module is used to perform alternating minimization processing based on the contour gradient information matrix and the grayscale image to obtain the target text image; the alternating minimization processing is used to reduce the difference between the grayscale values inside and outside the text.
[0036] The second processing module is used to perform binarization processing on the target text image to obtain a binarized text image.
[0037] This invention also provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction, at least one program, a code set, or an instruction set. The at least one instruction, the at least one program, the code set, or the instruction set are loaded and executed by the processor to implement the method.
[0038] This invention also provides a computer-readable storage medium storing at least one instruction, at least one program, a code set, or an instruction set, wherein the at least one instruction, the at least one program, the code set, or the instruction set is loaded and executed by a processor to implement the method.
[0039] The beneficial effects of this invention are as follows: By acquiring a text image and performing grayscale processing on the text image to obtain a grayscale image, detecting the text contour gradient information of the grayscale image, determining the contour gradient information matrix based on the text contour gradient information and gradient threshold, performing alternating minimization processing based on the contour gradient information matrix and the grayscale image to obtain a target text image, and performing binarization processing on the target text image to obtain a binarized text image; by using the text contour gradient information to reduce the difference between grayscale values inside and outside the text, the binarized text image can easily remove image defects such as stains, uneven lighting, or shadows, which is beneficial for practical applications. Attached Figure Description
[0040] Figure 1 This is a schematic diagram of the steps of the method of the present invention;
[0041] Figure 2 (a) is a schematic diagram of the document image before processing in a specific embodiment of the present invention. Figure 2 (b) is a schematic diagram of the processed document image. Figure 2 (c) is a one-dimensional signal diagram of the document image before processing. Figure 2 (d) is a one-dimensional signal diagram of the processed document image;
[0042] Figure 3 This is a priori schematic diagram of a two-dimensional signal according to a specific embodiment of the present invention;
[0043] Figure 4 This is a schematic diagram of the binarized text image generation process according to a specific embodiment of the present invention;
[0044] Figure 5 This is a schematic diagram showing the results comparison of a specific embodiment of the present invention, DIBCO 2011-HW1;
[0045] Figure 6 For specific embodiments of the present invention, parameters W and t 2 Relationship diagram;
[0046] Figure 7 This is a schematic diagram showing the results of a specific embodiment of the present invention, H-DIBCO 2018-4. Detailed Implementation
[0047] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0048] The terms "first," "second," "third," and "fourth," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or apparatus that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or apparatuses.
[0049] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of this application. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0050] like Figure 1 As shown, this embodiment of the invention provides a method for determining a binarized text image, including steps S100-S500:
[0051] S100. Acquire the text image and perform grayscale processing on the text image to obtain a grayscale image.
[0052] It should be noted that "text image" refers to an image containing text. Optionally, step S100 involves grayscale processing of the text image to obtain a grayscale image, including steps S110-S140. The execution order of steps S110, S120, and S130 is not limited.
[0053] S110, Calculate the first product of the preset first weighting factor and the first channel value of the text image.
[0054] S120, Calculate the second product of the preset second weighting factor and the second channel value of the text image.
[0055] S130, Calculate the third product of the preset third weighting factor and the third channel value of the text image.
[0056] S140. Based on the sum of the first product, the second product, and the third product, a grayscale image is obtained.
[0057] Specifically, the formula for calculating a grayscale image (Gray) is:
[0058] Gray = R*A1 + G*A2 + B*A3
[0059] Wherein, R is the first channel value, A1 is the first weighting factor, G is the second channel value, A2 is the second weighting factor, B is the third channel value, and A3 is the third weighting factor. It should be noted that in this embodiment of the invention, the second weighting factor is greater than the first weighting factor, which is greater than the third weighting factor. For example, the first weighting factor is 0.299, the second weighting factor is 0.587, and the third weighting factor is 0.144; in other embodiments, the values of each weighting factor can be set as needed.
[0060] S200: Detect the gradient information of the text outline in the grayscale image.
[0061] like Figure 2 As shown in (a), this is an image of a document with text before processing, such as... Figure 2 As shown in (c), this is a one-dimensional signal diagram of the document image before processing line L. It exhibits many gradient changes different from those in a clean document image. The areas of stains or shadows are generally larger. Within a certain range, only one side of the edge shows a large gradient change, while other non-text areas show varying degrees of amplitude, but most are not strong. For example... Figure 2 (b) shows the processed document image, as shown below. Figure 2As shown in (d), this is a one-dimensional signal diagram of the document image after processing line L. The brightness inside the text strokes is nearly uniform, and the brightness of the background pixels is similar. The large area of low brightness on the right side of the original signal has been removed, and the amplitude of the non-text area has been significantly reduced. The text outline becomes relatively smooth, and the signals inside and outside the text outline become flat. The text outline is sharpened, and the gradient abrupt changes in non-text areas become smooth. Meanwhile, it can be seen that the gradient changes of the text stroke outlines in both the pre-processed and post-processed document images are still similar to those in the clean document image. Therefore, the specific processing principle is to enhance the visual discernibility at the text outline by limiting the number of gradients that conform to this rule, while reducing gradient changes at other locations, so that the brightness inside the strokes and the external background becomes uniform.
[0062] Specifically, in the above processing, for a one-dimensional signal, the prior p(x) is defined as:
[0063] p(x) = #{i|x i -x i+1 >t,x i+w -x i+w+1 <-t,w≤W},
[0064] Where i and i+1 are any adjacent positions in the discrete signal (one-dimensional signal) x, x i -x i+1 It is the positive difference gradient, and t is the threshold of the gradient when x i -x i+1 When x > t, then i is considered to be at the left edge of the text (stroke). Similarly, when x > t, then i is considered to be at the left edge of the text (stroke). i+w -x i+w+1 When <-t, i is located at the right edge of the text (stroke), w is the width of a stroke in x, and W is the maximum width of the stroke in that signal; #{} is a counting operator, which returns x that meets the condition. i -x i+1 >t,x i+w -x i+w+1 The number of i <-t, w≤W. The specific one-dimensional signal objective function is:
[0065]
[0066] Among them, y i The original input signal, x i For the output signal, p(x) is the number of discrete signals that conform to the prior. λ is the weight of p(x) and is also a key parameter that controls the smoothness of the signal. λ is inversely proportional to p(x). When λ is set to be large, the result retains only a few effective contours.
[0067] In this embodiment of the invention, considering the similarity between the outline of text in a two-dimensional image and a one-dimensional signal, the detection of text outlines in a two-dimensional image is not only from a single direction but also has a single direction. The difference is that the detection of text outlines in a two-dimensional image is no longer from a single direction; the length of the text strokes may be greater than W1 mentioned above. Therefore, unidirectional detection is not suitable for texts containing long strokes. Figure 3 As shown, the strokes of a character may come from any direction, therefore the detection in this embodiment of the invention is performed from any direction.
[0068] Optionally, step S200 includes steps S210-S220:
[0069] S210. Determine the detection points from the text in the grayscale image.
[0070] S220. Starting from the detection point, perform detection along each width direction of the text according to the rotation angle to obtain the text outline gradient information.
[0071] Detection point 31 is determined from the text in the grayscale image, assumed to be position i in the text image. The arrows represent the various width directions of the text, and the distance between 31 and 32 is w. Specifically, detection is performed along the width of the arrow, starting from 31. A set of pixels passed through by the arrow segment in one width direction is considered a one-dimensional signal, and the one-dimensional text contour prior p(x) is used for this one-dimensional signal. It should be noted that the rotation angle between the arrow segment in each width direction and the x-axis is θ. By changing different θ, detection can be performed in multiple width directions, thereby determining the text contour gradient information. When there are enough detection directions and the angle θ between the arrow segment and the x-axis is discretely and uniformly distributed in [0, 2π), the text contour of the two-dimensional document image can be effectively detected. In this embodiment of the invention, in the two-dimensional image, our prior P(G) is defined as follows:
[0072]
[0073] Where i is the index of a pixel in image G, α θ G represents the unit vector of the rotation angle θ about the origin i. i Let i be the gray value of image G at position i. This represents the relationship between point i as the origin, angle θ, and point G. i The differential gradient between adjacent positions. w is the width of a character's stroke, and W2 is the maximum width of the character's stroke in image G. When a character outline is detected at index i in at least one direction, that position is considered to be the pixel containing the character outline. To facilitate solving the equation, the character edge detection process can be described as a convolution operation. For a grayscale image G, we have:
[0074]
[0075] in, This represents the gradient information in the grayscale image G along the x-direction, described in the form of forward difference. It is equivalent to filtering a single row of pixels along the x-direction of the image using a [1,-1] filter. The text edge gradient information is defined as matrix W', where each element ω... i,j for:
[0076]
[0077] l1≤k≤l2; i=1,L,M; j=1,L,N
[0078] Where, k * After restricting the stroke width k to l1≤k≤l2, when Minimize time We obtain that when the difference gradient k * We obtain 0, where M and N are the height and width of the image, respectively. In this embodiment of the invention, the objective function in a two-dimensional image is:
[0079]
[0080] Image G is a smoothed image obtained by minimizing equation (1), and I is the input image. The term guarantees the similarity of image structures. The value of the term λ·C(G) is constrained by the parameter λ. The prior term C(G) is:
[0081]
[0082] in, This represents the gradient information described in the form of forward difference along the x-direction in image G. Representative and Along the x-direction in adjacent ω i,j Gradient information at each position, where # is the counting symbol. Statistics The number of positions. Formula (1) involves discrete counting metrics, which are not differentiable. The global optimal problem is an NP-hard problem. Therefore, a semi-quadratic splitting alternating optimization strategy is used to relax the original problem into a quadratic programming problem.
[0083] S300. Determine the contour gradient information matrix based on the text contour gradient information and gradient threshold.
[0084] It should be noted that the text outline gradient information includes a one-dimensional outline corresponding to each width direction, that is, a set of pixels that an arrow line segment in a width direction passes through, or a one-dimensional signal corresponding to each width direction.
[0085] Optionally, step S300 includes steps S310-S320:
[0086] S310. Determine a pixel group in a one-dimensional contour corresponding to the same width direction; the pixel group includes a first pixel and a second pixel, and the first pixel and the second pixel are adjacent.
[0087] S320. When the difference between the first pixel and the second pixel of the pixel group is greater than the gradient threshold, or when the difference between the first pixel and the second pixel of the pixel group is less than the negative gradient threshold, a contour gradient information matrix is constructed based on the first pixel.
[0088] Specifically, pixel groups are determined within the width range w in each width direction. For example, the first pixel is the i-th pixel, the second pixel is the (i+a)-th pixel, and so on. θ For each pixel, if the difference between the first pixel and the second pixel is greater than the gradient threshold t, the first pixel is determined to be a left edge pixel, and the contour gradient information matrix is added as an element. When the first pixel is the i+w·a pixel... θ The first pixel is the i+(w+1)th pixel, and the second pixel is the i+(w+1)th pixel. θ For each pixel, when the difference between the first pixel and the second pixel is less than the negative gradient threshold -t, the first pixel is determined to be a right edge pixel and added to the contour gradient information matrix as an element. Therefore, the contour gradient information matrix (defined as the first contour gradient information matrix) includes the positions of edge points in each width direction.
[0089] In this embodiment of the invention, the specific solution of formula (1) is divided into two parts: solving the contour gradient information matrix and the smoothed image G. Auxiliary variables U and V are introduced, and the contour gradient information matrix is represented by auxiliary variables U and V. Formula (1) is rewritten in a point-by-point calculation form:
[0090]
[0091] Among them U ij This refers to the value of the element in the i-th row and j-th column of matrix U; V ij This refers to the value of the element in the i-th row and j-th column of matrix V; C(U,V)=#{i||U i |+|V i |≠0}, β is an adaptive parameter used to control the similarity between (U,V) and its corresponding gradient. When β is large enough, Equation (2) approaches Equation (1). G and (U,V) are obtained by alternating minimization. In each iteration, G and (U,V) are updated based on the values of the variables in the previous iteration.
[0092] In this embodiment of the invention, the contour gradient information matrix is obtained by solving for U and V using G in fixed formula (2):
[0093]
[0094] Where C(U,V) is |U i,j |+|V i,j The number of non-zero values in the matrix. For each pixel, this can be calculated using the following formula:
[0095]
[0096] In formula (3), b(|U i,j |+|V i,j |) is a binary function, if |U i,j |+|V i,j | ≠ 0 returns 1, otherwise returns 0. i,j It can be represented as:
[0097]
[0098] When formula (3) is minimized, (U i,j V i,j It can be obtained from the following formula:
[0099]
[0100] S400. The target text image is obtained by alternating minimization processing based on the contour gradient information matrix and the grayscale image.
[0101] In this embodiment of the invention, alternating minimization processing is used to reduce the difference between grayscale values inside and outside the text. Optionally, step S400 includes steps S410-S420:
[0102] S410. Based on the adaptive parameters, the unit vector of the rotation angle starting from the detection point, the grayscale image, and the contour gradient information matrix, a smooth image is obtained through Fourier transform processing.
[0103] S420. Update the adaptive parameters, gradient threshold, and smoothing image according to the objective function until the preset termination condition is met to obtain the target text image.
[0104] Specifically, steps S4201-S4202 are included:
[0105] S4201. Update the gradient threshold and adaptive parameters according to the minimum value of the objective function; the objective function is determined according to the sum of the first factor and the second factor; the first factor is the product of the square of the first difference and the adaptive parameter, the first difference is the difference between the differential gradient of adjacent pixels in the same width direction and the contour gradient information matrix; the second factor is the difference between the smoothed image and the grayscale image; the adaptive parameter is used to adjust the similarity of the corresponding elements in the differential gradient and the contour gradient information matrix.
[0106] S4202. Take the smoothed image as the new grayscale image, return to the step of detecting the text contour gradient information of the grayscale image, until a new smoothed image is obtained and the gradient threshold and adaptive parameters are updated to complete one update iteration. Repeat the update iteration until the preset termination condition is reached, and take the smoothed image of the last update iteration as the target text image.
[0107] In this embodiment of the invention, the smoothed grayscale image G is obtained by fixing U and V and omitting the λ·C(U,V) term in formula (2):
[0108]
[0109] because so
[0110]
[0111] Formula (5) contains at most quadratic terms, thus a global minimum can be obtained. Furthermore, by using the Fast Fourier Transform (FFT), the derivative operator is diagonalized and rewritten in matrix form, accelerating the solution process with the help of the Fourier Transform:
[0112]
[0113] in It is the Fast Fourier Transform operator. It is a complex conjugate operator. It is the Fourier transform of the δ function. Compared with minimizing expression (1) in image space, the calculation speed in the Fourier domain is much faster because a simple component division is used. Therefore, through the Fourier transform processing of formula (6), the smoothed image G can be obtained according to the adaptive parameter β, the grayscale image (input image I), and U and V that make up the contour gradient information matrix. It should be noted that when the smoothed image G is calculated for the first time, the contour gradient information matrix (U,V) is the contour gradient information matrix (first contour gradient information matrix) in step S300, while when the smoothed image G is updated in the subsequent steps, (U,V) is (U i V i (Second contour gradient information matrix).
[0114] Specifically, after estimating the smooth image G, the gradient threshold t and adaptive parameter β are updated according to the minimum value of the objective function (Formula (4)). The smooth image G is used as the new grayscale image, i.e., as the new input image I. The step of detecting the text contour gradient information of the grayscale image is returned, i.e., the steps S200-S400 are re-executed, i.e., the text contour gradient information of the new input image I is detected. The contour gradient information matrix (U,V) is updated according to the updated t. The new smooth image G is obtained by detection and re-estimation. The gradient threshold t and adaptive parameter β are updated again according to the minimum value of the objective function (Formula (4)). At this time, it is considered that one update iteration is completed. The parameters after this update iteration are used to repeat the iteration until the preset termination condition is reached. The smooth image G of the last update iteration is used as the target text image. It should be noted that the preset termination condition includes, but is not limited to, reaching the preset number of updates.
[0115] S500. Perform binarization processing on the target text image to obtain a binarized text image.
[0116] Specifically, the target text image is binarized using a binarization algorithm to obtain a binarized text image. Optionally, the binarization algorithm includes, but is not limited to, the grayscale average value method, the P-Tile method, the thresholding based on the minimum valley value, the OTU big law method, the binarization algorithm of SU, and the torque preservation method, etc.
[0117] like Figure 4 The diagram shows a specific processing flowchart of an embodiment of the present invention. The text image is used as the document image input. The input image is processed in grayscale to detect the text contour (information) in the image, thereby updating the contour gradient information matrix. The estimated smooth image G is obtained, which is equivalent to the first update of the smooth image G. The parameters (gradient threshold t and adaptive parameter β) are updated. Then, the smooth image G is used to iteratively update the text contour information in the image and update the contour gradient information matrix after detection. The updated smooth image G is estimated again. This process is repeated until the last updated smooth image G is applied to an arbitrary binarization algorithm to output a binary image (i.e., a binarized text image).
[0118] In summary, this invention proposes a novel text contour gradient prior for detecting the contours of text in text images. The text contours detected by this prior are used to unify the grayscale values inside and outside the text, and to remove degradation phenomena such as stains and uneven lighting in document images. Extensive experiments and data demonstrate that the proposed method is applicable to various document images with varying degrees of defects, and showcase its advantages and disadvantages.
[0119] like Figure 5As shown, we used the datasets provided by the DIBCO 2011-2018 text image binarization competition and a portion of the PHIBD 2012 dataset for experiments and evaluation. Regarding parameter settings, to accelerate the algorithm's computation speed, we avoided cumbersome image rotation operations in the experiments, opting instead for a direct traversal approach. Furthermore, during the traversal, we simultaneously selected positions i and i+w to reduce the size of the angle set θ and decrease the number of traversals. We used a fixed θ = {0°, 45°, 90°, 135°}, and β... max =10 6 The iteration step size (at this point) is K = 2, the initial value of β is K·λ, the initial t = 0.5, and λ, W2, and t min The values were optimized based on each dataset. The results of the output binarized text images were compared and evaluated with algorithms proposed by Otsu, Su, Sauvola, Kligler, Howe, and others on various metrics. Performance metrics used for evaluation included F-Measure (FM), pseudo F-Measure (pFM), peak signal-to-noise ratio (PSNR), and distance-reciprocal distortion (DRD). F-Measure is a combined metric of recall and precision; a higher F-Measure indicates that the binary image is closer to the ideal image (Ground Truth (GT)). Similarly, a higher pseudo F-Measure is better. PSNR is an objective standard for evaluating images; a higher PSNR value indicates less distortion. DRD measures the visual distortion of binary document images; a lower value is better. Specifically, 10 images were randomly selected from the above datasets, and the FM values of the output binary images from each algorithm were compared. Table 1 shows the statistical comparison results.
[0120] Table 1 Comparison of FM value results
[0121]
[0122] As can be seen, the quality of binary images obtained by using clean background document images produced by the method of this invention as input is significantly improved. A selection of images from Table 1 are also used for visual comparison. Figure 5 The visual comparison results of the DIBCO 2011-HW1 image are shown. The text outlines in the original image are relatively clear; therefore, during the iteration process, most of the blurry background spots are removed. The results from the method of this invention show that most of the spots in the image are effectively removed while the text information is well preserved. Specifically, regarding… Figure 5In the method of this invention, we set W = 50, λ = 0.02, and t... 2 =0.003, and in Figure 6 The parameter settings are further discussed in the line graph. Figure 6 The line graph statistically analyzed the DIBCO 2011-HW1 image as a function of W and t. 2 The FM value changes accordingly, with λ fixed at 0.02. The blue, orange, and gray lines (from bottom to top) represent W=30, W=50, and W=70, respectively. t ranges from 0.001 to 0.009, increasing by 0.001 at each node. It can be seen that the larger W is, the higher the FM value. This is because the original image does not contain large areas of clearly defined color blocks, and the text itself has low grayscale values and obvious outlines. A smaller W will cause significant gradient changes in the image within a local area, resulting in an increase in spots in the binary image. Furthermore, at t... 2 =0.003 and t 2 At 0.007, the broken line shows a clear downward trend. During the algorithm's iteration process, higher t... 2 The value can cause the outline of the text to be excessively blurred. The method of the present invention can achieve good results for document images containing color blocks and stains that do not overlap with the text.
[0123] In addition, the H-DIBCO 2018 dataset collected a large number of similar datasets. Figure 7 The document image containing these defects in (a) shows, as can be seen from the FM values in Table 1 and the visual representation of the binary image, that the present invention can remove defects more effectively compared to other algorithms. Figure 7 The color blocks and book edge marks on the left side of (a) are closer to the GT image. Table 2 shows the average performance of each algorithm on various indicators in the H-DIBCO2018 dataset. The method of this invention performs well in dealing with images with large areas of color blocks, such as H-DIBCO 2018, and the average values of each indicator are better than the comparison algorithms.
[0124] Table 2. Average values of the H-DIBCO 2018 dataset
[0125] algorithm FM pFM PSNR DRD Otsu 51.45% 53.04% 9.74 59.06 Su 82.21% 85.86% 16.59 8.27 Sauvola 57.62% 65.88% 13.85 13.58 Howe 77.22% 79.41% 15.71 13.74 Kligler 68.23% 69.71% 15.58 18.68 Method of the present invention 83.10 89.74 17.02 6.17
[0126] This invention also provides a device for determining a binarized text image, comprising:
[0127] The acquisition module is used to acquire text images and perform grayscale processing on the text images to obtain grayscale images;
[0128] The detection module is used to detect the gradient information of the text outline in the grayscale image;
[0129] The determination module is used to determine the contour gradient information matrix based on the text contour gradient information and the gradient threshold.
[0130] The first processing module is used to perform alternating minimization processing based on the contour gradient information matrix and the grayscale image to obtain the target text image; the alternating minimization processing is used to reduce the difference between the grayscale values inside and outside the text.
[0131] The second processing module is used to binarize the target text image to obtain a binarized text image.
[0132] The content of the above method embodiments is applicable to the device embodiments. The specific functions implemented by the device embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.
[0133] This invention also provides an electronic device, which includes a processor and a memory. The memory stores at least one instruction, at least one program, a code set, or an instruction set. The processor loads and executes the at least one instruction, at least one program, a code set, or an instruction set to implement the binarized text image determination method of the aforementioned embodiments. The electronic device of this invention includes, but is not limited to, any smart terminal such as a mobile phone, tablet computer, computer, and in-vehicle computer.
[0134] The content of the above method embodiments is applicable to this device embodiment. The specific functions implemented in this device embodiment are the same as those in the above method embodiments, and the beneficial effects achieved are also the same as those achieved in the above method embodiments.
[0135] This invention also provides a computer-readable storage medium storing at least one instruction, at least one program, code set, or instruction set, wherein the at least one instruction, at least one program, code set, or instruction set is loaded and executed by a processor to implement the binarized text image determination method of the foregoing embodiments.
[0136] This invention also provides a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the binarized text image determination method of the aforementioned embodiments.
[0137] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0138] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0139] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the shown or discussed mutual couplings, direct couplings, or communication connections may be through some interfaces; indirect couplings or communication connections between devices or units may be electrical, mechanical, or other forms. Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, i.e., they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs. Additionally, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The integrated units described above can be implemented in hardware or as software functional units.
[0140] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0141] The above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit it. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.
Claims
1. A method of determining a binaryzation of a text image, characterized in that, The method comprises the following steps: acquiring a character image and performing gray processing on the character image to obtain a gray image; detecting character contour gradient information of the gray image; determining a contour gradient information matrix according to the character contour gradient information and a gradient threshold value; performing alternating minimization processing on the contour gradient information matrix and the gray image to obtain a target character image; the alternating minimization processing is used to reduce the difference between the gray values inside and outside the character; performing binary processing on the target character image to obtain a binary character image; the step of detecting the character contour gradient information of the gray image comprises the following steps: determining a detection point from the character in the gray image; detecting along each width direction of the character from the detection point as a starting point and according to a rotation angle to obtain the character contour gradient information; the character contour gradient information comprises a one-dimensional contour corresponding to each width direction; the step of determining the contour gradient information matrix according to the character contour gradient information and the gradient threshold value comprises the following steps: determining a pixel group in the one-dimensional contour corresponding to the same width direction; the pixel group comprises a first pixel and a second pixel, and the first pixel is adjacent to the second pixel; when the difference between the first pixel and the second pixel of the pixel group is greater than the gradient threshold value or when the difference between the first pixel and the second pixel of the pixel group is less than the negative gradient threshold value, the first pixel is used to form the contour gradient information matrix; the step of performing alternating minimization processing on the contour gradient information matrix and the gray image to obtain a target character image comprises the following steps: performing Fourier transform processing on the adaptive parameter, a unit vector of the rotation angle with the detection point as a starting point, the gray image and the contour gradient information matrix to obtain a smooth image; updating the adaptive parameter, the gradient threshold value and the smooth image according to a target function until a preset ending condition is reached to obtain the target character image; the step of updating the adaptive parameter, the gradient threshold value and the smooth image according to the target function until the preset ending condition is reached to obtain the target character image comprises the following steps: updating the gradient threshold value and the adaptive parameter according to the minimum value of the target function; the target function is determined according to the sum of a first factor and a second factor; the first factor is the product of the square of a first difference and the adaptive parameter, and the first difference is the difference between the differential gradient of adjacent pixels in the same width direction and the contour gradient information matrix; the second factor is the difference between the smooth image and the gray image; the adaptive parameter is used to adjust the similarity between the differential gradient and the corresponding element in the contour gradient information matrix; taking the smooth image as a new gray image, returning to the step of detecting the character contour gradient information of the gray image until a new smooth image is obtained and the gradient threshold value and the adaptive parameter are updated for one iteration of update; repeating the update iteration until the preset ending condition is reached, and taking the smooth image of the last iteration of update as the target character image.
2. The method of claim 1, wherein: the step of performing gray processing on the character image to obtain a gray image comprises the following steps: calculating a first product of a preset first weighting factor and a first channel value of the character image; calculating a second product of a preset second weighting factor and a second channel value of the character image; calculating a third product of a preset third weighting factor and a third channel value of the character image; obtaining the gray image according to a sum of the first product, the second product and the third product.
3. The method of claim 1 or 2, wherein the method further comprises: determining a binary image of the text image. The binarization processing of the target character image comprises: The binarization processing of the target character image comprises:
4. An apparatus for determining binarization of a text image, characterized by comprises: The acquisition module is configured to acquire a character image and perform gray processing on the character image to obtain a gray image. The detection module is configured to detect character contour gradient information of the gray image. The determination module is configured to determine a contour gradient information matrix according to the character contour gradient information and a gradient threshold. The first processing module is configured to perform alternating minimization processing on the contour gradient information matrix and the gray image to obtain a target character image. The second processing module is configured to perform binarization processing on the target character image to obtain a binarized character image. The detection of the character contour gradient information of the gray image comprises: determining a detection point from the character in the gray image; detecting along each width direction of the character from the detection point as a starting point and according to a rotation angle to obtain the character contour gradient information. The character contour gradient information comprises a one-dimensional contour corresponding to each width direction. In the one-dimensional contour corresponding to the same width direction, a pixel group is determined; the pixel group comprises a first pixel and a second pixel, and the first pixel is adjacent to the second pixel. When a difference between the first pixel and the second pixel of the pixel group is greater than the gradient threshold, or when the difference between the first pixel and the second pixel of the pixel group is less than the negative gradient threshold, the first pixel is used to form the contour gradient information matrix. The alternating minimization processing on the contour gradient information matrix and the gray image to obtain a target character image comprises: performing Fourier transform processing on the adaptive parameter, a unit vector of the rotation angle with the detection point as a starting point, the gray image and the contour gradient information matrix to obtain a smoothed image; updating the adaptive parameter, the gradient threshold and the smoothed image according to a target function until a preset ending condition is reached to obtain the target character image. The updating of the adaptive parameter, the gradient threshold and the smoothed image according to the target function until the preset ending condition is reached to obtain the target character image comprises: updating the gradient threshold and the adaptive parameter according to a minimum value of the target function; the target function is determined according to a sum of a first factor and a second factor; the first factor is a product of a square of a first difference and the adaptive parameter, the first difference is a difference between a differential gradient of adjacent pixels in a same width direction and the contour gradient information matrix; the second factor is a difference between the smoothed image and the gray image; the adaptive parameter is used to adjust a similarity between the differential gradient and a corresponding element in the contour gradient information matrix; returning to the step of detecting the contour gradient information of the text of the gray image with the smoothed image as a new gray image until a new smoothed image is obtained and the gradient threshold and the adaptive parameter are updated for one updating iteration; repeating the updating iteration until a preset ending condition is reached, and taking the smoothed image of the last updating iteration as the target text image.
5. An electronic device, comprising: The electronic device includes a processor and a memory, and the memory stores at least one instruction, at least one program, a code set or an instruction set, which is loaded and executed by the processor to implement the method of any one of claims 1-3.
6. A computer-readable storage medium, characterized in that, The storage medium stores at least one instruction, at least one program, a code set or an instruction set, which is loaded and executed by the processor to implement the method of any one of claims 1-3.
Citation Information
Patent Citations
Character image processing method and device
CN107609558A
Character segmentation method and apparatus, and computer-readable storage medium
WO2021109697A1