close

Multi-Otsu方法是Otsu方法的擴展,用於多級分割。而不是找到一個最佳的二元閾值,它會找到多個閾值以分割圖像成多個區域。這種方法特別適合於具有多個明顯亮度級別的圖像。

以下是如何在Python中使用Multi-Otsu方法進行圖像閾值分割的範例:

 

from skimage.filters import threshold_multiotsu

# Compute the Multi-Otsu thresholds (for this example, we will compute 3 thresholds for 4 classes)
thresholds = threshold_multiotsu(provided_img, classes=4)

# Use the thresholds to segment the image into multiple regions
multi_otsu_regions = np.digitize(provided_img, bins=thresholds)

# Display the original and Multi-Otsu segmented images
fig, ax = plt.subplots(1, 2, figsize=(10, 5))

ax[0].imshow(provided_img, cmap='gray')
ax[0].set_title('Original Image')
ax[0].axis('off')

ax[1].imshow(multi_otsu_regions, cmap='gist_ncar')
ax[1].set_title('Multi-Otsu Segmented Image')
ax[1].axis('off')

plt.tight_layout()
plt.show()

如上所示,左側是您提供的原始圖像,而右側是使用Multi-Otsu方法進行分割的結果。

Multi-Otsu方法將圖像分割成了四個區域,每個區域都有不同的顏色。從結果中,您可以看到此方法是如何區分圖像的各個部分的。這種方法特別適合於當圖像具有多個明顯的亮度區域時。

這種方法提供了一種更細緻的分割方式,允許對圖像的多個區域進行分析和解釋。

arrow
arrow
    文章標籤
    圖像前處理
    全站熱搜
    創作者介紹
    創作者 Rocky 的頭像
    Rocky

    Rocky的部落格

    Rocky 發表在 痞客邦 留言(0) 人氣()