Обробка зображень у 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) — ndarrays.
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