A kind of method of image object level angle correction
Technical field
The invention belongs to Computer Image Processing field, for quickly determining that image object needs to carry out the angle of level correction right
Image makes level correction.
Background technology
Image procossing, also known as image processing, is the technology that image is analyzed reaching results needed with computer.Due to image
It is more likely to produce distortion during generating and transmitting, such as colour cast, fuzzy, geometric distortion, geometry inclination etc., so
Before analyzing image in detail, needing image is carried out pretreatment, with the distortion of correction chart picture, making image reach can
The degree analyzed.At present, the application of image distortion correction is increasingly wider, nearly all neck relating to application scanning and imaging
Territory is required for the distortion correction of image.
One relatively common in the distortion correction of image carries out Slant Rectify to image exactly.The image obtained by input equipment
Inevitably run-off the straight, this can bring difficulty to image processing and analysis work such as follow-up image recognitions, therefore, right
Significant in the correction of the level angle of image.
The core of image inclination angle correction is the most quickly and accurately to determine angle to be corrected.In prior art, typically
The determination method of image rectification angle is all detection edge, by profile slope calculations.Such as, Chinese patent literature
CN104318233A discloses a kind of license plate image rectification method, and the method utilizes character rule to search the conjunction of edge image
Method character connected domain, clicks on line linearity matching to the upper and lower side of connected domain and finds character zone up-and-down boundary, try to achieve slope, with this
Obtain the anglec of rotation of slant correction.But this kind of method scope of application is narrow, and the method for rim detection is the most unreliable.
In view of above-mentioned background, it is necessary to propose that a kind of scope of application is wider, efficiency and accuracy higher image level bearing calibration.
Summary of the invention
It is an object of the invention to: provide and a kind of be independent of edge contour, the image water that applied widely, speed is fast, effective
Flat correction angle determination method.
The above-mentioned purpose of the present invention is achieved through the following technical solutions:
A kind of determination method of image object level correction angle is provided, comprises the following steps:
1) initial pictures to be corrected is done gray proces, obtain single channel image, and do elimination noise processed;
2) image is rotated the most continuously;After rotating, first image is carried out edge enhancing and binary conversion treatment, so every time
Rear statistical picture arrange as the amount of the pixel of the right and left positional symmetry during axis of symmetry with each pixel, the symmetry obtained with statistics
The amount of pixel, as the score of corresponding axis of symmetry, records the best result X in all axis of symmetry scoresn, n therein be relative to
The anglec of rotation of initial pictures, takes the rational number between 0-360;Complete after 360 ° of initial pictures rotate and add up,
Find out all XnIn maximum, n therein be initial pictures need correction angle.
Step 1) described in initial pictures to be corrected is done gray proces, existing various ways can be used to complete, the present invention
The gray scale processing method formula preferably employed is as follows: v=0.31 × R+0.52 × G+0.17 × B.
Step 1) described in elimination noise processed, existing various ways can be used to complete, present invention preferably employs in 3 × 3
The method of value filtering.
Step 2) described in rotate image continuously, the angle every time rotated both can be identical, it is also possible to different, the angle of rotation
Arbitrarily angled in the range of can being 0-360 °;The present invention rotates with equal angular preferably every time, and each anglec of rotation is less than 3 °;
The anglec of rotation is not more than 1 ° the most every time.
Step 2) described in edge strengthen and can be realized by multiple means in existing method, the enhancing of currently preferred edge
Method is, with Sobel (Sobel) operator, image is done rim detection, in order to obtain more accurate edge detection results, this
Image is done rim detection by the Sobel operator of the bright following kernel of further preferred employing:
Step 2) described in binaryzation can be realized by multiple means in existing method, currently preferred binarization method
It is that Otsu algorithm (Otsu) carries out binary conversion treatment to image, at utmost to retain picture edge characteristic.
The determination method of the most preferred a kind of coloured image object level correction angle of the present invention, comprises the following steps:
1) initial pictures to be corrected is done gray proces, obtain single channel image, and do elimination noise processed;
1.1) use equation below that coloured image is carried out gray proces, obtain single channel image:
V=0.31 × R+0.52 × G+0.17 × B
1.2) to step 1.1) single channel image that obtains does 3 × 3 medium filterings, eliminates noise;
2) fixed angle with no more than 1 ° rotates through step 1.2 continuously for step-length in the horizontal direction) image that processes;Every time
After rotation, first with sobel operator, image done rim detection, then with Otsu algorithm (Otsu), image carried out binary conversion treatment,
Then statistical picture arranges as the amount of the pixel of the right and left positional symmetry during axis of symmetry with each pixel, with statistics obtain right
Claim the amount of pixel as the score of corresponding axis of symmetry, record the best result X in all axis of symmetry scoresn, n therein is relative
In the anglec of rotation of initial pictures, take the rational number between 0-360;Described sobel operator is the Sobel operator of following kernel:
Complete, after 360 ° of initial pictures rotate and add up, to find out all XnIn maximum, at the beginning of n therein is
Beginning image needs the angle of correction.
On this basis, a kind of method that the present invention further provides image object level correction, comprise the following steps:
(1) initial pictures to be corrected is done gray proces, obtain single channel image, and do elimination noise processed;
(1.1) use equation below that coloured image is carried out gray proces, obtain single channel image:
V=0.31 × R+0.52 × G+0.17 × B
(1.2) single channel image obtaining step (1.1) does 3 × 3 medium filterings, eliminates noise;
(2) fixed angle with no more than 1 ° rotates the image processed through step (1.2) continuously for step-length in the horizontal direction;Often
After secondary rotation, first with sobel operator, image done rim detection, then with Otsu algorithm (Otsu), image carried out binary conversion treatment,
Then statistical picture arranges as the amount of the pixel of the right and left positional symmetry during axis of symmetry with each pixel, with statistics obtain right
Claim the amount of pixel as the score of corresponding axis of symmetry, record the best result X in all axis of symmetry scoresn, n therein is relative
In the anglec of rotation of initial pictures, take the rational number between 0-360;The axis of symmetry coordinate that score is maximum is designated as x=a;Described
Sobel operator is the Sobel operator of following kernel:
Complete, after 360 ° of initial pictures rotate and add up, to find out all XnIn maximum, at the beginning of n therein is
Beginning image needs the angle of correction;
(3) step (2) described x=a be x coordinate point as rotate initial point, rotate image, the anglec of rotation is described in step (2)
N, completes the level correction of image.
Compared with prior art, the image level correction angle determination method of the present invention may apply to the big portion of various common scene
Divide the two dimensional image of object, especially for symmetrical subject image, the feelings most by finding symmetrical pixel
Condition, quickly determines the horizontal adjustment angle of picture of publishing picture, it is possible to be independent of edge contour, applied widely, determine speed fast,
Degree of accuracy is high.
Accompanying drawing explanation
Fig. 1 is the flow chart of the image level bearing calibration described in the embodiment of the present invention 1.
Fig. 2 a is the image effect schematic diagram after step 4 process of embodiment 2.
Fig. 2 b is symmetrical pixels point statistical method signal when being classified as axis of symmetry of a certain x coordinate place described in embodiment 2 step 5.1
Figure.
Detailed description of the invention
Below by way of the mode enumerating embodiment, technical scheme is described further.
Embodiment 1
A kind of method of coloured image level correction, as it is shown in figure 1, comprise the following steps:
1. transfer coloured image to single channel image according to below equation,
V=0.31 × R+0.52 × G+0.17 × B
2. pair image does 3x3 medium filtering;
3. the image after processing step 2 with following sobel operator does rim detection;
4. the image after processing step 3 by otsu method does binary conversion treatment;
5. for step 4 process after image in each column statistics symmetrical pixels number:
Arranging as axis of symmetry with each x coordinate place, the point of the every a line the right and left in statistical picture is the most symmetrical, also respectively
Be exactly symmetric position be all 255 (or not being 0), if symmetrical, then+1;Under each x coordinate, add up after all row
The statistical value of the most all row is added, and the total value obtained is exactly the score of this x coordinate;Record in all x coordinate scores
High score;The x coordinate of score maximum is axis of symmetry coordinate x=a;
6. being rotated by image, step-length is 1 °, rotates post processor and jumps into step 3, repeats step 3-5;Until rotating
Terminate when complete 360 ° to rotate;
7. the best result in all x coordinate scores obtained added up in record every time after rotating, and the x coordinate of score maximum is symmetry
Axial coordinate x=a;
8. find the maximum in x coordinate best result under all anglecs of rotation, its corresponding image rotation angle, be this first
The angle that beginning image is to be corrected.
9. x=a described in step 7 be x coordinate point as rotate initial point, rotate image, the anglec of rotation is the rotation that step 8 determines
Gyration, completes the level correction of image.
Embodiment 2
A kind of determination method of coloured image level correction angle, comprises the following steps:
1. transfer coloured image to single channel image according to below equation, obtain single channel image
V=0.31 × R+0.52 × G+0.17 × B
2. pair gained single channel image does 3x3 medium filtering, removes picture noise;
3. with following sobel operator, image is done rim detection;
4. with otsu method to step 3 process after image do binary conversion treatment, the image effect after process as shown in Figure 2 a, its
Only it is made up of the black pixel point that gray value is 255 and the white pixel point that gray value is 0;
5. in Fig. 2 a each column add up symmetrical pixels number:
5.1 arrange as axis of symmetry with each x coordinate place, the point of the every a line the right and left in statistical picture has how many group right respectively
Claiming, namely the gray value of symmetric position pixel is all 255 (or not being the most 0), as long as being found to have the pixel of symmetry, just
+1;Recording often row statistical value, be added by the statistical value of all row after having added up all row, the total value obtained is exactly this x coordinate
Score;Such as, as shown in Figure 2 b, in the image of 19 × 19 pixels, when arranging as axis of symmetry with the pixel that x coordinate is 9,
Progressively scan, add up the group number of often row symmetrical pixels point, as long as with the presence of one group of symmetrical pixels point just to statistical value+1, note
The statistical value of 19 row of record, then using 19 statistical value sums as the score of the axis of symmetry that x coordinate is 9;
5.2 add up all 19 x coordinate columns as score during axis of symmetry according to the mode of above-mentioned steps 5.1, take wherein
Best result;The x coordinate of score maximum is axis of symmetry coordinate x=a;
6. the image after step 5 being processed carries out the continuous rotation that step-length is 0.5 °, rotates post processor every time and jumps into step 3,
Repeat step 3-5;Until terminating when having rotated 360 ° to rotate;
7. the best result in all x coordinate scores obtained added up in record every time after rotating, and the x coordinate of score maximum is symmetry
Axial coordinate x=a;
8. find the maximum in x coordinate best result under all anglecs of rotation, its corresponding image rotation angle, be this first
The angle that beginning image is to be corrected.
9. x=a described in step 7 be x coordinate point as rotate initial point, rotate image, the anglec of rotation is the rotation that step 8 determines
Gyration, completes the level correction of image.