Summary of the invention
At existing in prior technology shortcoming and restriction, the object of the present invention is to provide a kind of sub-pixel edge localization method that can improve the ellipse target of measuring system precision.
The present invention designs a kind of sub-pixel edge localization method of ellipse target, this method is at first used Sobel edge detection operator detected image edge, after extracting the ellipse target edge, with least square method the elliptical edge point is carried out match, obtain the geometric parameter of ellipse target, ask for the edge model parameter according to the principle of geometric parameter and image moment then, and then try to achieve accurate sub-pixel edge position.The present invention adopts following technical scheme:
A kind of sub-pixel edge localization method of ellipse target, its key step is:
The 1st step: image removed make an uproar, the Sobel operator edge detection, extract the marginal point of ellipse target then, the total count_pixel of record marginal point, and the coordinate of storage pixel edge point are expressed as (x
p, y
p), p=1,2,3 ... count_pixel;
The 2nd step: utilize the marginal point of the ellipse target of the 1st step extraction, ask for oval general equation x
2+ A
eXy+B
ey
2+ C
eX+D
eY+E
e=0 coefficient A
e, B
e, C
e, D
e, E
e, and then try to achieve oval centre coordinate (x
Co, y
Co) be:
Long axis of ellipse length is:
Oval minor axis length is:
The 3rd step: ellipse target is carried out the sub-pixel edge location, and concrete steps are as follows:
The 3.1st step: the target gray scale h that asks for ellipse target
1With background gray scale h
2, concrete steps are as follows:
The 3.1.1 step: choose center (x around at the ellipse target edge with the ellipse target of tentatively obtaining
Co, y
Co) be inside and outside two squares at center, interior square is contained by ellipse target, outer square contains ellipse target, the twice of the difference of the allowance that interior foursquare length of side length is ellipse target minor axis length and 2~3 pixels, outer foursquare length of side length is the twice of the allowance sum of ellipse target long axis length and 2~3 pixels;
The 3.1.2 step: write down the number of the image slices vegetarian refreshments on inside and outside square four length of sides, be expressed as count_inside, count_outside respectively, and the gray-scale value of the image slices vegetarian refreshments on inside and outside square four length of sides is stored in array ain respectively
i, i=1,2,3 ... count_inside and aout
j, j=1,2,3 ... among the count_outside;
The 3.1.3 step: respectively to array ain
i, aout
jBy the numerical values recited ordering, choose ain
iIn the average of N_inside element in the middle of being positioned at as target gray scale h
1, choose aout
jIn the average of N_outside element in the middle of being positioned at as h
2, wherein, N_inside is the result after 80% * count_inside rounds, N_outside is the result after 80% * count_outside rounds;
The 3.1.4 step: to the pixel edge point (x of ellipse target
p, y
p), if x
pX
Co, pixel edge point (x then
p, y
p) be positioned at the RHP of ellipse target, if x
p≤ x
Co, pixel edge point (x then
p, y
p) be positioned at the left half-plane of ellipse target; If the gray-scale value of ellipse target is bigger than background value gray scale, then the background gray scale and the target gray scale of ellipse target left side half-plane to be exchanged, the target gray scale and the background gray scale of ellipse target RHP then remain unchanged; If the gray-scale value of ellipse target is littler than background gray levels, then the background gray scale and the target gray scale of ellipse target RHP to be exchanged, the left half-plane target gray scale and the background gray scale of ellipse target then remain unchanged;
The 3.2nd step: to pixel edge point (x
p, y
p) ask for edge angle θ, computing formula is:
Wherein, A
e, B
e, C
e, D
e, E
eIt is the coefficient of the oval general equation that obtains in the 2nd step;
The 3.3rd step: ask for the spacing l of pixel edge point and true edge point, concrete steps are as follows:
The 3.3.1 step: according to real system precision and the selected template dimension N of rapidity
c, N
cBe 3,5 or 7, generate the zeroth order square template of corresponding dimension;
The 3.3.2 step: will be the N at center with the pixel edge point
c* N
cThe gray-scale value of neighborhood territory pixel and 3.3.1 in the step selected zeroth order square template carry out convolution, obtain zeroth order square numerical value M
00
The 3.3.3 step: ask for the area S in the edge model of place, oval background area
2, computing formula is:
Wherein, M
00Be the zeroth order square numerical value of asking in the 3.3.2 step, h
1, h
2Be respectively the target gray scale and the background gray scale of the 3.1st ellipse target asked for of step;
The 3.3.4 step: ask for variable β with look-up table according to following formula,
Wherein, S
2It is the area in place, the oval background area edge model of asking in the 3.3.3 step;
The 3.3.5 step: ask for the spacing l of true edge and pixel edge point, computing formula is:
l=cosβ
The 3.4th step: for pixel edge point (x
p, y
p), obtain the sub-pix coordinate (x at corresponding real image edge
Sub, y
Sub), computing formula is:
Wherein, N
cBe the template dimension of choosing, l is the true edge of asking in 3.3.5 step and the spacing of pixel edge point, and θ the 3.2nd goes on foot the edge angle of asking for;
The 3.5th step: each the pixel edge point to storage in the 1st step, repeat the operation of 3.1.4~3.4, the position of asking for all accurate sub-pixel edge points of this ellipse target.
Compared with prior art, the present invention has following advantage:
(1) compares with existing two dimensional image edge localization method based on square, the method of the sub-pixel edge location that the present invention proposes relies on geometric parameter, it is more accurate to obtain the edge model parameter, stable, make that final edge positioning result is more accurate, stable, concrete experiment and experimental data are as follows, wherein SGM (Spatial Gray Moment) method is the method based on space gray scale square, ZOM (Zernike Orthogonal Moment) method is the method based on quadrature Zernike square, and OFMM (Orthogonal Fournier-Mellin Moment) method is the method based on quadrature Fourier-Malin's square.
One, emulation experiment
Table 1 is the result after the present invention and additive method are handled the analogous diagram that comprises ellipse target, and SNR is a signal noise ratio (snr) of image; As can be known from the results, this paper method obtain precision and noiseproof feature is best.
Two, full-scale investigation
Adopt the present invention and additive method that one width of cloth pictorial diagram is carried out the location, edge respectively, primitive figure in kind and positioning result are as shown in Figure 1; Adopt the present invention and additive method that several pictorial diagram are carried out the location, edge respectively, the error of fitting of positioning result as shown in Figure 2; From the full-scale investigation result as can be known, error of fitting of the present invention is less than the error of fitting of additive method, and bearing accuracy is the highest, and stability is best.
Table 1 ellipse target sub-pixel edge positioning result is (unit: 0.01pixel) relatively
(2) method of the sub-pixel edge location of the present invention's proposition was obtained on the basis of marginal point in the thick step of Sobel boundary operator, the template number that participates in the image convolution computing is reduced one, reduced the operation time of algorithm widely, improved the rapidity of algorithm, table 2 be the several different methods convolution algorithm time ratio.
Table 2 algorithm time ratio
|
Add operation |
Multiply operation |
SGM (5 * 5 template) |
25×6×N
p |
25×6×N
p |
ZOM (5 * 5 template) |
25×3×N
p |
25×3×N
p |
OFMM (5 * 5 template) |
25×6×N
p |
25×6×N
p |
The present invention's (5 * 5 template) |
25×1×N
p |
25×1×N
p |
(3) the present invention inherited based on the sub-pixel edge localization method noiseproof feature of square good, the advantage that bearing accuracy is high,
Overcome its operation time of big shortcoming, had very strong practicality.
Embodiment
Embodiment 1
Below in conjunction with accompanying drawing the specific embodiment of the present invention is further described.The sub-pixel edge location that application this method is carried out ellipse target mainly comprises three operation stepss of geometric parameter and sub-pixel edge location that detect the ellipse target pixel edge, ask for ellipse, the process flow diagram of concrete steps is used the concrete steps following steps that this method is carried out the sub-pixel edge location of ellipse target as shown in Figure 3:
The 1st step: image removed make an uproar, the Sobel operator edge detection, extract the marginal point of ellipse target then, the total count_pixel of record marginal point, and the coordinate of storage pixel edge point are expressed as (x
p, y
p), p=1,2,3 ... count_pixel, wherein, the coordinate of this marginal point of pixel edge point expression is whole Pixel-level;
The 2nd step: utilize the marginal point of the ellipse target of the 1st step extraction, adopt the method for least square fitting marginal point to ask for oval general equation x
2+ A
eXy+B
ey
2+ C
eX+D
eY+E
e=0 coefficient A
e, B
e, C
e, D
e, E
e, when count_pixel marginal point carried out the least square ellipse fitting, its mean square deviation and be
About A
e, B
e, C
e, D
e, E
eRespectively following formula is got partial derivative, and make that each formula is zero, obtain a static determinacy system of equations that comprises 5 equations and 5 unknown numbers, try to achieve the coefficient A of oval general equation with methods such as matrix inversion or the cancellations of Gauss's pivot in a column
e, B
e, C
e, D
e, E
eAnd then try to achieve oval centre coordinate (x
Co, y
Co) be:
Long axis of ellipse length is:
Oval minor axis length is:
The 3rd step: Fig. 4 is two-dimentional edge model figure, h
1Be target gray value, h
2Be background gray levels, l is the normalization distance that actual edge is put initial point, and initial point is represented the pixel edge point of the ellipse target of extracting in the 1st step, and θ is the angle of edge normal direction and x axle,
S
1, S
2Represent background area and the target area area in edge model respectively; Ellipse target is carried out the sub-pixel edge location, and concrete steps are as follows:
The 3.1st step: the target gray scale h that asks for ellipse target
1With background gray scale h
2, concrete steps are as follows:
The 3.1.1 step: according to the intensity profile characteristic of ellipse target, choose pixel grey scale average on inside and outside two square limits around at the ellipse target edge as the target gray value and the background gray levels of ellipse target, wherein, inside and outside two foursquare choosing methods are: choose the center (x with the ellipse target of tentatively obtaining around at the ellipse target edge
Co, y
Co) be inside and outside two squares at center, interior square is contained by ellipse target, outer square contains ellipse target, the twice of the difference of the allowance that interior foursquare length of side length is ellipse target minor axis length and 2~3 pixels, outer foursquare length of side length is the twice of the allowance sum of ellipse target long axis length and 2~3 pixels, Fig. 5 is the inside and outside foursquare synoptic diagram of choosing, O is the initial point of entire image, elect the upper left corner of image as, two thick line squares are selected inside and outside square, and the center is the ellipse target center O
c, shortaxis, longaxis represent the minor axis length and the long axis length of ellipse target respectively, interior square length of side l
1With outer square length of side l
2Length satisfy:
c
1, c
2Be the allowance of choosing;
The 3.1.2 step: write down the number of the image slices vegetarian refreshments on inside and outside square four length of sides, be expressed as count_inside, count_outside respectively, and the gray-scale value of the image slices vegetarian refreshments on inside and outside square four length of sides is stored in array ain respectively
i, i=1,2,3 ... count_inside and aout
j, j=1,2,3 ... among the count_outside;
The 3.1.3 step: in order to eliminate The noise in the real image, at first respectively to array ain
i, aout
jBy the numerical values recited ordering, choose ain
iIn the average of N_inside element in the middle of being positioned at as target gray scale h
1, choose aout
jIn the average of N_outside element in the middle of being positioned at as h
2, wherein, N_inside is the result after 80% * count_inside rounds, N_outside is the result after 80% * count_outside rounds;
The 3.1.4 step: for the pixel edge point (x of ellipse target
p, y
p), if x
pX
Co, pixel edge point (x then
p, y
p) be positioned at the RHP of ellipse target, if x
p≤ x
Co, pixel edge point (x then
p, y
p) be positioned at the left half-plane of ellipse target; When edge model when the ellipse target edge moves, indicated background, the target gray scale of the above-mentioned target of asking for, background gray scale and edge model is inconsistent, in order to adapt to background, the target gray scale of edge model indication, need do following adjustment: if the gray-scale value of ellipse target is bigger than background value gray scale, then the background gray scale and the target gray scale of ellipse target left side half-plane are exchanged, the target gray scale and the background gray scale of ellipse target RHP then remain unchanged; If the gray-scale value of ellipse target is littler than background gray levels, then the background gray scale and the target gray scale of ellipse target RHP to be exchanged, the left half-plane target gray scale and the background gray scale of ellipse target then remain unchanged;
The 3.2nd step: utilizing the gradient direction of the edge pixel point of ellipse target is the character of the normal direction of this place elliptic curve, to pixel edge point (x
p, y
p) ask for edge angle θ, method is: according to geometric knowledge, marginal point (x
p, y
p) normal direction slope k _ grad be:
Wherein, A
e, B
e, C
e, D
e, E
eBe the oval general equation G that obtains in the 2nd step (x, y)=x
2+ A
eXy+B
ey
2+ C
eX+D
eY+E
e=0 coefficient;
This marginal point (x
p, y
p) the edge angle be:
The 3.3rd step: ask for the spacing l of pixel edge point and true edge point, concrete steps are as follows:
The 3.3.1 step:, need with its discrete N of being for the ideal edge model
c* N
cImage, wherein, N
cBe the dimension of template, N
cBe 3,5,7, the template dimension is high more, and precision is high more, but algorithm complex increases, therefore, and according to real system precision and the selected template dimension N of rapidity
cBecause four edge parameters have only one not find the solution as yet, only need a zeroth order square template just can obtain edge parameters l, therefore, according to selected N
c, generate the zeroth order square template of corresponding dimension, wherein, 3 * 3,5 * 5,7 * 7 zeroth order square templates are shown in table 3~table 5;
Table 33 * 3 zeroth order square templates
Table 45 * 5 zeroth order square templates
Table 57 * 7 zeroth order square templates
3.3.2 step: under discrete situation, square be calculated as related operation, therefore, will be the N at center with the pixel edge point
c* N
cThe gray-scale value of neighborhood territory pixel and 3.3.1 in the step selected zeroth order square template carry out convolution, obtain zeroth order square numerical value M
00
The 3.3.3 step: according to edge model figure, the zeroth order square computing formula of continuous two-dimentional edge model is:
M
00=∫∫f(x,y)dxdy=S
1h
1+S
2h
2
The edge model projection in a unit circle, is had:
S
1+S
2=π
Therefore, the area S in the edge model of place, oval background area
2Computing formula be:
Wherein, M
00Be the zeroth order square numerical value of asking in the 3.3.2 step, h
1, h
2Be respectively the target gray scale and the background gray scale of the 3.1st ellipse target asked for of step;
3.3.4 step: with edge model through turning clockwise θ, postrotational edge model vertical view as shown in Figure 6, O
pBe the pixel edge point, l is the spacing of pixel edge point and true edge point, and the shade arcuate region is represented the background area of ellipse target, and the friendship excircle is G
c, W
c, and O
pT
c⊥ G
cW
c, T
cOn excircle, shade arcuate region area is the S that asks in the 3.3.3 step
2, β is arc G
cT
cCorresponding central angle according to the simple geometric relation, has:
Following formula relates to nonlinear equation finds the solution, and in order to improve the algorithm rapidity, finds the solution variable β with look-up table;
The 3.3.5 step: as shown in Figure 6, the computing formula of the spacing l of true edge and pixel edge point is:
l=cosβ
The 3.4th step: according to edge model, for pixel edge point (x
p, y
p), the sub-pix coordinate (x at corresponding real image edge
Sub, y
Sub) be:
Consider the enlarge-effect of template, therefore, following formula is rewritten as:
Wherein, N
cBe the template dimension of choosing, l is the true edge of asking in 3.3.5 step and the spacing of pixel edge point, and θ the 3.2nd goes on foot the edge angle of asking for;
The 3.5th step: each the pixel edge point to storage in the 1st step, repeat the operation of 3.1.4~3.4, the position of asking for all accurate sub-pixel edge points of this ellipse target.
Embodiment 2
According to said method, adopt the present invention that the real image that as shown in Figure 7 a pair comprises ellipse target is carried out the sub-pixel edge location, idiographic flow is as follows:
The 1st step: image removed make an uproar, the Sobel operator edge detection, extract the marginal point of ellipse target then, the elliptical edge point after the extraction writes down the total count_pixel of marginal point as shown in Figure 8, at this moment, count_pixel=47; Store the coordinate of pixel edge point, be expressed as (x
p, y
p), p=1,2,3 ... count_pixel, wherein, the coordinate of this marginal point of pixel edge point expression is whole Pixel-level, the pixel edge point coordinate of storage is as shown in table 6;
The 2nd step: utilize the marginal point of the ellipse target of the 1st step extraction, adopt the method for least square fitting marginal point to ask for oval general equation x
2+ A
eXy+B
ey
2+ C
eX+D
eY+E
e=0 coefficient A
e, B
e, C
e, D
e, E
e, at this moment, A
e=-0.0841, B
e=0.7570, C
e=-80.7437, D
e=-72.2997, E
e=3470.1, and then try to achieve oval centre coordinate (x
Co, y
Co) be:
Long axis of ellipse length is:
Oval minor axis length is:
Table 6 pixel edge point coordinate (unit: pixel)
p |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
x
p |
35 |
36 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
y
p |
47 |
46 |
45 |
44 |
43 |
42 |
42 |
42 |
41 |
42 |
42 |
42 |
43 |
43 |
44 |
p |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
x
p |
48 |
49 |
49 |
50 |
50 |
50 |
50 |
50 |
50 |
49 |
49 |
48 |
47 |
46 |
45 |
y
p |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
58 |
p |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
x
p |
44 |
43 |
42 |
41 |
40 |
39 |
38 |
37 |
37 |
36 |
36 |
35 |
35 |
35 |
35 |
y
p |
59 |
59 |
59 |
58 |
58 |
58 |
57 |
56 |
55 |
54 |
53 |
52 |
51 |
50 |
49 |
p |
46 |
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
x
p |
35 |
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
y
p |
48 |
47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
The 3rd step: Fig. 4 is two-dimentional edge model figure, h
1Be target gray value, h
2Be background gray levels, l is the normalization distance that actual edge is put initial point, and initial point is represented the pixel edge point of the ellipse target of extracting in the 1st step, and θ is the angle of edge normal direction and x axle,
S
1, S
2Represent background area and the target area area in edge model respectively; Ellipse target is carried out the sub-pixel edge location, and concrete steps are as follows:
The 3.1st step: the target gray scale h that asks for ellipse target
1With background gray scale h
2, concrete steps are as follows:
The 3.1.1 step: according to the intensity profile characteristic of ellipse target, choose pixel grey scale average on inside and outside two square limits around at the ellipse target edge as the target gray value and the background gray levels of ellipse target, wherein, inside and outside two foursquare choosing methods are: choose the center (x with the ellipse target of tentatively obtaining around at the ellipse target edge
Co, y
Co) be inside and outside two squares at center, interior square is contained by ellipse target, outer square contains ellipse target, the twice of the difference of the allowance that interior foursquare length of side length is ellipse target minor axis length and 2~3 pixels, outer foursquare length of side length is the twice of the allowance sum of ellipse target long axis length and 2~3 pixels, and two white square are the inside and outside square of choosing among Fig. 9;
The 3.1.2 step: the number that writes down the image slices vegetarian refreshments on inside and outside square four length of sides, be expressed as count_inside, count_outside respectively, at this moment, count_inside=48, count_outside=88, and the gray-scale value of the image slices vegetarian refreshments on inside and outside square four length of sides is stored in array ain respectively
i, i=1,2,3 ... count_inside and aout
j, j=1,2,3 ... among the count_outside;
The 3.1.3 step: in order to eliminate The noise in the real image, at first respectively to array ain
i, aout
jBy the numerical values recited ordering, choose ain
iIn the average of N_inside element in the middle of being positioned at as target gray scale h
1, choose aout
jIn the average of N_outside element in the middle of being positioned at as h
2, wherein, N_inside is the result after 80% * count_inside rounds, N_outside is the result after 80% * count_outside rounds, at this moment, target gray scale h
1=120, background gray scale h
2=30, N_inside=38, N_outside=70;
The 3.1.4 step: for the pixel edge point (x of ellipse target
p, y
p), if x
pX
Co, pixel edge point (x then
p, y
p) be positioned at the RHP of ellipse target, if x
p≤ x
Co, pixel edge point (x then
p, y
p) be positioned at the left half-plane of ellipse target; When edge model when the ellipse target edge moves, indicated background, the target gray scale of the above-mentioned target of asking for, background gray scale and edge model is inconsistent, in order to adapt to background, the target gray scale of edge model indication, need do following adjustment: if the gray-scale value of ellipse target is bigger than background value gray scale, then the background gray scale and the target gray scale of ellipse target left side half-plane are exchanged, the target gray scale and the background gray scale of ellipse target RHP then remain unchanged; If the gray-scale value of ellipse target is littler than background gray levels, then the background gray scale and the target gray scale of ellipse target RHP to be exchanged, the left half-plane target gray scale and the background gray scale of ellipse target then remain unchanged;
The 3.2nd step: utilizing the gradient direction of the edge pixel point of ellipse target is the character of the normal direction of this place elliptic curve, to pixel edge point (x
p, y
p) ask for edge angle θ, method is: according to geometric knowledge, marginal point (x
p, y
p) normal direction slope k _ grad be:
Wherein, A
e, B
e, C
e, D
e, E
eBe the oval general equation G that obtains in the 2nd step (x, y)=x
2+ A
eXy+B
ey
2+ C
eX+D
eY+E
e=0 coefficient;
This marginal point (x
p, y
p) the edge angle be:
The 3.3rd step: ask for the spacing l of pixel edge point and true edge point, concrete steps are as follows:
The 3.3.1 step:, need with its discrete N of being for the ideal edge model
c* N
cImage, wherein, N
cBe the dimension of template, N
cBe 3,5,7, the template dimension is high more, and precision is high more, but algorithm complex increases, therefore, and according to real system precision and the selected template dimension N of rapidity
cIn this example, choose N
c=5,5 * 5 zeroth order square template is as shown in table 4;
3.3.2 step: under discrete situation, square be calculated as related operation, therefore, will be the N at center with the pixel edge point
c* N
cThe gray-scale value of neighborhood territory pixel and 3.3.1 in the step selected zeroth order square template carry out convolution, obtain zeroth order square numerical value M
00
The 3.3.3 step: according to edge model figure, the zeroth order square computing formula of continuous two-dimentional edge model is:
M
00=∫∫f(x,y)dxdy=S
1h
1+S
2h
2
The edge model projection in a unit circle, is had:
S
1+S
2=π
Therefore, the area S in the edge model of place, oval background area
2Computing formula be:
Wherein, M
00Be the zeroth order square numerical value of asking in the 3.3.2 step, h
1, h
2Be respectively the target gray scale and the background gray scale of the 3.1st ellipse target asked for of step;
3.3.4 step: with edge model through turning clockwise θ, postrotational edge model vertical view as shown in Figure 6, O
pBe the pixel edge point, l is the spacing of pixel edge point and true edge point, and the shade arcuate region is represented the background area of ellipse target, and the friendship excircle is G
c, W
c, and O
pT
c⊥ G
cW
c, T
cOn excircle, shade arcuate region area is the S that asks in the 3.3.3 step
2, β is arc G
cT
cCorresponding central angle according to the simple geometric relation, has:
Following formula relates to nonlinear equation finds the solution, and in order to improve the algorithm rapidity, finds the solution variable β with look-up table;
The 3.3.5 step: as shown in Figure 6, the computing formula of the spacing l of true edge and pixel edge point is:
l=cosβ
The 3.4th step: according to edge model, for pixel edge point (x
p, y
p), the sub-pix coordinate (x at corresponding real image edge
Sub, y
Sub) be:
Consider the enlarge-effect of template, therefore, following formula is rewritten as:
Wherein, N
cBe the template dimension of choosing, l is the true edge of asking in 3.3.5 step and the spacing of pixel edge point, and θ the 3.2nd goes on foot the edge angle of asking for;
The 3.5th step: each the pixel edge point to storage in the 1st step, repeat the operation of 3.1.4~3.4, the position of asking for all accurate sub-pixel edge points of this ellipse target, net result is as shown in figure 10.