Hysteresis thresholding là kỹ thuật ngưỡng kép dùng trong phát hiện cạnh (edge detection), ví dụ Canny. Nó sử dụng hai ngưỡng:
- Low threshold: giữ các pixel cạnh yếu.
- High threshold: giữ các pixel cạnh mạnh.
Quy tắc: pixel cạnh mạnh (> high) luôn giữ. Pixel cạnh yếu (> low) chỉ giữ nếu nó kết nối với pixel cạnh mạnh. Nhiễu (≤ low) bị loại bỏ.
Ví dụ với scikit-image
import matplotlib.pyplot as plt
from skimage import data, filters
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)
fig, ax = plt.subplots(2, 2)
ax[0,0].imshow(orig_img, cmap='gray'); ax[0,0].set_title('Ảnh gốc')
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()
Giải thích
filters.sobeltính gradient magnitude (độ lớn gradient).apply_hysteresis_thresholdáp dụng ngưỡng histeresis: giữ pixel > high, và pixel > low nếu liên thông với pixel > high.- Kết quả loại bỏ nhiễu rải rác, giữ các đường liền mạch.