Method and system for removing multiple types of lines from document images
Through the improved pixel path relationship algorithm, combined with image preprocessing and line position judgment, the problem of inability to accurately detect multiple lines in the prior art is solved, and a fast and efficient line elimination effect is achieved.
Patent Information
- Application Number
- CN202211019357.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-24
- Publication Date
- 2025-08-15
- Estimated Expiration
- 2042-08-24
AI Technical Summary
The existing document image line detection methods cannot accurately detect non-connected long lines such as dotted lines, short solid lines, and text-surrounded lines, and have large calculations and slow processing speed.
The steps of image preprocessing, row pixel path extraction, preliminary line recognition, traversing all pixel rows, updating the threshold value of solid line length, accurate judgment of line position and vertical line elimination are adopted, combined with the improvement of pixel path relationship, the projection method is used to judge the line position through the length and spacing rules of pixel paths and eliminate it.
It realizes accurate detection of non-connected long lines such as dotted lines and short solid lines and text-surrounded lines. The calculation amount is small, the processing speed is fast, and the memory and time consumption is close to that of traditional projection methods.
Smart Images

Figure CN115393857B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of document image processing, and in particular relates to a method and system for removing multiple types of lines from document images. Background Art
[0002] In document images, there will be horizontal or vertical straight lines (hereinafter referred to as lines), such as table borders, column lines, underlines, and dashed boxes. It can be applied to scenarios where background lines need to be removed to improve the accuracy of document image content recognition. For example, when using OCR technology to recognize text in document images, the lines in the image will seriously reduce the accuracy of text recognition. Therefore, it is necessary to eliminate various types of line noise data in the image processing stage. Existing line detection mainly uses the Hough transform algorithm and the threshold projection method. However, the threshold projection method cannot accurately detect the position of non-connected long lines such as dotted lines, short solid lines, and text-surrounding lines; and the Hough transform algorithm has a large amount of calculation and a slow processing speed when performing line detection.
[0003] Therefore, it is very important to design a multi-type line removal method and system for document images that can accurately detect the position of non-connected long lines such as dotted lines, short solid lines, and text-wrapped lines, with low computational complexity and fast processing speed.
[0004] For example, the Chinese patent document with application number CN201810905440.X describes a method for removing interference lines in document images based on a greedy algorithm, which includes the following steps: a. binarizing the document image; b. thinning the lines of text and interference lines to obtain single-pixel lines; c. interference line detection: scanning the document image in a single horizontal direction, identifying the center line in the scanning direction, assigning a higher weight to the center line with a longer length, and if the calculated center line weight exceeds a set threshold, it is considered an interference line; for vertical interference lines, the image or template is rotated to transform it into a horizontal direction and then identified using the same method; the process of detecting horizontal and vertical interference lines also includes detecting oblique interference lines; d. interference line removal: determining the foreground pixel's location by the distance between it and the interference line, removing the pixels belonging to the interference line, and obtaining the processed document image. Although it can remove more complex interference lines in document images with high processing accuracy and fast processing speed, its disadvantage is that it cannot accurately detect the position of non-connected long lines such as dotted lines, short solid lines, and text wrapping lines. Summary of the Invention
[0005] The present invention aims to overcome the problems in the prior art of existing document image line detection methods, which are unable to accurately detect the positions of non-connected long lines such as dot-dashed lines and short solid lines, and text-surrounding lines, and have a large amount of calculation and slow processing speed. The present invention provides a method and system for eliminating multiple types of lines for document images, which can accurately detect the positions of non-connected long lines such as dot-dashed lines and short solid lines, and text-surrounding lines, and has a small amount of calculation and fast processing speed.
[0006] In order to achieve the above-mentioned object of the invention, the present invention adopts the following technical solutions:
[0007] The method for removing multiple types of lines from a document image comprises the following steps:
[0008] S1, image preprocessing:
[0009] Input the document image to be processed, and output a binary image through image preprocessing;
[0010] S2, row pixel path extraction:
[0011] Input binary image and pixel row, output pixel path set S corresponding to pixel row j ;
[0012] S3, preliminary line recognition:
[0013] Input pixel path set S j , based on the custom line feature parameters and the preset horizontal solid line judgment threshold, determine whether there is a line in the pixel row;
[0014] S4, traverse all pixel rows:
[0015] Repeat steps S2 to S3 until all pixel rows are traversed, and output the pixel path set S of all pixel rows;
[0016] S5, solid line length threshold update:
[0017] Input the pixel path set S and take the upper quartile of the box plot of the pixel path length array as the new threshold;
[0018] S6, accurate judgment of line position:
[0019] Input the pixel path set S, and obtain the horizontal line position set based on the customized line feature parameters and the updated horizontal solid line judgment threshold;
[0020] S7, line removal:
[0021] Fill the horizontal line position with background color to obtain an image without horizontal lines;
[0022] S8, vertical line removal:
[0023] The image without horizontal lines is rotated 90° clockwise, and steps S2 to S7 are repeated, followed by a 90° counterclockwise rotation to obtain a final image without horizontal lines.
[0024] Preferably, step S1 includes the following steps:
[0025] S11, input the document image to be processed In, after grayscale transformation, binarization, perspective transformation processing, output binary image Ib, pixel row r j ,j∈{1,…,n},r j = <v j,1 , v j,2 ,…,v j,m >, pixel column c i , i∈{1,…,m},c i = <v 1,i , v 2,i ,…,v n,i >, where v i,j express<i,j> The pixel value at .
[0026] Preferably, step S2 includes the following steps:
[0027] S21, traverse r j , when encountering the first non-background pixel p<j,start> When , the connectivity and path between the first non-background pixel and the subsequent pixels are calculated until the first disconnected pixel is encountered, and the path between the first non-background pixel and the subsequent pixels is obtained according to the greedy algorithm.<j,start> The pixel position p with the longest path<j,end> , and finally get a pixel channel PA<start,L> , where start represents the starting position of the pixel path and L represents the length of the pixel path;
[0028] S22, from pixel position p<j,end> Traverse backward and encounter the first non-background pixel p<j,start2> Repeat the above step S21 to obtain a pixel path PA<start2,L2> ;
[0029] S23, repeat the above step S22 until all pixel rows r are traversed. j , get the pixel path set S of row j j .
[0030] Preferably, step S3 includes the following steps:
[0031] Input pixel path set S of row j j , output row judgment result j , res>, where res is 0, 1, 2, and 3 respectively, indicating that the corresponding row has no lines, a solid line, a thin dotted line, or a dotted line. The specific process is as follows:
[0032] S31, solid line judgment:
[0033] S311, according to the pixel path set S of the jth row j , get the pixel path length difference array T j , where T j The values are all absolute values;
[0034] S312, if there is a pixel path PA in the jth row i If the length is greater than the first preset value Th1, then go to the next step, otherwise output j ,0>; wherein the first preset value is the initial value of the solid line length threshold, Th1=(image width)*0.02;
[0035] S313, if the pixel path PA i or next channel PA i+1 The length difference is greater than T j If the pixel path is the upper quartile of the row or the pixel path is the first pixel path of the row, it is preliminarily judged that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise go to the next step;
[0036] S314, if the pixel path PA i The length difference is less than T j The upper quartile of the pixel path PA is taken i-1 ; If the pixel path PA i-1 If the length is greater than the first preset value Th1, it is preliminarily determined that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise the output j ,0>;
[0037] S32, thin dotted line judgment:
[0038] If there are Th2 consecutive pixel paths in the jth row, the pixel paths have the same length and the spacing between adjacent paths is the same, then it is preliminarily determined that there is a thin dotted line in the jth row, and the judgment result is output. j , 2>, otherwise the output j ,0>; Th2 is the second preset value, indicating the number of continuous paths, Th2=3;
[0039] S33, dotted line judgment:
[0040] If there are Th3 continuous closed pixel paths in the jth row, and the spacing between adjacent paths is the same, it is preliminarily determined that there is a dotted line in the jth row, and the judgment result is output. j ,3>, otherwise the output j ,0>;Th3 is the third preset value, indicating the number of consecutive closed paths, Th3=5.
[0041] Preferably, step S5 includes the following steps:
[0042] S51, according to the pixel path set S, obtain the length array LT of all pixel paths;
[0043] S52 , taking the upper quartile of the array LT as the horizontal solid line judgment threshold K.
[0044] Preferably, step S6 includes the following steps:
[0045] Input pixel path set S, output horizontal line position set R1{<j,begin,finish> ,...}, where j represents the pixel row where the line is located; begin and finish represent the starting position of the line; the specific process method is as follows:
[0046] S61, based on the pixel path set S, obtain a preliminary judgment of the pixel path set Q1 containing solid lines, the pixel path set Q2 containing thin dashed lines, and the pixel path set Q3 containing dotted lines; Q i =< j ,i>,…>;
[0047] S62, solid line pixel path judgment:
[0048] S621, traverse the pixel path set Q1 to obtain the pixel path set S of a row j .
[0049] S622, according to the pixel path set S of a row j , get the pixel path length difference array T j , where T j The values are all absolute values;
[0050] S623, traverse the pixel path set S j , when encountering pixel path PAm<start,L> If the pixel path length is greater than the threshold K, then proceed to the next step, otherwise continue to traverse S j ;
[0051] S624, if the length difference of the pixel path PAm or the next pixel path PAm+1 is greater than T j If the pixel path is the first pixel path in the row, the pixel path<j,start,start+L> Add to the line position set R1 and return to step S623, otherwise go to the next step;
[0052] S625, if the length difference of the pixel path PAm is less than T j The upper quartile of the pixel path PAm-1 is taken. If the length of the pixel path PAm-1 is greater than the threshold K, the pixel path<j,start,start+L> Add to the line position set R1 and return to step S623; where j represents the pixel row where the line is located; start, start+L represent the starting position of the line;
[0053] S626, repeat steps S622 to S625 until Q1 is traversed;
[0054] S63, thin dotted line pixel path judgment:
[0055] S631, traverse Q2 and obtain the pixel path set S of a row j =<PA1,PA2,…> .
[0056] S632, according to the pixel path set S of a row j , get the pixel path length difference array T j , where T j The values are all absolute values;
[0057] S633, according to T j , get the n pixel path set temp= whose length difference value is 0 and is continuous<PAk,PAk+1,PAk+2,…,PAk+n> , wherein n>Th2, Th2 is a second preset value;
[0058] S634, based on the pixel path set temp, obtain a continuous pixel path set line with m adjacent paths having equal spacing between them =<PAb,PAb+1,PAb+2,…,PAb+m> , set Th2 <m≤n,PAb=<start1,L1> ,PAb+m=<startm,Lm> , the pixel path<j,start,startm+Lm> Add to the line position set R1;
[0059] S635, repeat S632 to S634 until Q2 is traversed;
[0060] S64, dot-dashed line pixel path judgment:
[0061] S641, traverse Q3 and obtain the pixel path set S of a row j =<PA1,PA2,…> ;
[0062] S642, according to S j , get the continuous n closed pixel path set temp=<PAk,PAk+1,PAk+2,…,PAk+n> , wherein n>Th3, Th3 is a third preset value;
[0063] S643, based on the pixel path set temp, obtain a continuous pixel path set line with m adjacent paths having equal spacings.<PAb,PAb+1,PAb+2,…,PAb+m> , set Th3 <m≤n,PAb=<start1,L1> ,PAb+m=<startm,Lm> , the pixel path<j,start1,startm+Lm> Add to the line position set R1;
[0064] S644, repeat steps S642 and S643 until Q3 is traversed.
[0065] Preferably, step S7 includes the following steps:
[0066] Input the image Ib after image preprocessing, the line position set R1, and output the image Ih without horizontal lines. The specific process is as follows:
[0067] S71, use K-means clustering on image Ib to separate the background color;
[0068] S72 , filling the positions of the lines with background color according to the line position set R1 to eliminate the lines and obtain an image without horizontal lines Ih.
[0069] Preferably, step S8 includes the following steps:
[0070] S81, rotate the image Ih 90° clockwise;
[0071] S82, repeating steps S2 to S7 to eliminate the original vertical lines to obtain image Iv;
[0072] S83, rotating the image Iv 90° counterclockwise to obtain a final lineless image I.
[0073] The present invention also provides a multi-type line removal system for document images, comprising:
[0074] Image preprocessing module, used to process the input document image to obtain a non-skewed, clear binary image;
[0075] The pixel path extraction module is used to process the pixels of the entire image and obtain the pixel path set of the entire image;
[0076] Line feature parameter module, used to determine whether a pixel path is a line, the user can customize the parameters;
[0077] The line detection module is used to process the pixel path set of the entire image and obtain the line position set based on the line feature parameters and judgment threshold;
[0078] The line remover is used to perform pixel flipping according to the line position set, eliminate the lines, and obtain a lineless document image.
[0079] Preferably, the pixel path extraction module includes:
[0080] The row pixel path counter is used to process a single row of pixels and obtain a single row of pixel path sets.
[0081] Compared with the prior art, the present invention has the following advantages: (1) the present invention designs a path algorithm, introduces the path relationship between pixels to improve the underlying algorithm of the projection method, uses pixel paths to represent continuous non-background pixel points, and can accurately detect the position of non-connected long lines such as dotted lines and short solid lines, as well as text-surrounding lines, with small computational complexity, and memory and time consumption similar to those of the projection method; (2) the present invention can increase the number of detectable line types as the line feature parameters increase, and users can customize the line feature parameters according to actual application scenarios to achieve line elimination. BRIEF DESCRIPTION OF THE DRAWINGS
[0082] Figure 1 A flow chart of a method for removing multiple types of lines from a document image provided by an embodiment of the present invention;
[0083] Figure 2 A principle block diagram of a multi-type line removal system for document images provided by an embodiment of the present invention;
[0084] Figure 3 A schematic diagram of the architecture of an image preprocessing module provided by an embodiment of the present invention;
[0085] Figure 4 A schematic diagram of the architecture of a pixel path extraction module provided by an embodiment of the present invention;
[0086] Figure 5 A schematic diagram of the architecture of a row pixel channel counter provided by an embodiment of the present invention;
[0087] Figure 6 A schematic diagram of the architecture of a line detection module provided by an embodiment of the present invention;
[0088] Figure 7 A schematic diagram of the actual application process of the multi-type line removal method for document images provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0089] To more clearly illustrate the embodiments of the present invention, specific embodiments of the present invention will be described below with reference to the accompanying drawings. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings and other embodiments can be obtained based on these drawings without inventive efforts.
[0090] Example:
[0091] like Figure 1 and Figure 7 As shown, the present invention provides a multi-type line removal method for document images. In an embodiment of the present invention, in order to more quickly and effectively remove various types of lines in document images, such as long solid lines, thin dotted lines, dotted lines, etc., a path algorithm is designed to introduce the path relationship between pixels to improve the underlying algorithm of the projection method. The result obtained by calculating a row of pixels is no longer a numerical value, but a group of arrays that can directly represent all continuous non-background pixels in a row of pixels, namely pixel paths. Then, the length and spacing rules of the pixel paths are used to determine whether it is a line, so as to eliminate it. The method specifically includes the following steps:
[0092] Step (1), image preprocessing. Figure 3 , input the document image to be processed In, after grayscale transformation, binarization, perspective transformation processing, output binary image Ib, pixel row r j ,j∈{1,…,n},r j = <v j,1 , v j,2 ,…,v j,m >, pixel column c i , i∈{1,…,m},c i = <v 1,i , v 2,i ,…,v n,i >, where v i,j express<i,j> The pixel value at .
[0093] Step (2), row pixel path extraction. Input binary image Ib, pixel row r j , output the pixel path set S of the jth row j . Reference Figure 5 Specific methods include:
[0094] Step (2.1), traverse r j, when encountering the first non-background pixel p<j,start> When , calculate its connectivity and path with subsequent pixels until it encounters the first disconnected pixel and stops. According to the greedy algorithm, the pixel p is obtained.<j,start> The pixel position p with the longest path<j,end> , thus obtaining a pixel path PA<start,L> , where start represents the starting position of the pixel path and L represents the length of the pixel path.
[0095] Step (2.2), then from pixel p<j,end> Traverse backward and encounter the first non-background pixel p<j,start2> Repeat the above steps (2.1) to obtain a pixel channel PA<start2,L2> .
[0096] Step (2.3), repeat the above step (2.2) until all pixel rows r are traversed. j , get the pixel path set S of row j j .
[0097] For example, the input pixel row r1 <0, 0, 0, 255, 255, 255, 0, 0, 255, 255, 255, 255, 0, ...>.
[0098] The pixel path set S1 {[4,3], [9,4], ...} of the changed row is obtained by the above method.
[0099] Step (3): Initial line recognition. Input the pixel path set S of the jth row j , output row judgment result j ,res>, this part can identify various types of lines based on the self-defined line feature parameters. Currently, three line types are preset. Among them, res is 0, 1, 2, and 3, which respectively represent the existence of no line, solid line, thin dotted line, and slightly dotted line. Specific methods include:
[0100] Step (3.1), solid line judgment, the specific method is as follows:
[0101] Step (3.1.1), according to the pixel path set S of the jth row j , get the pixel path length difference array T j (take the absolute value).
[0102] Step (3.1.2), if there is a pixel path PA in row j i If the length is greater than the first preset value Th1, go to the next step, otherwise output j , 0>. The first preset value is the initial value of the solid line length threshold, Th1 = input image width W*α, α = 0.02.
[0103] Step (3.1.3), if the path or the next path PA i+1 The length difference at is greater than T j If the pixel path is the upper quartile of the row or the pixel path is the first pixel path of the row, it is preliminarily judged that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise go to the next step.
[0104] Step (3.1.4), if the length difference value of the path is less than T j The upper quartile of the pathway PA i-1 , if the pixel path PA i-1 If the length is greater than the first preset value (two solid lines are adjacent), it is preliminarily determined that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise the output j ,0>.
[0105] The length difference value of each row of pixel paths can be:
[0106]
[0107] where DiffP i Represents the length difference value of the i-th pixel path, L i Represents the path length of the i-th pixel path.
[0108] The upper quartile calculation formula for the difference group is:
[0109] QT i =i*(n+1) / 4
[0110]
[0111] Among them QT i Indicates the observation value of the i-th quantile, n represents the number of elements in the difference array, Q i represents the i-th quantile, Indicates rounding down. Indicates rounding up, ti represents the i-th number in the difference array Tj.
[0112] For example, suppose the width of the input document image is W = 1000, H = 20;
[0113] Input pixel path set S2 {[5,6],[15,21],[40,3],[48,2],[55,5]};
[0114] T2=[0,15,18,1,3];
[0115] After sorting [0,1,3,15,18];
[0116] QT3 = 3*(5+1) / 4 = 4.5, so the quartile is between the fourth and fifth digits;
[0117] Q3=15+(18-15)*0.25=15.75;
[0118] The pixel path [15,21] has a length of 21, which is greater than H, and the subsequent length difference value 18 is greater than Q3. Therefore, it is preliminarily determined that there is a solid line in S2, and the output is<S2,1> .
[0119] Step (3.2), thin dotted line judgment, the specific method is as follows:
[0120] If there are Th2 continuous pixel paths in the jth row, with the same length and the same spacing between adjacent paths, it is preliminarily determined that there is a thin dotted line in the jth row, and the judgment result is output. j , 2>, otherwise the output j , 0>. Th2 is a second preset value, Th2=3.
[0121] Step (3.3), dotted line judgment, the specific method is as follows:
[0122] If there are Th3 continuous closed pixel paths in the jth row, and the spacing between adjacent paths is the same, it is preliminarily determined that there is a dotted line in the jth row, and the judgment result is output. j ,3>, otherwise the output j , 0>. Th3 is a third preset value, Th3=5.
[0123] Step (4): repeat the above steps (2) to (3) until all pixel rows are traversed and the pixel path set S is output, S = <<S1,res1> ,<S2,res2> ,…, n ,res n >>.
[0124] Step (5): Update the solid line length threshold. Input the pixel path set S and output the horizontal solid line judgment threshold K. The specific method includes:
[0125] (5.1), according to the pixel path set S, the length array LT of all pixel paths is obtained.
[0126] (5.2), the upper quartile of the array LT is taken as the horizontal solid line judgment threshold K.
[0127] Step (6): Accurately determine the line position. Input pixel path set S, output horizontal line position set R1{<j,begin,finish> ,...}, where j represents the pixel row where the line is located, begin and finish represent the starting position of the line. Different types of lines can be identified based on different line feature parameters. Currently, three line types are preset. Specific methods include:
[0128] Step (6.1): Based on the pixel path set S, obtain the pixel path set Q1 containing solid lines, the pixel path set Q2 containing thin dashed lines, and the pixel path set Q3 containing dotted lines. i =< j , i>,…>.
[0129] Step (6.2), solid line pixel path determination. The specific method is as follows:
[0130] Step (6.2.1), traverse Q1 and obtain the pixel path set S of a row j .
[0131] Step (6.2.2), according to the pixel path set S of a row j , get the pixel path length difference array T j (All values are absolute values).
[0132] Step (6.2.3), traverse S j , when encountering pixel path PA m <start,L> If the path length is greater than the threshold K, proceed to the next step, otherwise continue to traverse S j .
[0133] Step (6.2.4), if the path or the next path PA m+1 The length difference is greater than T j If the pixel path is the first pixel path in the row, the pixel path<j,start,start+L> Add it to the line position set R1 and return to step (6.2.3). Otherwise, proceed to the next step.
[0134] Step (6.2.5), if the length difference value of the path is less than T j The upper quartile of the previous path PA m-1 , if the pixel path PA m-1 The length is greater than the threshold K (two solid lines are adjacent), and the pixel path<j,start,start+L> Add it to the line position set R1 and return to step (6.2.3). Where j represents the pixel row where the line is located, start, start+L represent the starting position of the line.
[0135] Step (6.2.6), repeat steps (6.2.2) - step (6.2.5) until Q1 is traversed completely.
[0136] Step (6.3), determine the pixel path of the thin dotted line. The specific method is as follows:
[0137] Step (6.3.1), traverse Q2 to obtain the pixel path set S of one row j =<PA1, PA2, …>.
[0138] Step (6.3.2), according to the pixel path set S of one row j , obtain the pixel path length difference array T j (the values are all taken as absolute values).
[0139] Step (6.3.3), according to T j , obtain the set temp of n (n > Th2) consecutive pixel paths with a length difference value of 0, temp = <PA k , PA k+1 , PA k+2 , …, PA k+n , >, where Th2 is the second preset value.
[0140] Step (6.3.4), according to the pixel path set temp, obtain the set line of m (Th2 < m ≤ n) consecutive pixel paths with equal spacing between adjacent paths, line = <PA b , PA b+1 , PA b+2 , …, PA b+m >. (Assume PA b = <start1, L1>, PA b+m = <startm, Lm>), add the pixel path <j, start, startm + Lm> to the line position set R1.
[0141] Step (6.3.5), repeat steps (6.3.2) - step (6.3.4) until Q2 is traversed completely.
[0142] For example, assume the input pixel path set S3 {[5, 6], [12, 6], [19, 6], [26, 6], [33, 5]}
[0143] T3 = [0, 0, 0, 0, 1]
[0144] The pixel paths [5, 6], [12, 6], [19, 6], [26, 6] have equal lengths, and the spacing between the paths is 1. Therefore, these four pixel paths form a thin dotted line, and [3, 5, 32] is added to the line position set R1.
[0145] Step (6.4), dotted pixel path judgment. The specific method is as follows:
[0146] Step (6.4.1): Traverse Q3 to obtain the pixel path set S of a row j =<PA1, PA2,...>.
[0147] Step (6.4.2): According to S j , obtain the continuous n (n > Th3) closed pixel path sets temp = <PA k , PA k+1 , PA k+2 , …, PA k+n , >, where Th3 is the third preset value.
[0148] Step (6.4.3), according to the pixel path set temp, obtain the continuous pixel path set line = <PA b , PA b+1 , PA b+2 , …, PA b+m > where the distances between m (Th3 < m ≤ n) adjacent paths are equal. (Assume PA b =<start1, L1>, PA b+m =<startm, Lm>), and add the pixel path <j, start1, startm + Lm> to the line position set R1.
[0149] Step (6.4.4), repeat the operations of Step (6.4.2) and Step (6.4.3) until Q3 is traversed.
[0150] Step (7): Line elimination. Input the preprocessed image Ib of the input image and the line position set R1, and output the image Ih without horizontal lines. The specific method includes:
[0151] Step (7.1): Use K-means clustering to separate the background color.
[0152] Step (7.2): According to the line position set R1, fill the background color at the positions of the lines, so as to eliminate the lines and obtain the image Ih without horizontal lines.
[0153] Step (8), vertical line elimination. Input the image Ih without horizontal lines and output the final image I without lines. Just rotate the image Ih clockwise by 90°, at this time the vertical lines in the original image become horizontal lines relative to the image, and then repeat Steps (2) - Step (7) to eliminate the vertical lines. The specific method includes:
[0154] Step (8.1), rotate the image Ih clockwise by 90°.
[0155] Step (8.2), repeat steps (2) to (7), eliminate the original vertical image, and obtain image Iv.
[0156] In step (8.3), the image Iv is rotated 90° counterclockwise to obtain the final lineless image I.
[0157] like Figure 2 As shown, the present invention also provides a multi-type line removal system for document images, comprising:
[0158] Image preprocessing modules, such as Figure 3 As shown, it is used to process the input document image to obtain a non-skewed, clear binary image;
[0159] Pixel channel extraction module, such as Figure 4 As shown, it is used to process the pixels of the entire image and obtain the pixel path set of the entire image;
[0160] Line feature parameter module, used to determine whether a pixel path is a line, the user can customize the parameters;
[0161] Line detection module, such as Figure 6 As shown, it is used to process the pixel path set of the entire image and obtain the line position set based on the line feature parameters and the judgment threshold;
[0162] The line remover is used to perform pixel flipping according to the line position set, eliminate the lines, and obtain a lineless document image.
[0163] The pixel path extraction module includes:
[0164] Row pixel channel counter, such as Figure 5 As shown, it is used to process a single row of pixels and obtain a single row of pixel path sets.
[0165] The present invention designs a path algorithm, introduces the path relationship between pixels to improve the underlying algorithm of the projection method, uses pixel paths to represent continuous non-background pixel points, and can accurately detect the positions of non-connected long lines such as dotted lines and short solid lines, as well as text-surrounding lines. The calculation amount is small, and the memory and time consumption are similar to those of the projection method. The present invention can increase the number of detectable line types as the line feature parameters increase. Users can customize the line feature parameters according to actual application scenarios to achieve line elimination.
[0166] The above description is only a detailed description of the preferred embodiments and principles of the present invention. For ordinary technicians in this field, based on the ideas provided by the present invention, there may be changes in the specific implementation methods, and these changes should also be considered as the scope of protection of the present invention.
Claims
1. A multi-type line removal method for document images, characterized in that: The steps include: S1, image preprocessing: Input the document image to be processed, and output a binary image through image preprocessing; S2, row pixel path extraction: Input binary image and pixel row, output pixel path set S corresponding to pixel row j ; S3, preliminary line recognition: Input pixel path set S j , based on the custom line feature parameters and the preset horizontal solid line judgment threshold, determine whether there is a line in the pixel row; S4, traverse all pixel rows: Repeat steps S2 to S3 until all pixel rows are traversed, and output the pixel path set S of all pixel rows; S5, solid line length threshold update: Input the pixel path set S and take the upper quartile of the box plot of the pixel path length array as the new threshold; S6, accurate judgment of line position: Input the pixel path set S, and obtain the horizontal line position set based on the customized line feature parameters and the updated horizontal solid line judgment threshold; S7, line removal: Fill the horizontal line position with background color to obtain an image without horizontal lines; S8, vertical line removal: The image without horizontal lines is rotated 90° clockwise, and steps S2 to S7 are repeated, followed by a 90° counterclockwise rotation to obtain a final image without horizontal lines.
2. The method for removing multiple types of lines from a document image according to claim 1, wherein: Step S1 includes the following steps: S11, input the document image to be processed In, after grayscale transformation, binarization, perspective transformation processing, output binary image Ib, pixel row r j ,j∈{1,…,n},r j = <v j,1 , v j,2 ,…,v j,m >, pixel column c i , i∈{1,…,m},c i = <v 1,i , v 2,i ,…,v n,i >, where v i,j express<i,j> The pixel value at .
3. The method for removing multiple types of lines from a document image according to claim 2, wherein: Step S2 includes the following steps: S21, traverse r j , when encountering the first non-background pixel p<j,start> When , the connectivity and path between the first non-background pixel and the subsequent pixels are calculated until the first disconnected pixel is encountered, and the path between the first non-background pixel and the subsequent pixels is obtained according to the greedy algorithm.<j,start> The pixel position p with the longest path<j,end> , and finally get a pixel channel PA<start,L> , where start represents the starting position of the pixel path and L represents the length of the pixel path; S22, from pixel position p<j,end> Traverse backward and encounter the first non-background pixel p<j,start2> Repeat the above step S21 to obtain a pixel path PA<start2,L2> ; S23, repeat the above step S22 until all pixel rows r are traversed. j , get the pixel path set S of row j j .
4. The method for removing multiple types of lines from a document image according to claim 3, wherein: Step S3 includes the following steps: Input pixel path set S of row j j , output row judgment result j , res>, where res is 0, 1, 2, and 3 respectively, indicating that the corresponding row has no lines, a solid line, a thin dotted line, or a dotted line. The specific process is as follows: S31, solid line judgment: S311, according to the pixel path set S of the jth row j , get the pixel path length difference array T j , where T j The values are all absolute values; S312, if there is a pixel path PA in the jth row i If the length is greater than the first preset value Th1, then go to the next step, otherwise output j ,0>; wherein the first preset value is the initial value of the solid line length threshold, Th1=(image width)*0.02; S313, if the pixel path PA i or next channel PA i+1 The length difference is greater than T j If the upper quartile of the path is the first path in the row, it is preliminarily judged that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise go to the next step; S314, if the pixel path PA i The length difference is less than T j The upper quartile of the pixel path PA is taken i-1 ; If the pixel path PA i-1 If the length is greater than the first preset value Th1, it is preliminarily determined that there is a solid line in the jth row and the judgment result is output. j , 1>, otherwise the output j ,0>; S32, thin dotted line judgment: If there are Th2 consecutive pixel paths in the jth row, the pixel paths have the same length and the spacing between adjacent paths is the same, then it is preliminarily determined that there is a thin dotted line in the jth row, and the judgment result is output. j , 2>, otherwise the output j ,0>; Th2 is the second preset value, indicating the number of continuous paths, Th2=3; S33, dotted line judgment: If there are Th3 continuous closed pixel paths in the jth row, and the spacing between adjacent paths is the same, it is preliminarily determined that there is a dotted line in the jth row, and the judgment result is output. j ,3>, otherwise the output j ,0>;Th3 is the third preset value, indicating the number of consecutive closed paths, Th3=5. 5. The method for removing multiple types of lines from a document image according to claim 4, wherein: Step S5 includes the following steps: S51, according to the pixel path set S, obtain the length array LT of all pixel paths; S52 , taking the upper quartile of the array LT as the horizontal solid line judgment threshold K.
6. The method for removing multiple types of lines from a document image according to claim 5, wherein: Step S6 includes the following steps: Input pixel path set S, output horizontal line position set R1{<j,begin,finish> ,...}, where j represents the pixel row where the line is located; begin and finish represent the starting position of the line; the specific process method is as follows: S61, based on the pixel path set S, obtain a preliminary judgment of the pixel path set Q1 containing solid lines, the pixel path set Q2 containing thin dashed lines, and the pixel path set Q3 containing dotted lines; Q i =< j ,i>,…>; S62, solid line pixel path judgment: S621, traverse the pixel path set Q1 to obtain the pixel path set S of a row j; S622, according to the pixel path set S of a row j , get the pixel path length difference array T j , where T j The values are all absolute values; S623, traverse the pixel path set S j , when encountering pixel path PAm<start,L> If the pixel path length is greater than the threshold K, then proceed to the next step, otherwise continue to traverse S j ; S624, if the length difference of the pixel path PAm or the next pixel path PAm+1 is greater than T j If the pixel path is the first pixel path in the row, the pixel path<j,start,start+L> Add to the line position set R1 and return to step S623, otherwise go to the next step; S625, if the length difference of the pixel path PAm is less than T j The upper quartile of the pixel path PAm-1 is taken. If the length of the pixel path PAm-1 is greater than the threshold K, the pixel path<j,start,start+L> Add to the line position set R1 and return to step S623; where j represents the pixel row where the line is located; start, start+L represent the starting position of the line; S626, repeat steps S622 to S625 until Q1 is traversed; S63, thin dotted line pixel path judgment: S631, traverse Q2 and obtain the pixel path set S of a row j =<PA1,PA2,…> ; S632, according to the pixel path set S of a row j , get the pixel path length difference array T j , where T j The values are all absolute values; S633, according to T j , get the n pixel path set temp= whose length difference value is 0 and is continuous<PAk,PAk+1,PAk+2,…,PAk+n> , wherein n>Th2, Th2 is a second preset value; S634, based on the pixel path set temp, obtain a continuous pixel path set line with m adjacent paths having equal spacing between them =<PAb,PAb+1,PAb+2,…,PAb+m> , set Th2 <m≤n,PAb=<start1,L1> ,PAb+m=<startm,Lm> , the pixel path<j,start,startm+Lm> Add to the line position set R1; S635, repeat S632 to S634 until Q2 is traversed; S64, dot-dashed line pixel path judgment: S641, traverse Q3 and obtain the pixel path set S of a row j =<PA1,PA2,…> ; S642, according to S j , get the continuous n closed pixel path set temp=<PAk,PAk+1,PAk+2,…,PAk+n> , wherein n>Th3, Th3 is a third preset value; S643, based on the pixel path set temp, obtain a continuous pixel path set line with m adjacent paths having equal spacings.<PAb,PAb+1,PAb+2,…,PAb+m> , set Th3 <m≤n,PAb=<start1,L1> ,PAb+m=<startm,Lm> , the pixel path<j,start1,startm+Lm> Add to the line position set R1; S644, repeat steps S642 and S643 until Q3 is traversed.
7. The method for removing multiple types of lines from a document image according to claim 6, wherein: Step S7 includes the following steps: Input the image Ib after image preprocessing, the line position set R1, and output the image Ih without horizontal lines. The specific process is as follows: S71, use K-means clustering on image Ib to separate the background color; S72 , filling the positions of the lines with background color according to the line position set R1 to eliminate the lines and obtain an image without horizontal lines Ih.
8. The method for removing multiple types of lines from a document image according to claim 7, wherein: Step S8 includes the following steps: S81, rotate the image Ih 90° clockwise; S82, repeating steps S2 to S7 to eliminate the original vertical lines to obtain image Iv; S83, rotating the image Iv 90° counterclockwise to obtain a final lineless image I.
9. A system for removing multiple lines from document images, for implementing the method for removing multiple lines from document images according to any one of claims 1 to 8, characterized in that: The multi-type line removal system for document images comprises: Image preprocessing module, used to process the input document image to obtain a non-skewed, clear binary image; The pixel path extraction module is used to process the pixels of the entire image and obtain the pixel path set of the entire image; Line feature parameter module, used to determine whether a pixel path is a line, the user can customize the parameters; The line detection module is used to process the pixel path set of the entire image and obtain the line position set based on the line feature parameters and judgment threshold; The line remover is used to perform pixel flipping according to the line position set, eliminate the lines, and obtain a lineless document image.
10. The multi-type line removal system for document images according to claim 9, characterized in that: The pixel path extraction module includes: The row pixel path counter is used to process a single row of pixels and obtain a single row of pixel path sets.
Citation Information
Patent Citations
Greedy algorithm-based method for removing interference lines in document image
CN110807348A
Method for removing long interfering lines of text images
CN108805126A
Method and a system for substantially eliminating erroneously recognized non-solid lines
US6324302B1