|
| 1 | +# Canny Edge detection using OpenCV and python |
| 2 | + |
| 3 | +## What is Canny Edge Detection? |
| 4 | + |
| 5 | +Canny Edge Detection |
| 6 | +It is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. |
| 7 | +It was developed by John F. Canny ,an Australian computer scientist, back in 1986. |
| 8 | + |
| 9 | +### _The Canny edge detection algorithm is composed of 5 steps_: |
| 10 | ++ Noise reduction; |
| 11 | ++ Gradient calculation; |
| 12 | ++ Non-maximum suppression; |
| 13 | ++ Double threshold; |
| 14 | ++ Edge Tracking by Hysteresis. |
| 15 | + |
| 16 | +## Lets see how it's done. |
| 17 | + |
| 18 | +1. #### Input image: |
| 19 | + Input in RGB format. |
| 20 | + |
| 21 | +2. #### Converting the image to grayscale: |
| 22 | + For easier calculations. |
| 23 | + |
| 24 | +3. #### Smoothing the image: |
| 25 | + Smoothing of image for noise reduction. Gradient is the first order derivatives of image for each direction. |
| 26 | + It is cause of edges that seems more and the edges look thick. |
| 27 | + |
| 28 | +4. #### Image gradient: |
| 29 | + Gradient is the function of the partial derivatives. I applied to the image convolution process with Sobel filters to obtain this partial derivative. |
| 30 | + |
| 31 | +5. #### Non-maximum suppression: |
| 32 | + In this step the pixel is compared with its two neighbors of the pixel, if the compared pixel is larger than neighbor we do not change the pixel, |
| 33 | + otherwise, this pixel is not maximum value hence, we set the zero to that pixel. |
| 34 | + |
| 35 | +6. #### Tracking the edge by hysteresis: |
| 36 | + In this step we choose two type of threshold, high and low threshold value. Afterward, each pixel of image is compared with two different threshold value. |
| 37 | + If the pixel is larger than the high threshold, this pixel mark with 255 in the final image. |
| 38 | + If the pixel between high threshold and low threshold. If the pixel is smaller than low-threshold image, mark as black with 0 (black) value in the resulting image. |
| 39 | + |
| 40 | +7. #### Final Results: |
| 41 | + After passing all of the mentioned steps, we will give the final result from the method. |
| 42 | + |
| 43 | +# Output Results: |
| 44 | + |
| 45 | +For more detail on learning Canny Edge Detection and maths behind , see my article [here](https://medium.com/simply-dev/what-is-canny-edge-detection-cfefa272a8d0) |
| 46 | + |
| 47 | + |
| 48 | + |
0 commit comments