Hitta konturer

Bildbehandling i Python

Rebeca Gonzalez

Data Engineer

Hitta konturer

  • Mät storlek
  • Klassificera former
  • Bestäm antal objekt

Totalt antal prickar i dominobrickorna: 29.

Bildbehandling i Python

Binära bilder

En binär bild kan skapas med tröskling eller kantdetektering

Bildbehandling i Python

Hitta konturer med scikit-image

Förbered bilden

Omvandla bilden till 2D-gråskala.

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

Bildbehandling i Python

Hitta konturer med scikit-image

Förbered bilden

Binarisera bilden

# Obtain the thresh value
thresh = threshold_otsu(image)

# Apply thresholding
thresholded_image = image > thresh

Bildbehandling i Python

Hitta konturer med scikit-image

Använd sedan 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)

Bildbehandling i Python

Konstantnivåvärde

Bildbehandling i Python

Steg för att hitta konturer

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)
Bildbehandling i Python

Steg för att hitta konturer

Resultat

Bildbehandling i Python

En konturens form

Konturer: lista med (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)

Bildbehandling i Python

En konturens form

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) 

Bildbehandling i Python

En konturens form

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) 

Bildbehandling i Python

En konturens form

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) 

Bildbehandling i Python

En konturens form

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 

Antal prickar: 7.

Bildbehandling i Python

Nu kör vi en övning!

Bildbehandling i Python

Preparing Video For Download...