如何在 Matplotlib 中繪製滯後閾值?


要在 Matplotlib 中繪製滯後閾值,我們可以採取以下步驟:

  • 設定影像大小並調整子圖之間和周圍的填充。
  • 建立一個影像和一組子圖。
  • 載入一些來自龐貝的古希臘硬幣。
  • 使用 sobel 濾波器查詢影像的、和邊緣
  • 將滯後閾值化應用於“影像”。
  • 使用 imshow() 方法將資料顯示為影像,即,顯示在規則的二維柵格上。
  • 設定原影像和滯後閾值影像的標題。
  • 要顯示影像,請使用 show() 方法。

示例

import matplotlib.pyplot as plt
from skimage import data, filters

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

fig, ax = plt.subplots(nrows=1, ncols=2)
orig_img = data.coins()
edges = filters.sobel(orig_img)

low = 0.1
high = 0.4
low = (edges > low).astype(int)
height = (edges > high).astype(int)
hyst = filters.apply_hysteresis_threshold(edges, low, high)

ax[0].imshow(height + hyst, cmap='magma')
ax[0].set_xlabel('Hysteresis threshold')
ax[1].imshow(orig_img, cmap='magma')
ax[1].set_xlabel('Original Image')

plt.show()

輸出

更新於: 08-7 月-2021

501 次瀏覽

啟動你的 職業生涯

完成課程獲得認證

開始
廣告