Canny Edge Detection

Download: cannyEdge.zip

Under Construction.

Canny edge detection requires multiple steps to process;

  1. Smooth with gaussian filter.
  2. Compute h/v gradients.
  3. Compute magnitude of gradient.
  4. Perform Non-Maximal Suppression.
  5. Perform Hysteresis Threshold.

1) Smooth with Gaussian Filter

Convolve the input image with Gaussian kernel (filter) in order to remove high-freq noises. It is useful to remove small-scale textures effectively. Because Gaussian kernel is separable, use 2D separable convolution for faster computation.

2) Compute Horizontal/Vertical Gradient

Gradient is the first-order derivatives of image for each direction. It is rough detection of all possible edges in the image but the edges look thick. So we need to thinning algorithm to find 1-pixel edge lines, which is Non-Maximal Suppression. The gradient can be computed using central difference:
deltaX(x,y) = [(x+1, y) - (x-1, y)] / 2
deltaY(x,y) = [(x, y+1) - (x, y-1)] / 2

3) Compute Magnitude of gradient

Magnitude of horizontal and vertical gradient is used for non-maximal suppression process. The magnitude can be computed by:
magnitude = sqrt(deltaX*deltaX + deltaY*deltaY)

4) Non-Maximal Suppression (NMS)

NMS is an edge-thinning algorithm. This process results in one pixel wide ridges from thick edges. It requires h/v gradients and the magnitude of gradients. The basic idea of NMS is that: If a pixel value is not greater than its neighbored pixels, then the pixel is not the edge (the scalar value of the pixel is set to zero). During this process, it also needs to know the direction of the gradient vectors in order to find 2 neighbour pixels on the same direction, then to compare them with the current pixel. (mostly 4 or 8 directions are required)

5) Perform Hysteresis Threshold

Hysteresis thresholding is used to remove the weak edges and plus, connect the splitted edges. To connect edges, starting at a pixel which is greater than high treshold and search all 8 surround neighbours. If the neighbour is greater than low threshold, then it will also become an edge. The range of threshold is:
0 < tLow < tHigh < 1

←Back