【问题标题】:vertical line in histogram with pyplot带有pyplot的直方图中的垂直线
【发布时间】:2015-07-26 09:33:08
【问题描述】:

我已经计算了 kinect 深度图像的 Otsu 阈值,现在我想指出直方图上的最佳阈值,例如在 opencv2 中使用带有 pyplot 的 axvline。 我也是 python 和编程的初学者,这是我代码的特定部分:

fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
ax1.imshow(img)
ax1.set_title('Original')
ax1.axis('off')

ax2.hist(img)
ax2.set_title('Histogram')
plt.axvline(x=thresh, color='r', linestyle='dashed', linewidth=2)

ax3.imshow(binary, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')

plt.show()

但我不知道为什么,我得到了阈值图上的垂直线

我做错了什么?? 谢谢

【问题讨论】:

  • 也许您应该在ax2 上调用axvline 而不是调用pyplot 方法?
  • 是的,我已经完成了 ax2.axvline ......但我得到了一条不可见的线,一条白线而不是红色..为什么?

标签: python-2.7 matplotlib histogram threshold


【解决方案1】:

为我工作:

from scipy.misc import imread, imresize
import matplotlib.pyplot as plt
f = r"C:\Users\Public\Pictures\Sample Pictures\Lighthouse.jpg"
img = imread(f)[:, :, 0]
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 2.5))
ax1.imshow(img)
ax1.set_title('Original')
ax1.axis('off')

thresh = 100
ax2.hist(img)
ax2.set_title('Histogram')
ax2.axvline(x=thresh, color='r', linestyle='dashed', linewidth=2)

ax3.imshow(img, cmap=plt.cm.gray)
ax3.set_title('Thresholded')
ax3.axis('off')

plt.show()

【讨论】:

    猜你喜欢
    • 2019-02-02
    • 2011-08-27
    • 2012-02-09
    • 2017-12-12
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多