CN115601757A - Scanning document image inclination correction method based on segmented projection - Google Patents
Scanning document image inclination correction method based on segmented projection Download PDFInfo
- Publication number
- CN115601757A CN115601757A CN202211289169.4A CN202211289169A CN115601757A CN 115601757 A CN115601757 A CN 115601757A CN 202211289169 A CN202211289169 A CN 202211289169A CN 115601757 A CN115601757 A CN 115601757A
- Authority
- CN
- China
- Prior art keywords
- image
- projection
- scanned document
- document image
- rotation angle
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06V—IMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
- G06V30/00—Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
- G06V30/10—Character recognition
- G06V30/14—Image acquisition
- G06V30/146—Aligning or centring of the image pick-up or image-field
- G06V30/1475—Inclination or skew detection or correction of characters or of image to be recognised
Landscapes
- Engineering & Computer Science (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Multimedia (AREA)
- Theoretical Computer Science (AREA)
- Character Input (AREA)
Abstract
The invention discloses a scanned document image inclination correction method based on segmented projection, which comprises the following steps: preprocessing a scanned document image; determining a writing direction of the scanned document image; extracting a skeleton of a scanned document image; calculating a first inclination angle by adopting a linear detection algorithm and a linear slope averaging method; calculating a second inclination angle by adopting a rotating projection method and a foreground point method in the statistical region; and rotationally correcting the scanned document image according to the first inclination angle and the second inclination angle. The method combines the characteristics of the document image, combines the skeleton extraction method, the linear detection method, the rotation projection method and the foreground point method in the statistical area to calculate the inclination angle of the image, can quickly obtain the inclination angle of the scanned document image and perform inclination correction, can perform inclination correction on the scanned document image with undefined boundary, and has high detection precision and reliability of the inclination angle.
Description
Technical Field
The invention relates to the technical field of document image deviation correction, in particular to a scanned document image inclination correction method based on segmented projection.
Background
The inclination angle detection of the document image is a very important link in the document image processing and is the basic work of image recognition and machine vision. The current inclination detection is usually performed by a projection method, which is divided into horizontal projection and vertical projection, wherein the horizontal projection refers to the summation operation of foreground pixel points of a two-dimensional image according to a row direction, the vertical projection refers to the summation operation of the foreground pixel points of the two-dimensional image according to a column direction, and finally, the inclination degree of the document image is judged by using a peak value of the document image after projection.
As a patent document entitled "a method and apparatus for detecting document image tilt" (publication number "CN 109784332A"), a projection method is used to detect the tilt angle by the signal energy of the image feature, and this method has a long calculation time of the tilt angle when the interval of the rotation angle is set too small. Also, for example, in a patent document entitled "a scanned document image rectification method" (publication number "CN 106097254B"), a projection method is also used to scan a histogram of a document image, calculate projection values of text lines in the horizontal direction and the vertical direction, construct an appropriate feature function, and use an angle corresponding to an extreme value of the feature function as an inclination angle of the scanned document image. The angle corresponding to the extreme value of the characteristic function is easy to cause misjudgment, and because the abscissa or the ordinate corresponding to each extreme value is different, the inclination angle judged based on the peak value is not necessarily correct, and meanwhile, the accuracy of inclination angle detection is low.
Disclosure of Invention
In order to solve the technical problems, the invention provides a scanning document image inclination correction method based on segmented projection, which can quickly realize the detection of the inclination angle of a document image, improve the detection precision of the inclination angle and improve the algorithm efficiency.
The invention adopts the following technical scheme: a method for correcting the tilt of a scanned document image based on segmented projection, the method comprising the steps of:
(1) Preprocessing a scanned document image; converting scanned document image I to grayscaleImage I g Then, an image binarization algorithm is adopted to carry out on the gray level image I g Carrying out image binarization operation to obtain a first binary image I b1 ;
(2) Determining a writing direction of the scanned document image; using a line detection algorithm to perform a first binary image I b1 Performing linear detection to obtain a first line segment set L, and judging the writing direction of a text line on the scanned document image I according to the first line segment set L;
(3) Extracting a skeleton of a scanned document image; setting a rectangular structural element S according to the character direction of a scanned document image I; according to the rectangular structural element S, the first binary image I b1 Performing image expansion to obtain a second binary image I after the image expansion b2 (ii) a Finally, a skeleton extraction algorithm is adopted to carry out on the second binary image I b2 Performing skeleton extraction to obtain skeleton image I s ;
(4) Calculating a first inclination angle by adopting a linear detection algorithm and a linear slope average method; detecting skeleton image I by adopting linear detection algorithm s Obtaining a second line segment set L * (ii) a According to a second line segment set L * Calculating a first inclination angle theta by adopting a straight line slope average method 1 Then at a first inclination angle theta 1 For the first binary image I b1 Carrying out rotation correction to obtain a third binary image I b3 ;
(5) Calculating a second inclination angle by adopting a rotating projection method and a foreground point method in the statistical region; with a as the interval of the first rotation angle, [ theta ] s ,θ e ]For the first rotation angle range, the third binary image I is processed by a rotation projection method b3 Performing g times of rotating projection to obtain a first projection image set P = { P = { (P) } 1 ,P 2 ,…,P j ,…,P g In which P is j J =1,2, \8230;, g for the j-th rotated projection image; calculating a projection image P in a first projection image set P by a foreground point method in a statistical region j Number of regional foreground points V j Using the projection image P of the first set of projection images P j Number of regional foreground points V j Calculating a second rotation angle rangeThen a is used * = a/10 is interval of the second rotation angle,for the second rotation angle range, the rotation projection method is used for the third binary image I b3 G is carried out * Performing secondary rotation projection to obtain a second projection image set P = { P = { (P) 1 ,P 2 ,…,P y ,…,P g* In which P is y J =1,2, \8230;, g, for the y-th rotated projection image * (ii) a Calculating a second projection image set P by a foreground point method in a statistical area * Middle projection image P y * Number of foreground points of region V y * Using the projection image P of the second set of projection images P y * Number of foreground points of region V y * Calculating a second inclination angle theta 2 ;
(6) Rotationally correcting the scanned document image according to the first inclination angle and the second inclination angle; the first inclination angle theta 1 And a second inclination angle theta 2 Adding to obtain an inclination angle theta; taking the central point of the scanned document image I as an original point, rotating the scanned document image I by an angle theta around the original point to obtain a corrected scanned document image I * 。
Further, in the step (2), the writing direction of the text line is determined according to the first segment set L on the scanned document image I, and the specific method is as follows:
(2.1) setting k thr Setting the number n of vertical line segments for the threshold value of the slope of the line segment v And the number n of horizontal line segments h Is 0;
(2.2) for each line segment L in the first line segment set L i Wherein i =1,2, \8230;, d, d is the total number of line segments in the first line segment set L, and the slope k is calculated by adopting the following formula i :
Wherein the content of the first and second substances,andare respectively line segments l i The abscissa and the ordinate of the starting point of (c),andare respectively line segments l i The abscissa and ordinate of the end point of (2);
(2.3) when the slope k i Is greater than or equal to the threshold value k of the slope of the line segment thr When, the number of vertical line segments n v Increasing by 1; otherwise, the number of horizontal line segments n h Increasing by 1;
(2.4) the number n of vertical line segments v Greater than the number n of horizontal line segments h If the character direction of the label scanning document image I is the vertical direction; otherwise, the character direction of the label scanning document image I is the horizontal direction.
Further, in the step (3), the rectangular structural element S is set according to the character direction of the scanned document image I, and the specific method is as follows:
(3.1) setting a rectangular structural element S with the size of M multiplied by N;
(3.2) if the character direction of the scanned document image I is the horizontal direction, when the numerical values of M and N are set, M is larger than N; if the character direction of the scanned document image I is the vertical direction, M is smaller than N when the numerical values of M and N are set.
Further, the step (4) is based on the second line segment set L * Calculating a first inclination angle theta by adopting a straight line slope average method 1 The specific method comprises the following steps:
(4.1) for the second line segment set L * Each line segment ofWherein m =1,2, \ 8230;, u, u is the second set of line segments L * Total number of line segments in the line, calculating slope according to formula (1)
(4.2) according to the second set of line segments L * Each line segment ofSlope of (2)Computing a second set of line segments L * Average slope of (2)The calculation formula is as follows:
(4.3) average slopeConverting into angle to obtain first inclination angle theta 1 The calculation formula is as follows:
(4.4) first binary image I b1 Rotation theta 1 Angle to obtain a third binary image I b3 。
Further, in the step (5), the third binary image I is processed by the rotation projection method b3 G times of rotating projection are carried out, and the specific method is as follows:
(5.1.1) acquiring the width w and the height h of the scanned document image I;
(5.1.2) by theta s Is the initial rotation angleAnd (d) dividing the third binary image I b3 Rotated g times in the clockwise direction, wherein the j-th rotation angle is j × a (j =1,2, \ 8230;, g), resulting in a rotated image I j Will rotate the image I j Classified as a first set of rotated images I f In (3), the specific formula for g is as follows:
(5.1.3) for the first set of rotated images I f Each rotated image I of j Creating an image I and rotating it j Blank images I of the same size j * In which the blank image I j * The initial value of all the pixel points in the group is 255; if the writing direction of the scanned document image I is vertical, the rotating image I is firstly rotated j Performing vertical projection, i.e. statistically rotating the image I j The number M of foreground points in the middle t column t Wherein t =1,2, \8230;, w, w are the width of the scanned document image I, the foreground point is the pixel point with the pixel value of 0, and the blank image I is obtained j * First to Mth rows of the tth column t Setting the line pixel point to be 0 to obtain a projection image P j While projecting an image P j Classified in a first projection image set P; if the writing direction of the scanned document image I is horizontal, the rotating image I is firstly rotated j Performing horizontal projection, i.e. statistically rotating the image I j The number M of foreground pixel points in the middle-r row r Where r is the current line value, r =1,2, \ 8230;, h, h is the height of the scanned document image I, and the blank image I j * First column to M of middle r row r Setting the column pixel point to be 0 to obtain a projection image P j While projecting an image P j Into the first set of projection images P.
Further, the method for counting foreground points in the area in the step (5) specifically includes the following steps:
(5.2.1) calculating projection images P in the first projection image set P by a foreground point method in the statistical region j Number of foreground points of region V j (ii) a That is to say the headFirst from the projection image P j In the first area image S j If the writing direction of the scanned document image I is vertical, the first area image S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein 1<q<6,1<v<q; if the writing direction of the scanned document image I is the horizontal direction, the first area image S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (q, 0), (q + v, 0), (q, h) and (q + v, h), wherein 1<q<6,1<v<q;
(5.2.2) calculating the first region image S j The number of all foreground points in the first projection image set P is the number of the projection images P in the first projection image set P j Number V of foreground points in area j 。
Further, the step (5) is to use the projection image P in the first projection image set P j Number of foreground points of region V j Calculating a second rotation angle rangeThe specific method comprises the following steps:
(5.3.1) projecting image P in first projection image set P j Number of foreground points of region V j Forming key value pairs with the corresponding rotation angle jxa, forming a key value pair set by all the key value pairs, and acquiring the minimum value V of the number of the foreground points in the key value pair set min (ii) a Will minimum value V min The corresponding rotation angles form a first rotation angle setWherein l is the number of the rotation angles in the first rotation angle set;
(5.3.2) if l is equal to 1, the starting angle of the second rotation angle isEnd angle of second rotation angleFurther obtain a second rotation angle rangeIf l is greater than 1, calculating a first rotation angle set theta * Minimum angle ofAnd maximum angleObtaining a second rotation angle range
Further, in the step (5), the third binary image I is processed by the rotational projection method b3 G is carried out * The secondary rotation projection method comprises the following specific steps:
(5.4.1) according to the second rotation angle rangeTo be provided withTo start the rotation angle, a * The third binary image I is divided into two parts, namely a/10 part of the second rotation angle b3 Rotate in the clockwise direction g * Wherein the rotation angle of the y-th time is y × a * (y=1,2,…,g * ) Obtaining a rotated image I y * Will rotate the image I j Classified as a second set of rotated images I f * In (1), in particular g * The calculation formula of (a) is as follows:
(5.4.2) for the second set of rotated images I f * In (1)Each rotated image I y * Creating an image I and rotating it y * Blank images I of the same size y * In which the blank image I y * The initial value of all the pixel points is 255; if the writing direction of the scanned document image I is vertical, the rotating image I is rotated y * Performing vertical projection to obtain a projection image P y * (ii) a If the writing direction of the scanned document image I is horizontal, the rotating image I is rotated y * Performing horizontal projection to obtain a projection image P y * (ii) a Will obtain a projection image P y * Grouped in a second set of projection images P * In (1).
Further, in the step (5), the second projection image set P is calculated by a foreground point method in the statistical region * Middle projection image P y * Number of regional foreground points V y * The specific method comprises the following steps:
(5.5.1) calculating a second set of projection images P by a method of counting foreground points within a region * Middle projection image P y * Number of regional foreground points V y * (ii) a I.e. first from the projection image P y * Middle-cut second area image S y * If the writing direction of the scanned document image I is vertical, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein 1<q<6,1<v<q; if the writing direction of the scanned document image I is the horizontal direction, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (q, 0), (q + v, 0), (q, h) and (q + v, h), wherein 1<q<6,1<v<q;
(5.5.2) calculating the second region image S y * The number of all foreground points in the second projection image set P * Middle projection image P y * Number of regional foreground points V y * ;
Further, the step (5) utilizes the second projection image set P * Middle projection image P y * Number of foreground points of region V y * Calculating a second inclination angle theta 2 The specific method comprises the following steps:
(5.6.1) second set of projection images P * Middle projection image P y * Number of foreground points of region V y * And the corresponding rotation angle y × a * Forming key value pairs, forming all the key value pairs into a key value pair set, and acquiring the minimum value V of the number of foreground points in the key value pair set min * (ii) a Will minimum value V min * The corresponding rotation angles form a second rotation angle setWherein z is the number of the rotation angles in the second rotation angle set;
(5.6.2) if z is equal to 1, thenAt a second inclination angle theta 2 (ii) a If the number z of the rotation angles is larger than 1, calculating a second inclination angle theta according to an average formula 2 The specific averaging formula is as follows:
the image binarization algorithm in the step (1) is to convert the image with the pixel value range of [0,255] into the image with the pixel values of only 0 and 255. See Chen X, wang K, wang Q.A. adaptive binding method for camera based document image [ M ]// Software Engineering and Knowledge Engineering: theory and practice.Springer, berlin, heidelberg,2012: 677-684.
The dilation algorithm in step (3) is a relatively common image morphology method, see Kleefeld A, vorderwulcke S, burgth B. Organic diffusion, and oxidation in image processing [ J ]. International journal of computer mechanics, 2018,95 (6-7): 1375-1393.
The skeleton extraction algorithm in step (3) is a method for extracting the central pixel outline of the target on the image, see safe K,M,Rybnik M,et al.K3M:A universal algorithm for image skeletonization and a review of thinning techniques[J].2010。
the line detection algorithm in step (2) or step (4) is a method for detecting lines in an image, see Zhang L, huang X.A. straight line detection method based on edge following and line segments integration [ C ]//2015 6th IEEE International Conference on Software Engineering and Service Science (ICSESS). IEEE 2015 297-300.
Compared with the prior art, the invention has the advantages that: according to the document image inclination angle detection method based on segmented projection, a finer rotation angle range is calculated by setting a first rotation projection angle range and a first rotation angle interval, and then an optimal inclination angle is obtained by setting a second rotation projection angle range and a second rotation angle interval. Compared with the traditional projection correction method, the method can quickly obtain the inclination angle of the scanned document image and perform inclination correction, can perform inclination correction on the scanned document image with undefined boundary, and can realize the high-precision inclination correction effect.
Drawings
The present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
FIG. 1 is a flow chart of a method of an embodiment of the present invention;
FIG. 2 is a first binary image I obtained in step (1) according to an embodiment of the present invention b1 ;
FIG. 3 is a second binary image I obtained in step (3) of the present invention b2 ;
FIG. 4 is a skeleton image I obtained in step (3) of the present invention s ;
FIG. 5 is a third binary image I obtained in step (4) of the present invention b3 ;
FIG. 6 shows the corrected scanned document image I obtained in step (6) of the embodiment of the present invention * 。
Detailed Description
The following description will explain embodiments of the present invention in further detail with reference to the accompanying drawings in the examples of the present invention. It should be noted that the specific embodiment of the document image tilt correction method based on segmented projection according to the present invention is only an example and is not intended to limit the present invention.
The present embodiment describes a document image tilt correction algorithm based on the segmented projection in connection with a scanned document image I having a width of 1475 pixels and a height of 2655 pixels. As shown in the method flow chart of FIG. 1, the present invention adopts the following steps to detect the tilt angle of the scanned document image:
(1) Preprocessing a scanned document image; converting a scanned document image I into a grayscale image I g Subsequently to the gray scale image I g Carrying out image binarization operation to obtain a first binary image I b1 As shown in fig. 2;
(2) Determining a writing direction of the scanned document image; adopting Hough line detection algorithm to carry out detection on first binary image I b1 Performing linear detection to obtain a first line segment set L, and judging the writing direction of a text line on the scanned document image I according to the first line segment set L;
the Hough line detection algorithm used in the above steps is a commonly used line detection algorithm, see Galamhos C, matas J, kittler J. Progressive robust Hough transform for line detection [ C ]// proceedings.1999 IEEE computer society conference on computer vision and pattern recognition (Cat. No. PR 00149) IEEE,1999, 1;
(3) Extracting a skeleton of a scanned document image; setting a rectangular structural element S according to the character direction of a scanned document image I; according to the rectangular structural element S, the first binary image I b1 Carrying out image expansion to obtain a second binary image I after expansion b2 As shown in FIG. 3(ii) a Finally, adopting Zhang fast parallel thinning algorithm to carry out thinning algorithm on the second binary image I b2 Performing skeleton extraction to obtain skeleton image I s As shown in fig. 4;
the Zhang fast parallel refinement algorithm adopted in the above steps is a commonly used framework extraction method, see Zhang T Y, suen C Y.A fast parallel algorithm for the linking digital patterns [ J ]. Communications of the ACM,1984,27 (3): 236-239;
(4) Calculating a first inclination angle by adopting a linear detection algorithm and a linear slope averaging method; detecting skeleton image I by adopting linear detection algorithm s Obtaining a second line segment set L * (ii) a According to the second line segment set L * The first inclination angle theta is calculated by adopting a straight-line slope average method 1 Then at a first inclination angle theta 1 For the first binary image I b1 Carrying out rotation correction to obtain a third binary image I b3 As shown in fig. 5;
(5) Calculating a second inclination angle by adopting a rotating projection method and a foreground point method in the statistical region; with a =0.1 ° as the interval of the first rotation angle, [ θ ] s ,θ e ]=[-0.5°,0.5°]For the first rotation angle range, the rotation projection method is used for the third binary image I b3 Performing g =10 rotation projections to obtain a first projection image set P = { P = { (P) } 1 ,P 2 ,…,P j ,…,P g In which P is j J =1,2, \ 8230for the j-th rotated projection image, g; calculating a projection image P in a first projection image set P by a foreground point method in a statistical region j Number of foreground points V of middle area j Using the projection images P of the first set of projection images P j Number of foreground points of region V j Calculating a second rotation angle rangeThen a with * = a/10 is the interval of the second rotation angle,for the second rotation angle range, the third two is projected by rotationValue image I b3 G is carried out * Performing secondary rotation projection to obtain a second projection image set P = { P = { (P) 1 ,P 2 ,…,P y ,…,P g* In which P is y For the y-th rotated projection image, j =1,2, \8230;, g * (ii) a Calculating a second projection image set P by a foreground point method in a statistical area * Middle projection image P y * Number of foreground points of region V y * Using the projection image P of the second set of projection images P y * Number of foreground points of region V y * Calculating a second inclination angle theta 2 ;
(6) And rotationally correcting the scanned document image according to the first inclination angle and the second inclination angle. The first inclination angle theta 1 And a second inclination angle theta 2 Adding to obtain an inclination angle theta; taking the central point of the scanned document image I as an original point, rotating the scanned document image I by an angle theta around the original point to obtain a corrected scanned document image I * As shown in fig. 6.
Further, in the step (2), the writing direction of the text line is determined according to the first segment set L on the scanned document image I, and the specific method is as follows:
(2.1) setting k thr Setting the number n of vertical line segments for the threshold value of the slope of the line segment v And the number n of horizontal line segments h Is 0;
(2.2) for each line segment L in the first line segment set L i Wherein i =1,2, \ 8230;, d, d is the total number of line segments in the first line segment set L, and the slope k is calculated by the following formula i :
Wherein the content of the first and second substances,andare respectively line segmentsl i The abscissa and the ordinate of the starting point of (c),andare respectively line segments l i The abscissa and ordinate of the end point of (2);
(2.4) when the slope k i Greater than or equal to the threshold k of the slope of the line segment thr Time, vertical line segment number n v Increasing by 1; otherwise, the number of horizontal line segments n h Increasing by 1;
(2.5) the number n of vertical line segments v Greater than the number n of horizontal line segments h If the character direction of the label scanning document image I is the vertical direction; otherwise, the character direction of the label scanning document image I is the horizontal direction.
Further, in the step (3), the rectangular structural element S is set according to the character direction of the scanned document image I, and the specific method is as follows:
(3.1) setting a rectangular structural element S with the size of M multiplied by N;
(3.2) if the character direction of the scanned document image I is the horizontal direction, setting M =7, n =3; if the character direction of the scanned document image I is the vertical direction, M =3, n =7 is set.
Further, the step (4) is based on the second line segment set L * Calculating a first inclination angle theta by adopting a straight line slope average method 1 The specific method comprises the following steps:
(4.1) for the second line segment set L * Each line segment ofWherein m =1,2, \ 8230;, u, u is the second set of line segments L * Total number of segments in the line, calculating the slope according to equation (1)
(4.2) according to the second set of line segments L * Each line segment ofSlope of (2)Computing a second set of line segments L * Average slope of (2)The calculation formula is as follows:
(4.3) average slopeConverting into angle to obtain first inclination angle theta 1 The calculation formula is as follows:
(4.4) first binary image I b1 Rotation of theta 1 Angle to obtain a third binary image I b3 。
Further, in the step (5), the third binary image I is processed by the rotational projection method b3 G =10 rotation projections are performed, and the specific method is as follows:
(5.1.1) acquiring the width w and the height h of the scanned document image I;
(5.1.2) in [ theta ] s For starting the rotation angle, the third binary image I b3 Rotated g times in the clockwise direction, wherein the j-th rotation angle is j × a (j =1,2, \ 8230;, g), resulting in a rotated image I j Will rotate the image I j Classified as a first set of rotated images I f In (3), the specific formula for g is as follows:
(5.1.3) for the first set of rotated images I f Each rotated image I in (1) j Creating an image I and rotating it j Blank images I of the same size j * In which the blank image I j * The initial value of all the pixel points in the group is 255; if the writing direction of the scanned document image I is vertical, the rotating image I is firstly rotated j Performing vertical projection, i.e. statistically rotating the image I j The number M of foreground points in the middle t column t Where t =1,2, \ 8230;, w, w are the width of the scanned document image I, the foreground point is the pixel point with pixel value 0, and the blank image I j * First to Mth rows of the tth column t Setting the line pixel point to be 0 to obtain a projection image P j While projecting an image P j Classified in a first projection image set P; if the writing direction of the scanned document image I is horizontal, the rotating image I is firstly rotated j Performing horizontal projection, i.e. statistically rotating the image I j The number M of foreground pixel points in the middle-r row r Wherein r is the current line value, r =1,2, \8230;, h is the height of the scanned document image I, and the blank image I is obtained j * First column to Mth of the r-th row r Setting the column pixel point to be 0 to obtain a projection image P j While projecting an image P j Into the first set of projection images P.
Further, the method for counting foreground points in the area in the step (5) specifically includes the following steps:
(5.2.1) calculating the projection image P in the first projection image set P by a foreground point method in the statistical area j Number of foreground points of region V j (ii) a I.e. first from the projection image P j In the first area image S j If the writing direction of the scanned document image I is vertical, the first area image S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein q =5, v =2; if the writing direction of the scanned document image I is the horizontal direction, the first areaImage S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex of (q, 0), (q + v, 0), (q, h), (q + v, h), respectively, wherein q =5, v =2;
(5.2.3) calculating the first region image S j The number of all foreground points in the first projection image set P is the number of the projection images P in the first projection image set P j Number V of foreground points in area j 。
Further, the step (5) is to use the projection image P in the first projection image set P j Number of foreground points of region V j Calculating a second rotation angle rangeThe specific method comprises the following steps:
(5.3.1) projecting image P in first projection image set P j Number of foreground points of region V j Forming key value pairs with the corresponding rotation angle jxa, forming a key value pair set by all the key value pairs, and obtaining the minimum value V of the number of the regional foreground points in the key value pair set min . Will minimum value V min The corresponding rotation angles form a first rotation angle setWherein l is the number of the rotation angles in the first rotation angle set;
(5.3.2) if l is equal to 1, the starting angle of the second rotation angle isEnd angle of second rotation angleFurther obtain a second rotation angle rangeIf l is larger than 1, calculating the minimum angle in the first rotation angle set thetaAnd maximum angleObtaining a second rotation angle range
Further, in the step (5), the third binary image I is processed by the rotational projection method b3 G is carried out * The secondary rotation projection method comprises the following specific steps:
(5.4.1) according to the second rotation angle rangeTo be provided withTo start the rotation angle, a * The third binary image I is divided into two parts, namely a/10 part of the second rotation angle b3 Rotate in the clockwise direction g * Wherein the rotation angle of the y-th order is y × a * (y=1,2,…,g * ) Obtaining a rotated image I y * Will rotate the image I j Classified as a second set of rotated images I f * In (1), in particular g * The calculation formula of (a) is as follows:
(5.4.2) for the second set of rotated images I f * Each rotated image I in (1) y * Creating an image I and rotating it y * Blank images I of the same size y * In which the blank image I y * The initial value of all the pixel points in the group is 255; if the writing direction of the scanned document image I is vertical, rotating the image I y * Performing vertical projection to obtain a projection image P y * (ii) a If the document is scannedWhen the writing direction of the image I is horizontal, the rotating image I is rotated y * Performing horizontal projection to obtain a projection image P y * (ii) a Will obtain a projection image P y * Classified as a second set of projection images P * Performing the following steps;
further, in the step (5), the second projection image set P is calculated by a foreground point method in the statistical region * Each of which is projected image P y * Number of regional foreground points V y * The specific method comprises the following steps:
(5.5.1) calculating a second set of projection images P by a method of counting foreground points within a region * Middle projection image P y * Number of foreground points of region V y * (ii) a I.e. first from the projection image P y * Middle-cut second area image S y * If the writing direction of the scanned document image I is vertical, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein q =5, v =2q; if the writing direction of the scanned document image I is the horizontal direction, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (q, 0), (q + v, 0), (q, h), (q + v, h), respectively, wherein q =5, v =2;
(5.5.2) calculating the second region image S y * The number of all foreground points in the second projection image set P * Middle projection image P y * Number of foreground points of region V y * ;
Further, the step (5) utilizes the second projection image set P * Middle projection image P y * Number of foreground points of region V y * Calculating a second inclination angle theta 2 The specific method comprises the following steps:
(5.6.1) second set of projection images P * Middle projection image P y * Number of foreground points of region V y * And the corresponding rotation angle y × a * Forming key value pairs, forming all the key value pairs into a key value pair set, and acquiring the minimum value V of the number of foreground points in the key value pair set min * (ii) a Will minimum value V min * The corresponding rotation angles form a second rotation angle setWherein z is the number of the rotation angles in the second rotation angle set;
(5.6.2) if z is equal to 1, thenAt a second inclination angle theta 2 (ii) a If the number z of the rotation angles is larger than 1, calculating a second inclination angle theta according to an average formula 2 The specific averaging formula is as follows:
the above description is meant to be illustrative of the preferred embodiments of the invention and not to limit the invention, and equivalents and modifications may be made without departing from the spirit of the invention.
Claims (10)
1. A method for correcting the tilt of a scanned document image based on segmented projection, the method comprising the steps of:
(1) Preprocessing a scanned document image; converting a scanned document image I into a grayscale image I g Then, an image binarization algorithm is adopted to carry out on the gray level image I g Carrying out image binarization operation to obtain a first binary image I b1 ;
(2) Determining a writing direction of the scanned document image; using a line detection algorithm to perform on the first binary image I b1 Performing linear detection to obtain a first line segment set L, and judging the writing direction of a text line on the scanned document image I according to the first line segment set L;
(3) Extracting a skeleton of a scanned document image; setting a rectangular structural element S according to the character direction of a scanned document image I; according to the rectangular structural element S, the first binary image I b1 Performing image expansion to obtain a second binary image I after the image expansion b2 (ii) a Finally, a skeleton extraction algorithm is adopted to carry out on the second binary image I b2 Performing skeleton extraction to obtain skeleton image I s ;
(4) Calculating a first inclination angle by adopting a linear detection algorithm and a linear slope averaging method; detecting skeleton image I by adopting linear detection algorithm s Obtaining a second line segment set L * (ii) a According to a second line segment set L * The first inclination angle theta is calculated by adopting a straight-line slope average method 1 Then at a first inclination angle theta 1 For the first binary image I b1 Carrying out rotation correction to obtain a third binary image I b3 ;
(5) Calculating a second inclination angle by adopting a rotating projection method and a foreground point method in the statistical region; with a as the interval of the first rotation angle, [ theta ] s ,θ e ]For the first rotation angle range, the third binary image I is processed by a rotation projection method b3 Performing g times of rotating projection to obtain a first projection image set P = { P = { (P) } 1 ,P 2 ,…,P j ,…,P g In which P is j J =1,2, \8230;, g for the j-th rotated projection image; calculating a projection image P in a first projection image set P by a foreground point method in a statistical region j Number of regional foreground points V j Using the projection images P of the first set of projection images P j Number of foreground points of region V j Calculating a second rotation angle rangeThen a is used * = a/10 is the interval of the second rotation angle,for the second rotation angle range, the rotation projection method is used for the third binary image I b3 G is carried out * Sub-rotating the projection to obtain the secondSet of two projection imagesWherein P is y For the y-th rotated projection image, j =1,2, \8230;, g * (ii) a Calculating a second projection image set P by a foreground point method in a statistical region * Middle projection image P y * Number of regional foreground points V y * Using the projection images P of the second set of projection images P y * Number of regional foreground points V y * Calculating a second inclination angle theta 2 ;
(6) Correcting the scanned document image in a rotating mode according to the first inclination angle and the second inclination angle; the first inclination angle theta 1 And a second inclination angle theta 2 Adding to obtain an inclination angle theta; taking the central point of the scanned document image I as an original point, rotating the scanned document image I by an angle theta around the original point to obtain a corrected scanned document image I * 。
2. The method according to claim 1, wherein the writing direction of the text line is determined according to the first line set L in step (2) by:
(2.1) setting k thr Setting the number n of vertical line segments for the threshold value of the slope of the line segment v And the number n of horizontal line segments h Is 0;
(2.2) for each line segment L in the first line segment set L i Wherein i =1,2, \8230;, d, d is the total number of line segments in the first line segment set L, and the slope k is calculated by adopting the following formula i :
Wherein, the first and the second end of the pipe are connected with each other,are respectively a line segment l i The abscissa and the ordinate of the starting point of (c),are respectively line segments l i The abscissa and ordinate of the end point of (2);
(2.3) when the slope k i Greater than or equal to the threshold k of the slope of the line segment thr Time, vertical line segment number n v Increasing by 1; otherwise, the number of horizontal line segments n h Increasing by 1;
(2.4) the number n of vertical line segments v Greater than the number n of horizontal line segments h If the character direction of the label scanning document image I is the vertical direction; otherwise, the character direction of the label scanning document image I is the horizontal direction.
3. The method according to claim 2, wherein the rectangular structural element S is set according to the character direction of the scanned document image I in step (3), and the specific method is as follows:
(3.1) setting a rectangular structural element S with the size of M multiplied by N;
(3.2) if the character direction of the scanned document image I is the horizontal direction, when the numerical values of M and N are set, M is larger than N; if the character direction of the scanned document image I is the vertical direction, M is smaller than N when the numerical values of M and N are set.
4. The method according to claim 3, wherein said step (4) comprises correcting the image tilt of the scanned document according to the second line segment set L * The first inclination angle theta is calculated by adopting a straight-line slope average method 1 The specific method comprises the following steps:
(4.1) for the second line segment set L * Each line segment ofWherein m =1,2, \8230;, u, u is the second line segment set L * The total number of line segments in the line is calculated according to the formula (1)Slope of
(4.2) according to the second set of segments L * Each line segment ofSlope of (2)Computing a second set of line segments L * Average slope ofThe calculation formula is as follows:
(4.3) average slopeConverting into angle to obtain first inclination angle theta 1 The calculation formula is as follows:
(4.4) first binary image I b1 Rotation theta 1 Angle to obtain a third binary image I b3 。
5. The method according to claim 4, wherein said rotating projection is used to correct the tilt of the scanned document image I in step (5) b3 G times of rotating projection are carried out, and the specific method is as follows:
(5.1.1) acquiring the width w and the height h of the scanned document image I;
(5.1.2) by theta s For starting the rotation angle, the third binary image I b3 Rotated g times in the clockwise direction, wherein the j-th rotation angle is j × a (j =1,2, \ 8230;, g), resulting in a rotated image I j Will rotate the image I j Classified as a first set of rotated images I f In (3), the specific formula for g is as follows:
(5.1.3) for the first set of rotated images I f Each rotated image I in (1) j Creating an image I and rotating it j Blank images I of the same size j * In which the blank image I j * The initial value of all the pixel points in the group is 255; if the writing direction of the scanned document image I is vertical, the rotating image I is firstly rotated j Performing vertical projection, i.e. statistically rotating the image I j The number M of foreground points in the middle t column t Where t =1,2, \ 8230;, w, w are the width of the scanned document image I, the foreground point is the pixel point with pixel value 0, and the blank image I j * First row to M of the t-th column t Setting the line pixel point to be 0 to obtain a projection image P j While projecting an image P j Classified in a first projection image set P; if the writing direction of the scanned document image I is horizontal, the rotating image I is firstly rotated j Performing horizontal projection, i.e. statistically rotating the image I j The number M of foreground pixel points in the middle-r row r Wherein r is the current line value, r =1,2, \8230;, h is the height of the scanned document image I, and the blank image I is obtained j * First column to M of middle r row r Setting the column pixel point to be 0 to obtain a projection image P j While projecting the image P j Into the first set of projection images P.
6. The method for correcting the inclination of the scanned document image based on the segmented projection as claimed in claim 5, wherein the method for counting foreground points in the area in step (5) is as follows:
(5.2.1) calculating projection images P in the first projection image set P by a foreground point method in the statistical region j Number of foreground points of region V j (ii) a I.e. first from the projection image P j In the first area image S j If the writing direction of the scanned document image I is vertical, the first area image S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein 1<q<6,1<v<q; if the writing direction of the scanned document image I is the horizontal direction, the first area image S j The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are respectively (q, 0), (q + v, 0), (q, h) and (q + v, h), wherein 1<q<6,1<v<q;
(5.2.2) calculating the first region image S j The number of all foreground points in the first projection image set P is the number of the projection images P in the first projection image set P j Number V of foreground points in area j 。
7. The method according to claim 6, wherein the step (5) utilizes the projection image P in the first projection image set P j Number of foreground points of region V j Calculating a second rotation angle rangeThe specific method comprises the following steps:
(5.3.1) projecting image P in first projection image set P j Number of foreground points of region V j Forming key value pairs with the corresponding rotation angle jxa, forming a key value pair set by all the key value pairs, and acquiring the minimum value V of the number of the foreground points in the key value pair set min (ii) a Will minimum value V min The corresponding rotation angles form a first rotation angle setWherein l is the number of the rotation angles in the first rotation angle set;
8. The method for correcting the inclination of the scanned document image based on the segmented projection as claimed in claim 7, wherein the step (5) is performed by using the rotation projection method to the third binary image I b3 G is carried out * The secondary rotation projection method comprises the following specific steps:
(5.4.1) according to the second rotation angle rangeTo be provided withTo start the rotation angle, a * = a/10 interval of second rotation angle, and the third oneValue image I b3 Rotate in the clockwise direction g * Wherein the rotation angle of the y-th order is y × a * (y=1,2,…,g * ) Obtaining a rotated image I y * Will rotate the image I j Classified as a second set of rotated images I f * In (1), in particular g * The calculation formula of (c) is as follows:
(5.4.2) for the second set of rotated images I f * Each rotated image I of y * Creating an image I and rotating it y * Blank images I of the same size y * In which the blank image I y * The initial value of all the pixel points in the group is 255; if the writing direction of the scanned document image I is vertical, rotating the image I y * Performing vertical projection to obtain a projection image P y * (ii) a If the writing direction of the scanned document image I is horizontal, the rotating image I is rotated y * Performing horizontal projection to obtain a projection image P y * (ii) a Will obtain a projection image P y * Classified as a second set of projection images P * In (1).
9. The method for correcting the tilt of an image of a scanned document based on segmented projection as claimed in claim 8, wherein the step (5) is performed by calculating the second set of projection images P by a foreground point method in the statistical region * Middle projection image P y * Number of regional foreground points V y * The specific method comprises the following steps:
(5.5.1) calculating a second set of projection images P by a method of counting foreground points within a region * Middle projection image P y * Number of foreground points of region V y * (ii) a I.e. first from the projection image P y * Middle-cut second area image S y * If the writing side of the document image I is scannedIn the vertical direction, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (0, q), (w, q), (0, q + v), (w, q + v), respectively, wherein 1<q<6,1<v<q; if the writing direction of the scanned document image I is the horizontal direction, the second area image S y * The coordinates of the top left corner vertex, the top right corner vertex, the bottom left corner vertex and the bottom right corner vertex are (q, 0), (q + v, 0), (q, h) and (q + v, h), wherein 1<q<6,1<v<q;
(5.5.2) calculating the second region image S y * The number of all foreground points in the second set of projection images P * Middle projection image P y * Number of foreground points of region V y * 。
10. The method according to claim 9, wherein said step (5) utilizes a second set of projection images P * Middle projection image P y * Number of foreground points of region V y * Calculating a second inclination angle theta 2 The specific method comprises the following steps:
(5.6.1) second set of projection images P * Middle projection image P y * Number of regional foreground points V y * And the corresponding rotation angle y × a * Forming key value pairs, forming all the key value pairs into a key value pair set, and acquiring the minimum value V of the number of foreground points in the key value pair set min * (ii) a Will minimum value V min * The corresponding rotation angles form a second rotation angle setWherein z is the number of the rotation angles in the second rotation angle set;
(5.6.2) if z is equal to 1, thenAt a second inclination angle theta 2 (ii) a If the number z of the rotation angles is larger than 1, calculating a second inclination angle theta according to an average formula 2 The specific average formula is as follows:
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211289169.4A CN115601757A (en) | 2022-10-20 | 2022-10-20 | Scanning document image inclination correction method based on segmented projection |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202211289169.4A CN115601757A (en) | 2022-10-20 | 2022-10-20 | Scanning document image inclination correction method based on segmented projection |
Publications (1)
Publication Number | Publication Date |
---|---|
CN115601757A true CN115601757A (en) | 2023-01-13 |
Family
ID=84849232
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202211289169.4A Pending CN115601757A (en) | 2022-10-20 | 2022-10-20 | Scanning document image inclination correction method based on segmented projection |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN115601757A (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115880699A (en) * | 2023-03-03 | 2023-03-31 | 济南市莱芜区综合检验检测中心 | Food packaging bag detection method and system |
CN117315664A (en) * | 2023-09-18 | 2023-12-29 | 山东博昂信息科技有限公司 | Scrap steel bucket number identification method based on image sequence |
-
2022
- 2022-10-20 CN CN202211289169.4A patent/CN115601757A/en active Pending
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN115880699A (en) * | 2023-03-03 | 2023-03-31 | 济南市莱芜区综合检验检测中心 | Food packaging bag detection method and system |
CN117315664A (en) * | 2023-09-18 | 2023-12-29 | 山东博昂信息科技有限公司 | Scrap steel bucket number identification method based on image sequence |
CN117315664B (en) * | 2023-09-18 | 2024-04-02 | 山东博昂信息科技有限公司 | Scrap steel bucket number identification method based on image sequence |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN115601757A (en) | Scanning document image inclination correction method based on segmented projection | |
CN108921865B (en) | Anti-interference sub-pixel straight line fitting method | |
Gatos et al. | Segmentation based recovery of arbitrarily warped document images | |
US20110280477A1 (en) | Method and system for preprocessing an image for optical character recognition | |
JP2003304390A5 (en) | ||
CN101697228A (en) | Method for processing text images | |
CN107992869B (en) | Method and device for correcting tilted characters and electronic equipment | |
CN110647795A (en) | Form recognition method | |
CN110458167B (en) | Metal piece surface bending text line correction method | |
CN106447615A (en) | Inclination correction method for scanned document image | |
CN115619845A (en) | Self-adaptive scanning document image inclination angle detection method | |
CN111275049B (en) | Method and device for acquiring text image skeleton feature descriptors | |
WO1991020055A1 (en) | Self-centering character stroke thickening for optical character recognition | |
CN107609482B (en) | Chinese text image inversion discrimination method based on Chinese character stroke characteristics | |
WO2018061997A1 (en) | Medium recognition device and medium recognition method | |
CN112036294A (en) | Method and device for automatically identifying paper table structure | |
CN111626236A (en) | Rapid ellipse target detection method | |
CN112036232A (en) | Image table structure identification method, system, terminal and storage medium | |
CN114998347B (en) | Semiconductor panel corner positioning method and device | |
CN115410191B (en) | Text image recognition method, device, equipment and storage medium | |
CN115082939B (en) | System and method for correcting distortion table in image based on arc differentiation | |
JP3303246B2 (en) | Image processing device | |
CN112383670B (en) | Test paper scanning automatic centering method and device | |
KR100603618B1 (en) | Apparatus and Method for Geometric Distortion Correction of Document Image using Affine Transform | |
WO2004032482A1 (en) | Image reading device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication |