Digital-Image-Processing-kosta / Canny-edge-detection-algorithm

Matlab implementation of Canny edge detection algorithm from scratch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CANNY EDGE DETECTION ALGORITHM

Matlab implementation of Canny edge detection algorithm from scratch.

IMPLEMENTATION

Algorithm contains following steps:
1. Filtering input image with Gaussian filter with given standard deviation (filter size should be equal or greater than 6 * sigma)
2. Determining horizontal and vertical gradients of the filtered image

Original Image Gradients in x direction Gradients in y direction
o1 gx gy

3. Determining magnitude and angle od the gradients with following formulas:
img 15

Gradient magnitude Gradient angle
o1 gx

4. Quantization of the angle of the gradient on the following directions: 0, -45, 45, 90 degrees.
quantization
5. Supression of the gradients that do not represent local maximum.
We iterate thorugh every pixel of the magnitude of the gradient and we read qunatized value of the gradient angle for that pixel. For every direction of the gradient angle specific matrix of 0s and 1s is defined:
matriciies
We take the matrix that corresponds to the read quantized value of the gradient angle and multiply it with 3x3 gradient magnitude surrounding of the pixel. If the maximum value in the resulting 3x3 matrix is not in the middle, the pixel value is set to zero. This must NOT be done inplace!
supression
6. Determining the maps of weak and strong edges based on low and high threshold.
All values of the magnitude of the gradient that are higher than T_high are set to value 1 in the map of the combined edges and they go into the map of the strong edges. All values between T_low and T_high are set to value 50/250 in the map of the combined edges and they go into the map of the weak edges. All values below T_low are set to 0.

Weak edges Strong edges Combined edges
o1 gx gy

7. Determining final map of edges by including weak edges that are connected with strong edges.
We iterate thorugh the combined map of the edges and if the edge is weak we check the 3x3 surrounding arround that edge. If in that surrounding exists at least 1 strong edge, the value of the weak edge is set to strong. This must NOT be done in place! This procedure repeats until there is no change from weak to strong.
final

TEST

Run the main.m to test the algorithm on the house.tif, camerman.tif, van.tif and lena.tif images.

About

Matlab implementation of Canny edge detection algorithm from scratch.


Languages

Language:MATLAB 100.0%