Hledání kontur

Image Processing in Python

Rebeca Gonzalez

Data Engineer

Hledání kontur

  • Měření velikosti
  • Klasifikace tvarů
  • Určení počtu objektů

Celkový počet bodů na dominech: 29.

Image Processing in Python

Binární obrazy

Binární obraz lze získat pomocí prahování nebo detekce hran

Image Processing in Python

Hledání kontur pomocí scikit-image

Příprava obrazu

Převeďte obraz na 2D ve stupních šedi.

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

Image Processing in Python

Hledání kontur pomocí scikit-image

Příprava obrazu

Binarizace obrazu

# Obtain the thresh value
thresh = threshold_otsu(image)

# Apply thresholding
thresholded_image = image > thresh

Image Processing in Python

Hledání kontur pomocí scikit-image

Poté použijte 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)

Image Processing in Python

Hodnota konstantní úrovně

Image Processing in Python

Kroky pro detekci kontur

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)
Image Processing in Python

Kroky pro detekci kontur

Výsledek

Image Processing in Python

Tvar kontury

Kontury: seznam (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)

Image Processing in Python

Tvar kontury

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

Image Processing in Python

Tvar kontury

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Outer border
(401, 2)
(401, 2) --> Inner border
(123, 2)
(123, 2) 
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Image Processing in Python

Tvar kontury

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Outer border
(401, 2)
(401, 2) --> Inner border
(123, 2)
(123, 2) --> Divisory line of tokens
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Image Processing in Python

Tvar kontury

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Outer border
(401, 2)
(401, 2) --> Inner border
(123, 2)
(123, 2) --> Divisory line of tokens
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) --> Dots 

Počet bodů: 7.

Image Processing in Python

Lass uns üben!

Image Processing in Python

Preparing Video For Download...