Skip to content

Canny edge detector

The Canny edge detector is an edge detection operator that uses a multi-stage algorithm to detect a wide range of edges in images. It was developed by John F. Canny in 1986. Canny also produced a computational theory of edge detection explaining why the technique works.

Edge detect 알고리즘의 한 종류이다.

Step

"A Computational Approach to Edge Detection" 논문을 이해하는건 쉬운일이 아니기 때문에 아래와 같이 아주 간단하게 정리하면 Canny edge는 4단계로 이루어져 있다.

  1. Gaussian Blur 로 이미지를 blur해주어 노이즈를 없앤다.
  2. Sobel Edge Detector를 이용해 edge를 찾는다.
  3. Non-maxima Suppression: Edge의 magnitude 가 maximum인 경우만 edge로 사용한다. 이 때 모든 3x3 neighbor에 대해서 maximum인지 판별하는 것이 아닌 edge의 orientaton을 고려해 탐색 방향을 결정한다.
  4. Edge들을 연결 (Hysteresis analysis)

Non-maxima Suppression

엣지의 magnitude 가 maximum인 경우만 엣지로 사용한다. 이 때 모든 3x3 neighbor에 대해서 maximum인지 판별하는 것이 아닌 edge의 orientaton을 고려해 탐색 방향을 결정한다.

Canny Edge의 특징중 하나는 두개의 threshold를 사용하는 것인데, 이 과정에서 높은 threshold보다 엣지의 magnitude가 크면 엣지 픽셀로 지정하고 낮은 threshold 보다 높은 magnitude를 가지면 나중에 edge들을 연결(hysteresis analysis)할 때 엣지 픽셀과 인접해 있으면 엣지로 지정한다.

Example

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('messi5.jpg',0)
edges = cv2.Canny(img,100,200)

plt.subplot(121),plt.imshow(img,cmap = 'gray')
plt.title('Original Image'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(edges,cmap = 'gray')
plt.title('Edge Image'), plt.xticks([]), plt.yticks([])

plt.show()

See also

Favorite site

References


  1. Carstart.tistory.com_-Corner_Detection-_Canny_Edge.pdf 

  2. Gaussian37.github.io_-vision-concept-_edge_detection.pdf