AbstractIn image edge detection, the detected edge is often closed. In this paper, we analyze two common algorithms: The Harf transform and the Canny edge detection algorithm. Finally, discuss the criteria that edge operators should satisfy.
KeywordsEdge detection, closed, Harf transformation, and Canny operator
1 IntroductionThe edge of an image refers to the area with significant brightness changes. The gray profile of the area is generally considered as a step, the gray value changes sharply from a very small buffer area to another gray value with a large difference. The edge part of the image concentrates most of the information of the image. the identification and extraction of the image edge is very important for the identification and understanding of the entire image scenario. It is also an important feature of image segmentation, edge Detection mainly measures, detects, and locates the gray-scale changes of images. After more than 50 years of development since edge detection was proposed in 1959, many different edge detection methods exist. In some of our commonly used edge detection operators, Laplace operators often generate dual boundaries, while other operators such as Sobel operators often form non-closed areas. This article mainly discusses algorithms for obtaining Closed Boundary Areas in edge detection.
2 basic steps of image edge detection(1) filter. Edge detection is mainly based on derivative calculation, but is affected by noise. However, when the filter reduces noise, it also causes loss of edge strength. (2) enhancement. The enhancement algorithm highlights vertices with significant gray changes in the neighborhood. Generally, the gradient amplitude is calculated. (3) detection. However, in some images, the gradient amplitude is not the edge point. The simplest edge detection method is the gradient amplitude threshold determination. (4) positioning. Precisely determine the edge position.
Figure 1 basic steps of the edge detection Acid Method
3. Boundary closed Algorithms
3.1 Harf transformation [3]Due to the existence of noise, edge pixels obtained by various operators are not consecutive, but due to the continuity between edge pixels, we can connect edge pixels based on their continuity in the gradient amplitude or gradient direction. Specifically, if pixels (S, T) are in the pixel (x, y) field and their gradient amplitude and gradient direction meet the given threshold: T is the amplitude threshold; A is the angle threshold;
Then, if the above judgment and connection are performed on all edge pixels, a closed boundary can be obtained. The Harf transform method directly detects the target contour based on the global characteristics of the image, the Harf transformation can accurately capture the target boundary (Continuous Acquisition of discontinuous), and finally output the transformation result in the form of a continuous curve, this transform accurately separates known shapes from targets in a strong noise environment. The core idea of Harf's transformation is duality ). After converting an image from an image control to a parameter space, the linear equation of an over point (x, y) in the image space is y = px + Q, it can be converted to another form through algebraic transformation, P =-px + Y, that is, a straight line of point passing (p, q) in the parameter space, if the slope and intercept of a straight line remain unchanged in the image space, the parameter space must be over (p, q), which means that, in the image space, the points of the common line correspond to the line of the common points in the parameter space. the Harf transformation is to convert the linear detection problem in the image space into the point detection problem in the parameter space based on the parity of the above-mentioned point-line, the processing of the latter is much easier than that of the former, and edge detection can be achieved by simply accumulating statistics. the Harf transform not only detects the target of the first-order Curve such as a straight line, but also can detect the higher-order curves such as the garden and the ellipse. For example, the equation of the circle is:
The parameter space is a 3D space a (a, B, r). The principle is the same as that of vertices on the detection line, but the complexity increases. If the radius R of the circle is unknown, the problem returns to the 2D space a (A, B) the Harf transformation has little impact on the detection process of known targets due to adverse factors such as random noise and curve interruption, and the split goal is to directly put it in another "clean" cache, therefore, it is quite advantageous to achieve zero noise. In theory, the conventional Harf transformation can perform Target Detection on all curves that can write specific parsing expressions. However, in actual processing, the targets to be detected are irregular, difficult to obtain, or even have no analytical expression at all. In this case, the target should be detected through the Harf transformation in a broad sense,
3.2 optimal tiered edge detection algorithm (Canny edge detection)1. Basic principles of edge detection (1) image edge detection must meet two conditions: one can effectively suppress noise, and the other must be as accurate as possible to determine the edge position. (2) Measure the signal-to-noise ratio and positioning product to obtain the optimal approximation operator. This is the edge detection operator. (3) similar to the MARR (log) edge detection method, it is also a method for smoothing first and then obtaining the derivative. 2. edge moderation algorithm: Step 1: Use a Gaussian filter to smooth the image; Step 2: Use a first-order partial derivative finite difference to calculate the gradient amplitude and direction; Step 3: non-maximum gradient amplitude suppression; Step 4: Use a dual-threshold algorithm to detect and connect edge. Step 1: Gaussian smoothing function Step 3: only the global gradient obtained by non-maximum suppression is not enough to determine the edge. Therefore, to determine the edge, the vertex with the largest partial gradient must be retained, rather than the maximum value. (Non-maxima suppression, NMs) solution: Use the gradient direction. Figure 2 Non-maximum values suppress the numbers of the four slices from 0 to 3, corresponding to four possible combinations in the 3*3 neighborhood. At each point, the center pixel m in the neighborhood is compared with the two pixels along the gradient line. If the gradient value of M is not greater than the gradient value of two adjacent pixels along the ladder, m = 0. That is: Step 4: Use a threshold value for N [I, j] to reduce the number of false edge segments. Assign zero values to all values below the threshold. But the question is how to select the threshold? Solution: double threshold algorithm. The dual-threshold algorithm is used to suppress non-maximum values of an image. The two thresholds are Tau 1 and Tau 2, and the two thresholds are Tau 1 ≈ Tau 2, so that the two threshold edge images N1 [I, j] and N2 [I, j]. Since N2 [I, j] is obtained using a high threshold value, it contains very few False edges, but there are disconnections (not closed ). The Dual Threshold Method connects the edge to the contour in N2 [I, j]. When the contour endpoint is reached, the algorithm is in N1 [I, j] is used to find the edge that can be connected to the contour. In this way, the algorithm constantly collects the edge in N1 [I, j] Until N2 [I, j] until the connection is established.
4. Principles to be met by edge OperatorsIf this rule is met, only one response is returned at a single edge. The performance evaluation of an algorithm can be divided into two stages: Calculation of the number of False edges and the number of lost edges; measurement is used to estimate the error (or error distribution) of the location and direction ). The advantages and disadvantages of edge detection algorithms can also be described by figure of merit. Pratt quality factor is one of them. It focuses on three kinds of errors, including loss of valid edge, edge positioning error, and determination of noise as edge.
5 conclusionEdge Detection plays an important role in image segmentation, pattern recognition, and machine vision. Many edge detection algorithms have been developed, the Harf transform and the Canny edge operator are the most classic algorithms. Some new improved algorithms have been proposed based on these classical algorithms.
References[1] Jia yunde. Machine Vision [M]. Beijing: Science Press, 2000
[2] Chapter Jin. image processing and analysis [M]. Beijing: Tsinghua University Press, 1999 [3] Lang Rui. Digital Image Processing. Beijing: Hope electronics Publishing House, 2002
[4] Wang Na, Li Xia. A new improved Canny edge detection algorithm. Journal of Shenzhen University, (2), 149-152, with the source code of the Canny operator // The Code
Void creatgauss (double Sigma, double ** pdkernel, int * pnwidowsize );
Void gaussiansmooth (size SZ, lpbyte pgray, lpbyte presult, double sigma );
Void Grad (size SZ, lpbyte pgray, int * pgradx, int * pgrady, int * pmag );
Void nonmaxsuppress (int * pmag, int * pgradx, int * pgrady, size SZ, lpbyte pnsrst );
Void estimatethreshold (int * pmag, size SZ, int * pthrhigh, int * pthrlow, lpbyte pgray, double drathigh, double dratlow );
Void hysteresis (int * pmag, size SZ, double dratlow, double drathigh, lpbyte presult );
Void traceedge (INT y, int X, int nthrlow, lpbyte presult, int * pmag, size sz );
Void canny (lpbyte pgray, size SZ, double Sigma, double dratlow, double drathigh, lpbyte presult); # include "afx. H"
# Include "math. H"
# Include "canny. H" // One-dimensional Gaussian distribution function, used for smoothing the Gaussian filter coefficient generated in the function
Void creatgauss (double Sigma, double ** pdkernel, int * pnwidowsize)
{Long I; // array center point
Int ncenter; // The distance from one point to the center of the array
Double DDIs; // intermediate variable
Double dvalue;
Double dsum;
Dsum = 0; // The data within [-3 * Sigma, 3 * Sigma] will overwrite the vast majority of the filter coefficients.
* Pnwidowsize = 1 + 2 * Ceil (3 * sigma );
Ncenter = (* pnwidowsize)/2;
* Pdkernel = new double [* pnwidowsize]; // generates Gaussian data
For (I = 0; I <(* pnwidowsize); I ++)
{
DDIs = double (I-ncenter );
Dvalue = exp (-(1/2) * DDIs/(Sigma * sigma)/(SQRT (2*3.1415926) * sigma );
(* Pdkernel) [I] = dvalue;
Dsum + = dvalue;
} // Normalization
For (I = 0; I <(* pnwidowsize); I ++)
{
(* Pdkernel) [I]/= dsum;
}}
// Use a Gaussian filter to smooth the original image void gaussiansmooth (size SZ, lpbyte pgray, lpbyte presult, double sigma)
{
Long X, Y; long I; // Gaussian filter Length
Int nwindowsize; // Window Length
Int nlen; // One-dimensional Gaussian filter
Double * pdkernel; // Gaussian coefficient and point multiplication of image data
Double ddotmul; // The sum of the filter coefficients.
Double dweightsum;
Double * pdtemp;
Pdtemp = new double [Sz. CX * Sz. Cy]; // generates one-dimensional Gaussian data.
Creatgauss (Sigma, & pdkernel, & nwindowsize );
Nlen = nwindowsize/2; // X direction Filter
For (y = 0; y = 0 & (I + x) = 0 & (I + Y) <Sz. Cy)
{Ddotmul + = (double) pdtemp [(Y + I) * Sz. cx + x] * pdkernel [nlen + I];
Dweightsum + = pdkernel [nlen + I];
}
}
Presult [y * Sz. cx + x] = (unsigned char) ddotmul/dweightsum;
}
}
Delete [] pdkernel;
Pdkernel = NULL;
Delete [] pdtemp;
Pdtemp = NULL;
}
// Derivative of the direction to obtain the gradient
Void Grad (size SZ, lpbyte pgray, int * pgradx, int * pgrady, int * pmag)
{Long y, X; // the derivative of the Direction X.
For (y = 1; y ABS (Gx ))
{// Calculate the interpolation Ratio
Weight = FABS (Gx)/FABS (Gy );
G2 = pmag [nPos-sz.cx];
G4 = pmag [NPOs + Sz. CX]; // If the symbols of the two direction derivatives of X and Y are the same // C is the current pixel, and the position of the g1-g4 is: // G1 G2 // C/G4 G3
If (Gx * Gy> 0)
{
G1 = pmag [nPos-sz.cx-1];
G3 = pmag [NPOs + Sz. cx + 1];} // if the direction of the two directions of X and Y is the opposite of the direction of the derivative // C is the current pixel, the relationship with the g1-g4 is: // G2 G1 // C // G3 G4
Else
{
G1 = pmag[ nPos-sz.cx + 1];
G3 = pmag [NPOs + Sz. cx-1];
}
} // If the X component of the direction derivative is greater than the Y component, it indicates that the direction of the derivative tends to be X component.
Else
{// Interpolation Ratio
Weight = FABS (Gy)/FABS (Gx );
G2 = pmag [NPOs + 1];
G4 = pmag [nPos-1]; // If X, Y both directions have the same direction derivative symbol
// The relationship between the current pixel C and the g1-g4 is
// G3 // G4 C G2 // G1
If (Gx * Gy> 0)
{
G1 = pmag [NPOs + Sz. cx + 1];
G3 = pmag [nPos-sz.cx-1];
} // If the direction of the two derivatives X and Y is the opposite
// The relationship between C and g1-g4 is // G1 // G4 C G2 // G3
Else
{
G1 = pmag[ nPos-sz.cx + 1];
G3 = pmag [NPOs + Sz. cx-1];
}
} // Gradient Interpolation using g1-g4
{
Dtmp1 = weight * G1 + (1-weight) * G2;
Dtmp2 = weight * G3 + (1-weight) * G4; // the gradient of the current pixel is the local maximum.
// This point may be a boundary point
If (dtmp> = dtmp1 & dtmp> = dtmp2) {pnsrst [NPOs] = 128 ;}
Else
{// Not a boundary point
Pnsrst [NPOs] = 0;
}
}
}
}
}
}
// Counts the pmag histogram and determines the threshold.
Void estimatethreshold (int * pmag, size SZ, int * pthrhigh, int * pthrlow, lpbyte pgray, double drathigh, double dratlow)
{
Long y, X, K; // the size of the array is related to the gradient value range. If the algorithm of this program is used, the gradient range will not exceed POW)
Int nhist [256]; // number of possible boundaries
Int nedgenum; // maximum number of gradients
Int nmaxmag;
Int nhighcount;
Nmaxmag = 0; // Initialization
For (k = 0; k <256; k ++)
{
Nhist [k] = 0;
} // Calculate the threshold using the Histogram
For (y = 0; y = nthrhigh ))
{// Set this point as a boundary point
Presult [NPOs] = 255;
Traceedge (Y, X, nthrlow, presult, pmag, SZ );
}
}
} // Other points cannot be the border points.
For (y = 0; y = nthrlow)
{// Set this point to a boundary point
Presult [yy * Sz. cx + XX] = 255;
// Tracking with this point as the center
Traceedge (YY, XX, nthrlow, presult, pmag, SZ );
}
}
}
// You can use the moderation operator.
Void canny (lpbyte pgray, size SZ, double Sigma, double dratlow, double drathigh, lpbyte presult)
{// Image after Gaussian filtering
Lpbyte pgausssmooth; pgausssmooth = new unsigned char [Sz. CX * Sz. Cy];
// X-direction derivative pointer
Int * pgradx; pgradx = new int [Sz. CX * Sz. Cy];
// Y
Int * pgrady; pgrady = new int [Sz. CX * Sz. Cy];
// Gradient Amplitude
Int * pgradmag; pgradmag = new int [Sz. CX * Sz. Cy];
// Gaussian filter of the source Image
Gaussiansmooth (SZ, pgray, pgausssmooth, SIGMA );
// Calculates the magnitude of the direction derivative and gradient.
GRAD (SZ, pgausssmooth, pgradx, pgrady, pgradmag );
// Application Non-maximum suppression
Nonmaxsuppress (pgradmag, pgradx, pgrady, SZ, presult );
// Apply hysteresis to locate all boundaries
Hysteresis (pgradmag, SZ, dratlow, drathigh, presult );
Delete [] pgradx; pgradx = NULL;
Delete [] pgrady; pgrady = NULL;
Delete [] pgradmag; pgradmag = NULL;
Delete [] pgausssmooth; pgausssmooth = NULL;
}/*
// Use the instance
Void cchildwnd: oncanny ()
{
If (! M_fopenfile) return;
M_fdone = true;
Rgbtogray (szimg, argb, agray, BPP );
Canny (agray, szimg, 0.1, 0.9, 0.76, abinimg );
Showgrayimage ("L", szimg, abinimg );
}//*/