- Low error rate: 모든 경계는 감지되어야 되지만, 노이즈에 의한 경계는 감지는 되어선 안된다.
- Edge points should be well localized : 모든 경게선은 폐구간으로 닫혀 있어야 한다.
- Single edge point response: 경계선의 두께는 반드시 하나의 점으로 이루어 져야 한다.
- Pre-processing : Gaussian blur를 이용하여 이미지의 노이즈를 감소 시켜준다.
- Gradient calculate : Sobel 커널을 이용하여 엣지부분의 벡터를 연산
- Non-maximum Suppression : 중첩된 엣지를 제거
- Hysterisis Thresholding : 불 필요한 엣지 제거
Sobel 커널을 이용하여 이미지의 픽셀 미분값을 구함
X Sobel 커널 , Y Sobel 커널 를 구한 뒤 극좌표 형태로 구현
: Gradient의 Norm
: Gradient의 기울기
여기서 는 아래의 기준에 맞춰 4가지 방향으로 분류
(-angle은 기울기의 크기가 음수일때 판정)
i) horizontal edge : 0 ~ 22.5 deg, 157.5 ~ 180 deg
ii) vetical edge : 67.5 ~ 112.5 deg
iii) -45deg edge : 22.5 ~ 67.5 deg
iv) 45deg edge : 112.5 ~ 157.5 deg
- 이어져 있는 경계선이 sure edge일 경우 High Threshold 값보다 적은 엣지 값은 제거 하지 않음
- 특정 엣지가 High Threshold 값보다 작다면 해당 엣지는 삭제
import cv2
from matplotlib import pyplot as plt
import numpy as np
bagpipe = cv2.imread('gene.jpg')
# Convert to grayscale.
bagpipe_gray = cv2.cvtColor(bagpipe, cv2.COLOR_BGR2GRAY)
plt.imshow(bagpipe_gray, cmap = 'gray'); plt.axis('off'); plt.title('original')
edges = cv2.Canny(bagpipe_gray, threshold1 = 70, threshold2 = 90)
plt.figure(figsize= (20,20))
plt.subplot(131);plt.imshow(edges, cmap = 'gray'); plt.axis('off'); plt.title('original')