Thresholding से शुरुआत करें

Python में इमेज प्रोसेसिंग

Rebeca Gonzalez

Data Engineer

Thresholding

किसी इमेज को foreground और background में बाँटना

उसे black and white बनाकर

ऐसा करने के लिए हर पिक्सेल को सेट करते हैं:

  • 255 (white) अगर पिक्सेल $\gt$ thresh value
  • 0 (black) अगर पिक्सेल $\lt$ thresh value

कैमरा लिए व्यक्ति की thresholded इमेज

Python में इमेज प्रोसेसिंग

Thresholding

Image segmentation की सबसे सरल विधि

  • ऑब्जेक्ट अलग करें
    • Object detection
    • Face detection
    • आदि

डोमिनोज़ टोकन्स की thresholded इमेज

Python में इमेज प्रोसेसिंग

Thresholding

सिर्फ grayscale इमेज से

Threshold के स्टेप्स, डोमिनोज़ टोकन्स के साथ: पहले RGB-3, फिर grayscale, फिर thresholded

Python में इमेज प्रोसेसिंग

इसे लागू करें

# Obtain the optimal threshold value
thresh = 127

# Apply thresholding to the image binary = image > thresh
# Show the original and thresholded show_image(image, 'Original') show_image(binary, 'Thresholded')

कैमरा लिए व्यक्ति की thresholded इमेज

Python में इमेज प्रोसेसिंग

Inverted thresholding

# Obtain the optimal threshold value
thresh = 127

# Apply thresholding to the image inverted_binary = image <= thresh
# Show the original and thresholded show_image(image, 'Original') show_image(inverted_binary, 'Inverted thresholded')

कैमरा लिए व्यक्ति की inverted thresholded इमेज

Python में इमेज प्रोसेसिंग

श्रेणियाँ

  • Global या histogram आधारित: समान background पर अच्छा

  • Local या adaptive: असमान background illumination के लिए

Global और local thresholding की तुलना

Python में इमेज प्रोसेसिंग

और thresholding एल्गोरिदम आज़माएँ

from skimage.filters import try_all_threshold

# Obtain all the resulting images fig, ax = try_all_threshold(image, verbose=False)
# Showing resulting plots show_plot(fig, ax)
Python में इमेज प्रोसेसिंग

और thresholding एल्गोरिदम आज़माएँ

एक टेक्स्ट पेज की grayscale इमेज पर सभी global thresholding तरीकों का परीक्षण

Python में इमेज प्रोसेसिंग

सर्वोत्तम thresh value

Global

Uniform background
# Import the otsu threshold function
from skimage.filters import threshold_otsu

# Obtain the optimal threshold value thresh = threshold_otsu(image)
# Apply thresholding to the image binary_global = image > thresh
Python में इमेज प्रोसेसिंग

सर्वोत्तम thresh value

Global

# Show the original and binarized image
show_image(image, 'Original')
show_image(binary_global, 'Global thresholding')

कैमरा लिए व्यक्ति की मूल इमेज, इसकी thresholded इमेज, और histogram जिसमें लाल रेखा सर्वोत्तम thresh value दिखाती है

Python में इमेज प्रोसेसिंग

सर्वोत्तम thresh value

Local

Uneven background
# Import the local threshold function
from skimage.filters import threshold_local

# Set the block size to 35 block_size = 35
# Obtain the optimal local thresholding local_thresh = threshold_local(text_image, block_size, offset=10)
# Apply local thresholding and obtain the binary image binary_local = text_image > local_thresh
Python में इमेज प्रोसेसिंग

सर्वोत्तम thresh value

Local

# Show the original and binarized image
show_image(text_image, 'Original')
show_image(binary_local, 'Local thresholding')

टेक्स्ट पेज की locally thresholded इमेज

Python में इमेज प्रोसेसिंग

अभ्यास करते हैं!

Python में इमेज प्रोसेसिंग

Preparing Video For Download...