This paper simply introduces the method of the edge detection, and the results of MATLAB are demonstrated.
What is the edge.
The edge is generally refers to the image in a certain local intensity of the drastic changes in the region. The intensity change generally has two kinds of conditions:
1. Step Change
The grayscale change image is shown in the following image (horizontal axis represents spatial variation, vertical axis represents grayscale change, dotted line indicates edge):
This diagram corresponds to the process of brightening the gradient.
2. Roof change
The grayscale change image is shown in the following image (horizontal axis represents spatial variation, vertical axis represents grayscale change, dotted line indicates edge):
The graph corresponds to the process of darkening from dark to light.
Task for edge Detection:
Find a set of pixels with a step change or a roof change.
Fundamentals of Edge Detection:
Since the edge is the most drastic change in the position of gray, the most intuitive idea is to find differentiation.
For the first case: the peak value of a differential is the edge point, and the 0 point of the second order differential is the edge point.
For the second case: the first-order differential 0 points are the edge points, and the second-order differential peaks are marginal points.
Using the first order differential method, we define a gradient operator, and the gradient is a vector, which indicates the direction of the most drastic change in the image gray.
The size of the gradient:
Direction of the gradient:
But in the actual image processing, can use the difference method to carry on the computation. But using difference method to edge detection must make the direction of difference and the direction of the edge perpendicular, this need to the different direction of the image difference operation, increase the calculation. You can generally divide the edges into horizontal, vertical, and diagonal edges.
1. Reberts operator
The Roberts gradient operator uses the difference of two pixel values in the diagonal direction as the measurement criterion, and its calculation method is as follows:
If written in the form of convolution operations, the convolution nuclei are:
2. Prewitt operator
The Prewitt operator combines the difference operation with the neighborhood averaging method. Its convolution template is as follows:
3.sobel operator
The Sobel operator is similar to the Prewitt operator, but the weighted average is used to take into account the difference in the degree of influence of the neighboring different pixel points. Its convolution template is as follows:
4.laplacian operator
The Laplacian operator is a number of operators that use the second order differential, which is actually the divergence of the gradient:
Second Order differential:
and
So writing as a convolution template is:
This is the Laplacian operator.
5.canny operator
Canny operator is a set of methods to find the optimal edge detection. It is a method of smoothing and derivation first.
First step:
The image is smoothed with a Gaussian filter.
Gaussian filter is used to reduce the noise of the image, and a neighborhood weighted averaging method is applied to compute the value of each pixel point.
Step Two:
The first-order difference is used to compute the direction and amplitude of the edge.
Note the convolution template is as follows:
This method has been introduced in the first order differential edge detection method, and the method is the same. It is also to get the amplitude and direction of the edge.
Step Three:
Non maxima suppression.
It is not possible to determine the position of the edge simply by finding the global gradient direction. So the need for some gradient value is not the largest store to suppress, highlighting the real edge.
In the second step, the direction of the gradient can be 360°, and we divide the 360 ° region into 4 spaces, as shown in the following figure.
corresponding to the image, a pixel and its adjacent 8 pixel points can also be divided into 4 regions.
Now what needs to be done is, to determine the 3 pixel points along the gradient direction (the pixel points in the center pixel and the other two gradient direction regions), if the gradient value of the center pixel is not greater than the gradient value of the other two pixels, the gray value of the pixel point is 0.
Fourth Step:
Double threshold detection.
For the previous processing of the completed image two threshold values, Th1 and Th2, meet Th1 = 0.4 Th2. The gray value of the point with the gradient value less than the threshold is directly set to 0, and two new images are obtained, and the graphs 1 and 2 are recorded. Fig. 2 Because of the greater threshold for action, it removes most of the noise and may also remove useful edge information. Figure 1 Preserves more edge information, and we use the diagram to complement Figure 2.
Complementary methods:
When you scan Figure 2 for a pixel p (x, y) of the first non-0 grayscale, and then begin to scan the contiguous non-0 gray-point pixels (the contour line of the edges) with P-point. When the end of the contour line is found (that is, a point that does not scan for a contiguous non-0 grayscale pixel point, as Q Point, whenever a Q-point is found, the pixel points in the same position are found in Figure 1, and the adjacent 8 pixel points are not 0 gray pixels. If it does, then the point grayscale in Figure 2 is set to non-0, and as a P point, the entire scan process is repeated.
When the whole process can no longer continue, we think we have found a contour line of the edge. Repeat the process until you find all the edges of the contour line.
Finally, the test of the MATLAB code and experimental results:
i = imread (' lena.png ');
A = fspecial (' Gaussian ');
i = Filter2 (A, i)/255;
Figure;
Imshow (i);
Imwrite (i, ' lena_0.jpg ');
A = Edge (i, ' Prewitt ');
Figure;
Imshow (a);
Imwrite (A, ' lena_1.jpg ');
A = Edge (i, ' Sobel ');
Figure;
Imshow (a);
Imwrite (A, ' lena_2.jpg ');
A = Edge (i, ' log ');
Figure;
Imshow (a);
Imwrite (A, ' lena_3.jpg ');
A = Edge (i, ' canny ');
Figure;
Imshow (a);
Imwrite (A, ' lena_4.jpg ');
Test results:
Original:
Prewitt Operator:
Sobel operator:
Laplacian operator:
Canny operator: