Python으로 배우는 이미지 처리
Rebeca Gonzalez
Data Engineer


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

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

이미지를 2D 그레이스케일로 변환합니다.
# Make the image grayscale
image = color.rgb2gray(image)

이미지 이진화
# Obtain the thresh value
thresh = threshold_otsu(image)
# Apply thresholding
thresholded_image = image > thresh

그다음 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)



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)

윤곽선: (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)

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)

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)

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)

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으로 배우는 이미지 처리