Menemukan kontur

Pemrosesan Citra dengan Python

Rebeca Gonzalez

Data Engineer

Menemukan kontur

  • Mengukur ukuran
  • Mengklasifikasikan bentuk
  • Menentukan jumlah objek

Total titik pada kepingan domino: 29.

Pemrosesan Citra dengan Python

Citra biner

Kita dapat memperoleh citra biner dengan menerapkan thresholding atau menggunakan deteksi tepi

Pemrosesan Citra dengan Python

Temukan kontur dengan scikit-image

Menyiapkan citra

Ubah citra ke skala abu-abu 2D.

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

Pemrosesan Citra dengan Python

Temukan kontur dengan scikit-image

Menyiapkan citra

Binerkan citra

# Obtain the thresh value
thresh = threshold_otsu(image)

# Apply thresholding
thresholded_image = image > thresh

Pemrosesan Citra dengan Python

Temukan kontur dengan scikit-image

Lalu gunakan 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)

Pemrosesan Citra dengan Python

Nilai level konstan

Pemrosesan Citra dengan Python

Langkah menemukan 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)
Pemrosesan Citra dengan Python

Langkah menemukan kontur

Hasilnya

Pemrosesan Citra dengan Python

Bentuk sebuah kontur

Kontur: daftar ndarray berdimensi (n, 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)

Pemrosesan Citra dengan Python

Bentuk sebuah kontur

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

Pemrosesan Citra dengan Python

Bentuk sebuah kontur

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Batas luar
(401, 2)
(401, 2) --> Batas dalam
(123, 2)
(123, 2) 
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Pemrosesan Citra dengan Python

Bentuk sebuah kontur

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Batas luar
(401, 2)
(401, 2) --> Batas dalam
(123, 2)
(123, 2) --> Garis pembatas kepingan
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) 

Pemrosesan Citra dengan Python

Bentuk sebuah kontur

for contour in contours:
    print(contour.shape)
(433, 2)
(433, 2) --> Batas luar
(401, 2)
(401, 2) --> Batas dalam
(123, 2)
(123, 2) --> Garis pembatas kepingan
(59, 2)
(59, 2)
(59, 2)
(57, 2)
(57, 2)
(59, 2)
(59, 2) --> Titik 

Jumlah titik: 7.

Pemrosesan Citra dengan Python

Ayo berlatih!

Pemrosesan Citra dengan Python

Preparing Video For Download...