Summary of the invention
The objective of the invention is to, solve existing inclination image rotation technique with element laterally or the variation that directly makes progress, can't try to achieve the technical problem at accurate angle of inclination.
Above-mentioned purpose of the present invention is achieved in that a kind of automatic tilt image correction method, wherein, comprises following steps:
Detect a plurality of frontier districts that have a border on the image;
Calculate respectively gradient direction angle and its weight of accumulative total of this frontier district; And
Rotate this image according to described gradient direction angle with highest weighting;
On behalf of the maximum in this frontier district, wherein said border show that difference value is greater than a limiting value.
Automatic tilt image correction method of the present invention, wherein, the decision of described frontier district is definite through the following steps:
Cutting this image is a plurality of squares districts, and respectively this square district comprises the N*N pixel, and N is the odd number beyond 1;
According to a plurality of angles this square district is divided into a plurality of pixel group;
Calculating each other demonstration difference value between adjacent two pixel groups under this angle respectively;
Determine that maximum demonstration difference value is greater than this limiting value; And
The square district that definition has this border is described frontier district.
Automatic tilt image correction method of the present invention, wherein, described each square district gets with the trunnion axis angle to become 0 °, 45 °, 90 ° to be partitioned into described respectively as number group with 135 ° of angles.
Automatic tilt image correction method of the present invention, wherein, the difference of the display parameters total value that described demonstration difference value is adjacent two these pixel groups.
Automatic tilt image correction method of the present invention, wherein, the display parameters total value of described pixel group comprises the summation of the display parameter value of pixel for it.
Automatic tilt image correction method of the present invention, wherein, described display parameter value is brightness value or chromatic value.
Automatic tilt image correction method of the present invention, wherein, described demonstration difference value is a luminance difference value or a colourity difference value.
Automatic tilt image correction method of the present invention wherein, when calculating described gradient direction angle, also comprises one and confirms that this gradient direction angle is positioned at the step of an angular range.
Automatic tilt image correction method of the present invention, wherein, described angular range is-89 ° to 89 °.
Automatic tilt image correction method of the present invention, wherein, described angular range is-45 ° to 45 °.
Automatic tilt image correction method of the present invention wherein, also comprises the step of exporting an information warning.
Automatic tilt image correction method of the present invention wherein, also comprises the step of adjusting this border, image rotation back.
Automatic tilt image correction method of the present invention, wherein, described gradient direction angle is to try to achieve by the Suo Beier operator.
In sum, a kind of automatic tilt image correction method provided by the invention, it comprises the following step: detect all frontier districts that have the border on the image; Calculate gradient direction angle and its weight of accumulative total of each frontier district; And, according to gradient direction angle image rotating with highest weighting.
Wherein the decision of frontier district also comprises following steps: the cutting image is a plurality of squares districts, and each square district comprises the N*N pixel; According to a plurality of angles this square district is divided into most pixel groups; Calculating each other demonstration difference value between pixel group adjacent two under each angle; Determine that maximum demonstration difference value is greater than limiting value; And the square district that definition has the border is the frontier district.
Owing to adopted the effect that aforesaid the present invention reached, be to go all pixels on the detecting image one by one with the square district that comprises the N*N pixel, find out and have the frontier district that the border exists, the accumulative total of weight is carried out at the gradient direction angle of calculating all frontier districts again, and the gradient direction angle of resultant like this highest weighting is the image angle of inclination of pinpoint accuracy.
Embodiment
Automatic tilt image correction method provided by the present invention, original conception is the image that scans that is applied to correct tilt, and this scans element on the image such as literal (Character), image (Picture), form (Table), at original record medium (Record Media is as paper) mainly is to become horizontal or straight to layout; In other words, if having laterally or directly when the homogeneity (Uniformity) of layout, can proofread and correct by this method as the element of inclination image.
As shown in Figure 1, the method mainly comprises following steps:
Step 110: at first detect all frontier districts that have the border on the image;
Step 120: gradient direction angle and its weight of accumulative total of calculating each frontier district then;
Step 130: last then according to gradient direction angle image rotating with highest weighting.
Then, each step is done further detailed must the explanation.
Step 110: detect all frontier districts that have the border on the image:
So-called border (Edge), be to represent that the maximum in the frontier district shows that difference value (DisplayDifference) is greater than a limiting value (Threshold), and show that difference value is to be preset as a brightness (Luminance) difference value or a colourity (Chrominance) difference value, limiting value is an empirical value, and is different with the machine of image capture unit.Wherein, as shown in Figure 2, the decision of frontier district is to determine by following steps,
Step 210: cutting this image is a plurality of squares districts, and each square district comprises the N*N pixel, and wherein N is the odd number beyond 1.With N=3 is example, and each square district (Block) comprises 9 pixels, as shown in Figure 3, gives the numbering of 1-9 earlier at this; Then represent the display parameter value of each pixel as for Z1-Z9, this display parameter value is predeterminable to be the brightness value or the chromatic value of each pixel;
Step 220: each square district is divided into a plurality of pixel group according to different angles.The angle that adopts is to get with the trunnion axis angle to become 0 °, 45 °, 90 ° and 135 ° of equal angles, distinguishes each as number group (PixelGroup).The pixel group that each angle is divided into comprises, pixel group 123,456,789 shown in Fig. 4 a 0 ° the time, shown in Fig. 4 b with the pixel group 124,357,689 of 45 ° of differentiations, shown in Fig. 4 c with the pixel group 147,258,369 of 90 ° of differentiations, with shown in Fig. 4 d with the pixel group 236,159,478 of 135 ° of differentiations.
Step 230: calculate in each other demonstration difference value between adjacent two pixel groups under each angle.Represent the display parameters total value with " Data ", then the display parameters total value is the summation of the display parameter value of all pixels in the pixel group, and is as follows with the formula tabular form:
a.0°:
Data123=Z1+Z2+Z3
Data456=Z4+Z5+Z6
Data789=Z7+Z8+Z9
b.45°:
Data124=Z1+Z2+Z4
Data357=Z3+Z5+Z7
Data689=Z6+Z8+Z9
c.90°:
Data147=Z1+Z4+Z7
Data258=Z2+Z5+Z8
Data369=Z3+Z6+Z9
d.135°:
Data236=Z2+Z3+Z6
Data159=Z1+Z5+Z9
Data478=Z4+Z7+Z8
Show difference value with " Diff " representative, show that then difference value is defined as the difference of the display parameters total value of adjacent two pixel groups, is expressed as follows (Abs represents absolute value) with formula:
a.0°:
Diff123_456=Abs(Data123-Data456)
Diff789_456=Abs(Data789-Data456)
b.45°:
Diff124_357=Abs(Data124-Data357)
Diff689_357=Abs(Data689-Data357)
c.90°:
Diff147_258=Abs(Data147-Data258)
Diff369_258=Abs(Data369-Data258)
d.135°:
Diff478_159=Abs(Data478-Data159)
Diff478_159=Abs(Data478-Data159)
Step 240: determine maximum demonstration difference value greater than limiting value, that is, according to previous definition, square has " border " in the district.Show that difference value is big more, represent between two neighbor groups on display effect such as brightness or colourity, to have significant difference; If this difference value greater than (or equaling) limiting value (for example 120, with brightness value), then is enough to the target as sampling.
Step 250: the square district that definition has the border is the frontier district, and the square district that is defined as the frontier district will be used to be further processed.
Step 120: gradient direction angle and its weight of accumulative total of calculating each frontier district:
The demonstration difference of each frontier district will be converted into gradient direction angle (Gradient Angle), its representative be all possible angle of inclination of image (Skew Angle).
The calculating at gradient direction angle can be tried to achieve by Suo Beier operator (Sobel Operator) Gx and Gy, and as shown in Figure 5, the calculating of the gradient direction angle A of frontier district can cooperate Fig. 3 to be expressed as follows with formula:
Gx=(Z7+2*Z8+Z9)-(Z1+2*Z2+Z3)
Gy=(Z3+2*Z6+Z9)-(Z1+2*Z4+Z7)
A=tan
-1(Gy/Gx)
Wherein A refers to the angle with trunnion axis, tan
-1Inverse function for trigonometric function tan.
By the accumulative total of each its weight of gradient direction angle (Weighting) that calculates, can find a gradient direction angle with weight limit, based on the homogeneity prerequisite of this method image element, this gradient direction angle is the angle of inclination of image.
Step 130: according to gradient direction angle image rotating with highest weighting:
The technology of image rotating to a special angle is known, and this method is characterised in that and can seeks out the angle of inclination accurately by the weight accumulative total at gradient direction angle.
Below describe in detail by a preferred embodiment.See also Fig. 6, can pick out one of them element on the image 300 very easily and be letter " B ", and letter " B " image 310 inclinations one angle.Carry out step 210,220 and distinguish in regular turn after square district, the pixel group, promptly carry out the calculating that step 230 shows difference value, present embodiment is to be foundation with the brightness value; With square district 311 is example, the brightness value of its each pixel, and promptly display parameter value is as shown in Figure 7, so the display parameters total value of each pixel group is calculated as follows:
0°:
Data123=83+60+53=196
Data456=137+73+51=261
Data789=200+141+86=427
45°:
Data124=83+60+137=280
Data689=51+141+86=278
Data357=53+73+200=326
90°:
Data147=83+137+200=420
Data258=60+73+141=274
Data369=53+51+86=190
135°:
Data478=137+200+141=478
Data159=83+73+86=242
Data236=60+53+51=164
Show the calculating of difference value:
0°:
Diff123_456=abs(Data123-Data456)=abs(196-261)=65
Diff789_456=abs(Data789-Data456)=abs(427-2610)=166
45°:
Diff124_357=abs(Data124-Data357)=abs(280-326)=46
Diff689_357=abs(Data689-Data357)=abs(278-326)=48
90°:
Diff147_258=abs(Data147-Data258)=abs(420-274)=146
Diff369_258=abs(Data369-Data258)=abs(190-274)=84
135°:
Diff478_159=abs(Data478-Data159)=abs(478-242)=236
Diff236_159=abs(Data236-Data159)=abs(164-242)=78
It is 236 that above-mentioned result of calculation can draw maximum demonstration difference value, is 120,236>120 so the square district is the frontier district with border as default limiting value.
And being calculated as follows of its gradient direction angle:
Gx=(Z7+2*Z8+Z9)-(Z1+2*Z2+Z3)
=(200+2*141+86)-(83+2*60+53)=312
Gy=(Z3+2*Z6+Z9)-(Z1+2*Z4+Z7)
=(53+2*51+86)-(83+2*137+200)=-316
A=tan
-1(Gy/Gx)=tan
-1(316/312)=-1 (radian)
Gradient direction angle A=-1* (180/ π) after converting=-45 °
Follow above-mentioned mode, find out frontier districts all on the image 300, and calculate its gradient direction angle and carry out after the weight accumulation, find that-45 ° have maximum weights, image rotating 300 according to this so just is as Fig. 8.
The angle of inclination that can try to achieve according to the present invention is in theory between-89 ° to 89 °, so approaching-89 ° or the 89 ° of normal angled that may represent image, therefore when the calculating at gradient direction angle, can increase by one and confirm that the gradient direction angle is positioned at the step of an angular range, this angular range is for being generally between-89 ° to 89 °, and the best is between-45 ° to 45 °.
And postrotational image 300 borders as shown in Figure 8 need be carried out the chamfered edge adjustment usually again, therefore can proceed a step of adjusting border, image rotation back after the rotation, with the result that image 300 is formed as Fig. 9.
When if this method is applied to scanning apparatus or photocopier, for avoiding image rotation, can excise the local edge of image when deburring is adjusted, perhaps, for keeping the integrality that scans image, this method still can increase the step of output one information warning, reminds the user to scan again.
The above only is preferred embodiment of the present invention, is not in order to limit scope of the invention process; Any personnel that have the knack of this type of technology not breaking away from the equalization variation of being done under spirit of the present invention and the scope and modification, all are covered by in the claim of the present invention.