윤곽선 찾기

Python으로 배우는 이미지 처리

Rebeca Gonzalez

Data Engineer

윤곽선 찾기

  • 크기 측정
  • 모양 분류
  • 객체 수 파악

도미노 토큰의 점 개수: 29.

Python으로 배우는 이미지 처리

이진 이미지

이진 이미지는 임계값 처리 또는 에지 검출로 얻을 수 있습니다.

Python으로 배우는 이미지 처리

scikit-image로 윤곽선 찾기

이미지 준비

이미지를 2D 그레이스케일로 변환합니다.

# Make the image grayscale
image = color.rgb2gray(image)

Python으로 배우는 이미지 처리

scikit-image로 윤곽선 찾기

이미지 준비

이미지 이진화

# Obtain the thresh value
thresh = threshold_otsu(image)

# Apply thresholding
thresholded_image = image > thresh

Python으로 배우는 이미지 처리

scikit-image로 윤곽선 찾기

그다음 find_contours()를 사용합니다.

# Import the measure module
from skimage import measure

# Find contours at a constant value of 0.8
contours = measure.find_contours(thresholded_image, 0.8)

Python으로 배우는 이미지 처리

상수 레벨 값

Python으로 배우는 이미지 처리

윤곽선 찾기 단계

from skimage import measure
from skimage.filters import threshold_otsu

# Make the image grayscale
image = color.rgb2gray(image)

# Obtain the optimal thresh value of the image thresh = threshold_otsu(image) # Apply thresholding and obtain binary image thresholded_image = image > thresh
# Find contours at a constant value of 0.8 contours = measure.find_contours(thresholded_image, 0.8)
Python으로 배우는 이미지 처리

윤곽선 찾기 단계

결과

Python으로 배우는 이미지 처리

윤곽선의 shape

윤곽선: (n, 2) 형태의 ndarray 리스트.

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2)
(401, 2)
(401, 2) 
(123, 2)
(123, 2) 
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2)

Python으로 배우는 이미지 처리

윤곽선의 shape

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> 바깥 경계
(401, 2)
(401, 2)
(123, 2)
(123, 2)
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Python으로 배우는 이미지 처리

윤곽선의 shape

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> 바깥 경계
(401, 2)
(401, 2) --> 안쪽 경계
(123, 2)
(123, 2) 
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Python으로 배우는 이미지 처리

윤곽선의 shape

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> 바깥 경계
(401, 2)
(401, 2) --> 안쪽 경계
(123, 2)
(123, 2) --> 토큰 구분선
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Python으로 배우는 이미지 처리

윤곽선의 shape

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> 바깥 경계
(401, 2)
(401, 2) --> 안쪽 경계
(123, 2)
(123, 2) --> 토큰 구분선
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) --> 점 

점 개수: 7.

Python으로 배우는 이미지 처리

연습해 봅시다!

Python으로 배우는 이미지 처리

Preparing Video For Download...