Implementation of canny algorithm

Source: Internet
Author: User

Canny edge detection first to the image Gaussian denoising, because the front preprocessing to the image denoising, so you can directly to the image grayscale differential operation. The common method of differential operation is to use the template operator, the template center corresponds to each pixel location of the image, and then according to the formula of the template to the central pixel and the pixels around it to calculate the value of the image corresponding to the pixel point in the experiment template matrix selected Laplacian operator [44], soble operator and Roberts operators. La Plaze operator is a 2-order differential operator, its precision is relatively high, but the noise is too sensitive to noise, the effect is very poor. The effect of Robert operator in uneven illumination is also very poor, which is sensitive to noise. The following is a simple example of a template to explain:

1, calculate the x and Y direction gradient values to get the gradient amplitude and gradient direction of gray scale

Gx= (Hd[x][y+1]-hd[x][y]+hd[x+1][y+1]-hd[x+1][y])/2;
Gy= (hd[x][y]-hd[x+1][y]+hd[x][y+1]-hd[x+1][y+1])/2;

g[x][y]= (int) math.sqrt (GY*GY+GX*GX);
Angle[x][y]=math.atan2 (GY,GX);

2. Selection of high and low threshold values. Usually the high threshold of the canny operator and the 0.4,tl=0.4*th of the low threshold Tl, while the high threshold value selects different values according to the purpose of the binary, the priori knowledge is usually Th selected: the gradient amplitude matrix is counted as the high threshold value for that amplitude value of the gradient value of the former q% (q% between 0.75-0.85). Points below the low threshold are treated as a non-edge point of 0, which is greater than or equal to the high threshold value as the edge Point 255, which is between the upper and lower thresholds for the point 125 to be detected.

3, non-maximal value suppression, which is the key to edge detection, is the region of the gradient amplitude value of the extremum as the edge point, such as:

For the entire gradient amplitude map, if the (x, y) point is greater than the amplitude of P and M, the (x, y) is treated as an edge point and the value is set to 255. It can be seen from the graph that the P-point amplitude value can be tan (sigma) * (G (X+1,y)-g (x, Y)) and the gradient amplitude of the M-point can be obtained by the same token.

4, the gradient in the amplitude of the first step is considered to be the edge of the 8 domain scanning, if greater than or equal to th is considered to be the edge Point 255, will be lower than the TL directly set to 0 as the non-edge point is greater than the TL 125, with a detection point.

5, the edge connected to the previous image to be scanned, 255 around the 8 domain points for detection, if 125 is considered to be the edge point, set to 255, and then the new 255 of the point 8 field to find the detection point, if any, set it to 255, until there is no new edge point to produce so far.

Implementation of canny algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.