如何在 Matplotlib 中绘制滞后阈值?
pythonserver side programmingprogramming更新于 2025/8/8 12:28:17
要在 Matplotlib 中绘制滞后阈值,我们可以采取以下步骤 −
- 设置图形大小并调整子图之间和周围的填充。
- 创建一个图形和一组子图。
- 加载一些希腊硬币,庞贝古城的希腊硬币。
- 使用 sobel 过滤器查找图像的 高、低 和 边缘。
- 将滞后阈值应用于"图像"。
- 使用 imshow() 方法将数据显示为图像,即在 2D 常规栅格上。
- 设置标题原始图像和具有滞后阈值的图像。
- 要显示图形,请使用 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()
输出

相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/

