Rapid edge-detection method based on way of fitting
Technical field
The invention belongs to sub-pix Image Edge-Detection field, be specifically related to a kind of rapid edge-detection method based on way of fitting.
Background technology
The essential characteristic of image is the edge, so-called edge refers to that its surrounding pixel gray scale has the set of those pixels of step variation or roof variation, the edge detection method of early application mostly is Pixel-level, the bearing accuracy of these methods is whole pixel, namely, can judge marginal position is in some pixels, but can't segment again in this pixel, yet along with industrial detection improving constantly the measuring accuracy requirement, the Pixel-level precision can not satisfy the requirement of actual detection, and subpixel method arises at the historic moment.
The edge detection method of existing sub-pixel can be summarized as three kinds: based on the method for square, based on the fitting process of least square method with based on the method for interpolation, its robustness of fitting process based on least square method is stronger, to insensitive for noise, therefore Edge detected is relatively accurate, but due to the nonlinear match computing of needs, so computing velocity is relatively slow, can't satisfy processing and the monitoring occasion of real-time detection.And based on the method for square or based on the method for interpolation, computing velocity both is all than comparatively fast, but these two kinds of detection methods are all more responsive to picture noise again, in the situation that picture noise is more, its accuracy of detection both all can be a greater impact.
More with the prior art that the present invention comparatively approaches, such as, " a kind of based on the improved sub-pix algorithm of subdivision of polynomial interpolation " [J] of Li Qingli etc. University of Science ﹠ Technology, Beijing's journal, 2003,25 (3): 280-283, the method is applied in the direction template that constructs on classical Sobel operator basis, gray level image is processed, obtain gradient image, then the gradient direction along object edge carries out polynomial interpolation sub-pix segmentation calculating on gradient image, object edge is carried out sub-pix accurately locate.Yet the method has been inherited the characteristic of method of interpolation to the picture noise sensitivity, in the situation that picture noise is more, its rim detection precision will be subject to severe jamming.
Wang Jianmins etc. are at " research of operator of spatial moment based edge detection " [J] optical technology .1999, No, 4,3-6.Proposed a kind of Sub-pixel Edge Detection based on spatial moment, can realize faster that sub-pixel edge detects.The basic model of the method is the step edge model, yet be subject to the effect of imaging noise in the actual imaging process, and edge model is strict step not often, but fuzzy, so the method easily is subject to the interference of noise, thereby affects the bearing accuracy at edge.
And for example, old waiting quietly at " research of fitting of a polynomial Sub-pixel Edge Detection fast " [J]. applied optics 2011,32 (1): introduced a kind of fast sub-picture element edge detection algorithm based on fitting of a polynomial in 91-95.DOI:10.3969/j.issn.1002-2082.2011.01.020, this algorithm is according to the intensity profile of image, use the edge of cubic polynomial fitted figure picture to realize sub-pixel positioning, thereby reach higher bearing accuracy.Although the method has also utilized fitting of a polynomial to eliminate noise, but the inner product operation that contains much complex in the computing formula that it provides, can cause solution procedure slower, so the solution procedure of this detection method is slower, can't adapts to the real-time rim detection that actual effect is had relatively high expectations.In addition, two-dimentional rim detection is to realize the main application means of sub-pixel edge location, and the method only limits to the discussion to the one dimension edge detection method, does not provide the method that how its one dimension detection method is applied on two-dimentional rim detection.
Sun Qiucheng etc. are at " a kind of edge detection method of sub-pixel precision " the journal .2009.10.35 of Beijing University of Technology (10), 1332-1337. proposed a kind of Sub-pixel Edge Detection based on Bezier edge fitting model, by match correction Bezier edge model, obtain the sub-pixel location of image border.This approximating method has robustness preferably to noise, has higher edge precision.But due to the analytic formula that does not have edge calculation, all need to carry out the match computing in each testing process, can cause the approximating method detection speed slower, especially when the method is applied to two-dimentional rim detection, need match Three-Dimensional Gray curved surface, because fitting function is too complicated, detection speed can be slower.
Summary of the invention
in order to solve in existing sub-pixel edge detection method, all relatively easily be subject to the interference of picture noise based on square or based on the method for interpolation, and existing match class methods are not because exist the analytic formula of edge calculation point, thereby cause all needing to carry out the match computing in each one dimension edge detection process, particularly need to carry out the surface fitting computing in two-dimentional rim detection, cause thus its calculating process complicated, find the solution speed slow, the technical matters that can't adapt to the higher two-dimentional rim detection of requirement of real-time, the invention provides a kind of rapid edge-detection method based on way of fitting.
The technical scheme that technical solution problem of the present invention is taked is as follows:
Rapid edge-detection method based on way of fitting comprises the steps:
Step 1: the whole pixel edge of image detects and the location: utilize the Canny edge detection operator to carry out rim detection to image, obtain coordinate and the gray scale of all whole pixel grids at place, image border;
Step 2: extract video in window: contain centered by marginate whole pixel grid so that step 1 is described, extract the square gray matrix A in a part of region, image border
M * m, namely video in window, comprise a bit of edge line to be detected in video in window;
Step 3: the processing that quantizes of video in window specifically comprises the following steps:
Step 3.1: take the center of the described video in window of step 2 as initial point, set up the xoy rectangular coordinate system, wherein transverse axis is the x axle, and the longitudinal axis is the y axle; The unit length of coordinate system is 1 pixel;
Step 3.2: establish that in video in window, the coordinate of each pixel grid central point in rectangular coordinate system as described in step 3.1 is (x, y), the gray-scale value of whole pixel grid is put corresponding gray-scale value as this, and add the Z axis Special composition three-dimensional coordinate system vertical with this plane right-angle coordinate in the primary plane rectangular coordinate system, Z axis represents the gray-scale value that pixel is corresponding, obtain thus about the discrete distributed function I (x, y) of gray-scale value with the coordinate points variation;
Step 3.3: this straight line is the normal at edge by coordinate origin and perpendicular to the straight line of edge line to be detected at one at the rectangular coordinate system graphic memory, and the angle that defines this edge normal and horizontal cross shaft is θ;
Step 4: determine the direction of edge normal, its concrete steps are:
Step 4.1: utilize the spatial moment computing formula, each rank spatial moment M corresponding to square window image inscribed circle that extracts in calculation procedure 3.1
pq:
The Continuous Gray Scale distribution function of f (x, y) presentation video pixel in formula (1), the exponent number of p and q representation space square is positive integer, r represents the radius of inscribed circle;
Step 4.2: with the described Continuous Gray Scale distribution function of step 4.1 f (x, y) rotation θ as described in step 3.3 angle centered by the described Z axis of step 3.2, can obtain new Continuous Gray Scale distribution function in video in window, the numerical value of each rank spatial moment that the video in window inscribed circle is corresponding at this moment changes;
Step 4.3: theoretical according to the spatial moment rotational invariance, obtain rotating spatial moment M' corresponding to rear inscribed circle
pqWith not the rotation before spatial moment M
pqRelation as follows:
I represents from 0 to p integer, s represents from 0 to q integer, as Continuous Gray Scale distribution function f (x, y) behind rotation θ angle, edge line to be detected in video in window is vertical with the described coordinate system transverse axis of step 3.1 x, namely rotate gray scale function corresponding to rear hatch image inscribed circle symmetrical about transverse axis x, according to the spatial moment computing formula as can be known, spatial moment M' corresponding to rotation rear hatch image inscribed circle
01=0, this moment p=0, q=1, utilize formula (2) to obtain:
M'
01=-sinθ·M
10+cosθ·M
01=0……(3)
M wherein
10And M
01Spatial moment corresponding to inscribed circle before expression is not rotated;
Step 4.4: utilize the spatial moment calculation template to replace formula (1), and the discrete gray scale function I (x, y) of pixel in the video in window inscribed circle is updated in above-mentioned discrete template formula, with the spatial moment M in calculating formula (3)
01And M
10Value;
Step 4.5: obtain formula (4) according to formula (3), the spatial moment M that step 4.4 is obtained
01And M
10Value substitution formula (4), try to achieve the value at θ angle:
Step 4.6: establishing the edge normal is new horizontal cross shaft X, with the θ angle in step 4.5 as projected angle, on the pixel coordinate (x, y) of the described have a few of step 3.2 in pixel planes and normal place, edge transverse axis, there is following projection formula in point coordinate X:
X=xcosθ+ysinθ……(5)
After in formula (5), being projected in X value representation video in window pressed projected angle θ projection, the coordinate readings value of corresponding subpoint on the described new transverse axis X of step 4.6;
Step 5: based on the one dimension endpoint detections of way of fitting, determine the position of intersecting point of edge normal and edge line to be detected, it comprises the steps:
Step 5.1: the described Z axis of step 3.2 and the described horizontal cross shaft X of step 4.6 are reconstituted the plane right-angle coordinate XOZ that the one dimension endpoint detections is required, i.e. a projection plane;
According to projection formula (5), the central point of each pixel grid in video in window is projected on the described horizontal cross shaft X of step 4.6; In plane right-angle coordinate XOZ, obtain the discrete distributed function (X of edge normal upslide shadow point gray-scale value
i, Z
i), i=1 ..., 2n+1;
Step 5.2: the normalization of subpoint coordinate, if the subpoint number that forms as upper in transverse axis X as described in step 5.1 is 2n+1, establish
And order
X is arranged
i∈ [1,1];
Step 5.3: calculate system of orthogonal polynomials, utilize schemite orthogonalization method calculating system of orthogonal polynomials about weight function ρ (x)=1 on [1,1] interval;
Step 5.4: get the front quadravalence orthogonal basis function in step 5.3
Carry out way of fitting with formula (7) three times as the match substrate, the equation of polynomial fitting is:
Coefficient { a of the polynomial fitting in formula (8)
1, a
2, a
3, a
4It is fitting parameter to be asked;
Step 5.5: utilize formula (8) can derive normal equation group corresponding to the equation of polynomial fitting as follows:
In formula (9)
Represent discrete vector
With the inner product of self, Z=[Z
1, Z
2..., Z
2n+1]
TDiscrete gray-scale value vector,
The expression Z with
Inner product;
Step 5.6: utilize system of equations formula (9) to draw the coefficient { a of polynomial fitting
1, a
2, a
3, a
4Computing formula:
With each known quantity substitution formula (10), get respectively a
0, a
1, a
2And a
3Result;
Step 5.7: as known quantity substitution formula (8), the polynomial fitting equation becomes with the result of the described polynomial fitting of step 5.6:
Step 5.8: the second derivative of calculating cubic polynomial formula (11) is zero point, that is:
Find the solution and obtain the above-mentioned second derivative that makes formula (12) and be the coordinate of zero point;
Step 5.9: find the solution formula (12) and with the result of calculation renormalization, obtain the position coordinates R of one dimension marginal point on transverse axis X, that is:
Formula (13) is the analytic formula of Computing One-Dimensional edge point position, and this marginal point is the intersection point of edge normal and edge line to be detected;
Step 6: utilize formula (13) to determine to cross in video in window the position of intersecting point of initial point edge normal and edge line to be detected, utilize step 4.5 to obtain the deflection θ of edge normal, determine edge line to be detected equation in the xoy coordinate system, thereby realize the sub-pixel positioning of edge line to be detected in video in window;
Step 7: reselect the described whole pixel grid of step 1 by the operator, and repeat step 2 to step 6, to obtain the sub-pixel positioning of edge line to be detected in the video in window of newly obtaining;
Step 8: when the operator judge completed entire image on during the sub-pixel positioning of required marginal position, detection method finishes.
The invention has the beneficial effects as follows: rapid edge-detection method of the present invention can directly apply to two-dimentional rim detection, the method is all utilized the projecting direction of spatial moment edge calculation at every turn when video in window being quantized processing, and in conjunction with projection formula, two-dimentional rim detection is converted into the one dimension rim detection, avoided all repeating the required complex calculation of match gray surface in each one dimension edge detection process.Use way of fitting to obtain the analytic formula of Computing One-Dimensional edge point position, the method that has effectively overcome match can not obtain the difficult problem of analytic solution usually, this analytic formula form is simple, containing less inner product calculates, final in conjunction with detecting edge point position and the edge normal direction that obtains, determine the position of edge line in video in window.The method has significantly improved arithmetic speed, can adapt to the higher two-dimentional edge detection process of requirement of real-time, also had both based on the method for square or method of interpolation fast operation and fitting process the insensitive characteristic of picture noise, can significantly improve precision and the speed of rim detection.
Description of drawings
Fig. 1 is the rapid edge-detection method flow diagram that the present invention is based on way of fitting;
Fig. 2 is the process flow diagram of step 3 of the present invention;
Fig. 3 is the process flow diagram of step 4 of the present invention;
Fig. 4 is the process flow diagram of step 5 of the present invention;
Fig. 5 be on video in window of the present invention pixel by the application schematic diagram of projected angle θ to the transverse axis X projection of normal place, edge.
Embodiment
Below in conjunction with accompanying drawing, the present invention is described in further details.
As shown in Figure 1, the rapid edge-detection method that the present invention is based on way of fitting comprises the steps:
Step 1: the whole pixel edge of image detects and the location: utilize the Canny edge detection operator to carry out rim detection to image, obtain coordinate and the gray scale of all whole pixel grids at place, image border, thus edge to be detected cardinal principle orientation and scope in the pixel coordinate plane in positioning image.
Step 2: extract video in window: contain centered by marginate whole pixel grid so that step 1 is described, extract the square gray matrix A in a part of region, image border
M * m, namely video in window 2.The interior edge to be detected of video in window 2 can be similar to and regard a bit of straight line as under the microcosmic level.As shown in Figure 5, in the present embodiment, as video in window 2, extract the square-shaped image that contains a bit of edge line to be detected 1 with 5 * 5 formed image-regions of whole pixel grid from image.
Step 3: the processing that quantizes of video in window 2 specifically comprises following substep as shown in Figure 2:
Step 3.1: as shown in Figure 5, take the center of the described video in window 2 of step 2 as initial point, set up the xoy rectangular coordinate system, wherein transverse axis is the x axle, and the longitudinal axis is the y axle.The unit length of coordinate system is 1 pixel, and so by step 1 as can be known, edge to be detected is arranged in this coordinate system.
Step 3.2: as shown in Figure 5, if in video in window 2, the coordinate of each pixel grid central point in rectangular coordinate system as described in step 3.1 is (x, y), the gray-scale value of whole pixel grid is put corresponding gray-scale value as this, and add Z axis in former xoy plane right-angle coordinate, gray-scale value corresponding to expression pixel obtains the discrete distributed function I (x, y) that changes with coordinate points about gray-scale value thus.
Step 3.3: as shown in Figure 5, this straight line is the normal at edge by coordinate origin o and perpendicular to the straight line at edge to be detected at one at xoy rectangular coordinate system graphic memory, and the angle that defines this edge normal 3 and horizontal cross shaft is θ.
Step 4: determine edge normal 3 directions, it specifically comprises following substep as shown in Figure 3:
Step 4.1: utilize the spatial moment computing formula, each rank spatial moment M corresponding to square window image 2 inscribed circles that extracts in can calculation procedure 3.1
pq:
The continuous distribution function of f (x, y) presentation video pixel grey scale in formula (1), positive integer p and q be the exponent number of representation space square respectively, and r represents the radius of inscribed circle.
Step 4.2: with the described Continuous Gray Scale distribution function of step 4.1 f (x, y) rotation θ as described in step 3.3 angle centered by the described Z axis of step 3.2, obtain new Continuous Gray Scale distribution function in the interior meeting of video in window 2, the numerical value of each rank spatial moment that video in window 2 inscribed circles are corresponding at this moment changes.
Step 4.3: theoretical according to the spatial moment rotational invariance, can obtain rotating spatial moment M' corresponding to rear inscribed circle
pqWith not the rotation before square M
pqRelation as follows:
I represents from 0 to p integer, s represents from 0 to q integer, as Continuous Gray Scale distribution function f (x, y) behind rotation θ angle as shown in Figure 5, edge line to be detected 1 in video in window 2 is vertical with the described coordinate system transverse axis of step 3.1 x, namely rotate gray scale function corresponding to rear hatch image 2 inscribed circles symmetrical about transverse axis x, according to the spatial moment computing formula as can be known, spatial moment M' corresponding to rotation rear hatch image 2 inscribed circles
01=0, this moment p=0, q=1, utilize formula (2) to obtain:
M'
01=-sinθ·M
10+cosθ·M
01=0……(3)
M wherein
10, (p=1, q=0) and M
01, spatial moment corresponding to inscribed circle before (p=0, q=1) expression is not rotated.
Step 4.4: due to the grey scale pixel value I (x in video in window, y) be discrete, namely there is not continuous gray scale function f (x, y), therefore utilize the spatial moment calculation template to replace formula (1), and the discrete gray-scale value I (x, y) of pixel in the video in window inscribed circle is updated in above-mentioned spatial moment calculation template formula, with the spatial moment M in calculating formula (3)
01And M
10Value.Described spatial moment calculation template is by LyversEP, Mitchell OR. is at its works Precisionedgecontrastandorientationestimation[J], IEEETrans.PatternAnal.Mach.Intell, 1988,10 (6): 927-937.[1] the spatial moment calculation template that provides in.
Step 4.5: obtain formula (4) according to formula (3), the spatial moment M that step 4.4 is obtained
01And M
10Value substitution formula (4), try to achieve the value at θ angle:
After the θ angle was tried to achieve, the position of as described in step 3.3 edge normal 3 in the xoy coordinate system just was determined, and become known quantity.
Step 4.6: as shown in Figure 5, if edge normal 3 is new horizontal cross shaft X, as projected angle, on the pixel coordinate (x, y) of the described have a few of step 3.2 in pixel planes and edge normal 3 place transverse axis, there is following projection formula in point coordinate X with the θ angle in step 4.5:
X=xcosθ+ysinθ……(5)
After in formula (5), being projected in X value representation video in window 2 pressed projected angle θ projection, the coordinate readings value of corresponding subpoint 4 on the described new transverse axis X of step 4.6.Due on this projecting direction, Continuous Gray Scale distribution function f (x, y) does not change, and the gray-scale value of putting on therefore new transverse axis is identical with corresponding subpoint gray-scale value 5.
Pass through step 4, pixel in two-dimentional sample window all can be projected on the edge normal of video in window matrix initial point, and then should two dimension rim detection problem change one dimension rim detection problem into, and then utilize following steps can locate and obtain the position of edge line.
Step 5: carry out the one dimension endpoint detections based on way of fitting, to determine the position of intersecting point of edge normal 3 and edge line 1 to be detected, it comprises following substep as shown in Figure 4:
Step 5.1: as shown in Figure 5, the described Z axis of step 3.2 and the described horizontal cross shaft X of step 4.6 are reconstituted a plane right-angle coordinate XOZ that the one dimension endpoint detections is required, it is projection plane 6, new XOZ coordinate system is the one-dimensional plane coordinate system, its XOZ initial point overlaps with former xoy coordinate origin position, therefore, the coordinate of subpoint 4 is (X, Z) in new coordinate.
According to projection formula (5), the central point of each pixel grid in video in window 2 is projected on the described horizontal cross shaft X of step 4.6, owing to being identical along gray-scale value corresponding to the pixel of projecting direction θ in video in window, therefore the gray-scale value of subpoint be projected a little identical, therefore in plane right-angle coordinate XOZ, can obtain the discrete distribution function (X of projection image's vegetarian refreshments gray-scale value 5 on edge normal 3
i, Z
i), i=1 ..., 2n+1.
Step 5.2: the normalization of subpoint coordinate, if the number of the subpoint 4 on transverse axis X as described in step 5.1 is 2n+1, according to the symmetry of square matrix projection, above-mentioned subpoint 4 X both sides on transverse axis are symmetrical.If establish
And order
X is arranged
i∈ [1,1] is [1,1] with regard to making subpoint in the scope of X-axis like this.
Step 5.3: calculate system of orthogonal polynomials, utilize the schemite orthogonalization method to calculate on [1,1] interval about the system of orthogonal polynomials of weight function ρ (x)=1, described system of polynomials is as follows:
Step 5.4: get the front quadravalence orthogonal basis function in step 5.3
Carry out way of fitting with formula (7) three times as the match substrate, the equation of polynomial fitting is
Coefficient { a of the polynomial fitting in formula (8)
1, a
2, a
3, a
4It is fitting parameter to be asked.
Step 5.5: according to the property of orthogonality of least square fitting principle and orthogonal polynomial, utilize formula (8) can derive normal equation group corresponding to the equation of polynomial fitting as follows:
In formula (9)
Represent discrete vector
With the inner product of self, Z=[Z
1, Z
2..., Z
2n+1]
TDiscrete gray-scale value vector,
The expression Z with
Inner product.
Step 5.6: utilize system of equations formula (9) can draw the coefficient { a of polynomial fitting
1, a
2, a
3, a
4Computing formula:
With each known quantity substitution formula (10), get respectively a
0, a
1, a
2And a
3Result.
Step 5.7: as known quantity substitution formula (8), the polynomial fitting equation becomes with the result of the described polynomial fitting of step 5.6:
Step 5.8: because formula (11) is cubic polynomial, therefore having unique second derivative is zero point, and the second derivative of calculating cubic polynomial formula (11) is zero point, that is:
Find the solution and obtain the above-mentioned second derivative that makes formula (12) and be the coordinate of zero point.
Step 5.9: find the solution formula (12) and with the result of calculation renormalization, can obtain the position coordinates R on transverse axis X of one dimension marginal point, that is:
Formula (13) is the analytic formula of Computing One-Dimensional edge point position, and this marginal point is the intersection point of edge normal 3 and edge line 1 to be detected.
By the described method of step 5, we just can be by the position of this formula edge calculation point on X-axis, the namely position of intersecting point of edge line and normal.
Step 6: utilize formula (13) to determine the interior position of intersecting point of crossing initial point edge normal 3 and edge line 1 to be detected of video in window 2, utilize step 4.5 to obtain the deflection θ of edge normal 3, determine the equation of edge line to be detected 1 in the xoy coordinate system, thereby realize the sub-pixel positioning of edge line 1 to be detected in video in window 2;
Step 7: reselect the described whole pixel grid of step 1 by the operator, and repeat step 2 to step 6, to obtain the sub-pixel positioning of edge line 1 to be detected in the video in window 2 of newly obtaining;
Step 8: when the operator judge completed entire image on during the sub-pixel positioning of required marginal position, detection method finishes.
the rapid edge-detection method that the present invention is based on way of fitting can directly apply to two-dimentional rim detection, unchangeability when it utilizes the spatial moment rotation obtains the projecting direction θ at edge, and draw projection formula, thereby the pixel in video in window and corresponding gray-scale value thereof are all projected to take the edge normal as transverse axis by this projection formula, in plane take gray scale as the longitudinal axis, and then two-dimentional rim detection problem is converted into one dimension rim detection problem, by obtain edge normal in video in window and the intersecting point coordinate position at edge based on the one dimension edge detection method of way of fitting, final combination detects and obtains edge normal direction θ, determine the position of edge line in video in window.
Detection method of the present invention is in processing procedure that each video in window is quantized, utilize spatial moment theoretical, at first calculate the projecting direction θ at edge, in conjunction with projection formula, two-dimentional rim detection problem is converted into one dimension rim detection problem, has avoided all repeating the required complex calculation of match gray surface in each one dimension edge detection process.Theoretical according to way of fitting, can obtain the analytic formula of Computing One-Dimensional edge point position, the method that has effectively overcome match can not obtain the difficult problem of analytic solution usually, the gray-scale value that utilizes this analytic formula only need to bring marginal position into can obtain the analytic solution of relevant edge point position very easily, because the analytic formula form is simple, contain less inner product and calculate, significantly improved arithmetic speed, thereby can adapt to the real-time working condition edge detection process that actual effect is had relatively high expectations.
In addition, detection method of the present invention has merged well based on square and based on two kinds of sub-pix detection methods of fitting process, not only inherited based on the method for square or the characteristic of method of interpolation fast operation, more had fitting process concurrently to the insensitive advantage of picture noise, picture noise be can reduce preferably on interference and the impact of result, thereby precision and the speed of rim detection significantly improved.