canny edge detection

Mechboy·2024년 6월 4일
0

OPENCV

목록 보기
6/9

Canny Edge detection

Canny Edge detection 개요

  • Canny Edge 감지 시스템은 sobel Edage 감지 방법의 단점을 개선하기 위해서 도입
  • 대표적인 Canny Edge detection의 특징은
    1. Low error rate: 모든 경계는 감지되어야 되지만, 노이즈에 의한 경계는 감지는 되어선 안된다.
    2. Edge points should be well localized : 모든 경게선은 폐구간으로 닫혀 있어야 한다.
    3. Single edge point response: 경계선의 두께는 반드시 하나의 점으로 이루어 져야 한다.

Canny Edge detection 검출 알고리즘

  • Canny Edge detection은 다음과 같은 순서로 이루어 진다.
    1. Pre-processing : Gaussian blur를 이용하여 이미지의 노이즈를 감소 시켜준다.
    2. Gradient calculate : Sobel 커널을 이용하여 엣지부분의 벡터를 연산
    3. Non-maximum Suppression : 중첩된 엣지를 제거
    4. Hysterisis Thresholding : 불 필요한 엣지 제거

1. Pre-processing

  • 이미지를 우선 가우시안 커널을 이용하여 노이즈 제거

2. Gradient calculate

  • Sobel 커널을 이용하여 이미지의 픽셀 미분값을 구함

  • X Sobel 커널 gx(x,y)g_{x}(x,y) , Y Sobel 커널 gy(x,y)g_{y}(x,y) 를 구한 뒤 극좌표 형태로 구현


    Ms(x,y)M_s(x,y) : Gradient의 Norm
    α(x,y)\alpha(x,y) : Gradient의 기울기

  • 여기서 α(x,y)\alpha(x,y) 는 아래의 기준에 맞춰 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

3. Non-maximum Suppression

  • 2에서 구한 정보를 기준으로 인접셀과 비교하여 가장 큰값이 아닐 경우 해당 픽셀의 값을 0으로 바꿔줌

4. Hysterisis Thresholding

  • 3에서 구한 정보를 기준으로 폐구간을 연결 시켜주거나 불필요한 Edge를 삭제
    • 이어져 있는 경계선이 sure edge일 경우 High Threshold 값보다 적은 엣지 값은 제거 하지 않음
    • 특정 엣지가 High Threshold 값보다 작다면 해당 엣지는 삭제

Canny Edge detection 검출 알고리즘

  • 알고리즘 구현
  • Module 및 이미지 불러오기
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')

profile
imageprocessing and Data science

0개의 댓글

관련 채용 정보