Hysteresis หมายถึงผลลัพธ์ที่ตามมาช้า (lagging effect) เกี่ยวกับ threshold hysteresis หมายถึง พื้นที่ที่อยู่เหนือค่า threshold ต่ำ หรือเหนือค่า threshold สูง กล่าวคือพื้นที่ที่มีความมั่นใจสูง (highly-confident)
ด้วย hysteresis สามารถเพิกเฉย雜訊 (noise) นอกขอบของวัตถุในภาพได้
มาดูวิธีทำ hysteresis threshold ด้วย scikit-learn (scikit-image):
ตัวอย่าง
import matplotlib.pyplot as plt
from skimage import data, filters
fig, ax = plt.subplots(nrows=2, ncols=2)
orig_img = data.coins()
edges = filters.sobel(orig_img)
low = 0.1
high = 0.4
lowt = (edges > low).astype(int)
hight = (edges > high).astype(int)
hyst = filters.apply_hysteresis_threshold(edges, low, high)
ax[0, 0].imshow(orig_img, cmap='gray')
ax[0, 0].set_title('Original image')
ax[0, 1].imshow(edges, cmap='magma')
ax[0, 1].set_title('Sobel edges')
ax[1, 0].imshow(lowt, cmap='magma')
ax[1, 0].set_title('Low threshold')
ax[1, 1].imshow(hight + hyst, cmap='magma')
ax[1, 1].set_title('Hysteresis threshold')
for a in ax.ravel():
a.axis('off')
plt.tight_layout()
plt.show()
ผลลัพธ์

คำอธิบาย
- นำเข้าไลบรารีที่จำเป็น
- ใช้ subplot กำหนดพื้นที่พล็อต
- ใช้ข้อมูล 'coins' ใน scikit-learn เป็นอินพุต
- ฟิลเตอร์ 'sobel' เน้นขอบในภาพผลลัพธ์
- ฟังก์ชัน 'apply_hysteresis_threshold' หาค่าที่อยู่เหนือ/ต่ำกว่า threshold
- แสดงข้อมูลด้วย 'imshow'
Hysteresis thresholding ใช้ two thresholds: high (strong edges) และ low (weak edges) เฉพาะ weak edges ที่เชื่อมต่อกับ strong edges จะถูกเก็บไว้