【问题标题】:Why can't I plot image histogram's in python-OpenCV为什么我不能在 python-OpenCV 中绘制图像直方图
【发布时间】:2023-03-03 05:05:24
【问题描述】:

我必须得到一张图像,应用直方图均衡化并绘制两个图像(原始和修改)的直方图。所以我尝试了这段代码:

import cv2
import numpy as np
from skimage import io, img_as_float, img_as_ubyte
import matplotlib.pyplot as plt  
from matplotlib import pyplot as plt

gray = cv2.imread("folder\img1.jpg",0)


equ = cv2.equalizeHist(gray)

io.imshow(gray)
io.imshow(equ)

histr = cv2.calcHist([gray],[0],None,[256],[0,256])
  
plt.plot(histr)
plt.show()

但是返回的情节是..:

我该如何解决?

【问题讨论】:

标签: python opencv matplotlib histogram


【解决方案1】:

您没有创建新图形,因此直方图绘制在显示图像的最后一个图形上。
您可以在绘制直方图之前创建一个新图形:

histr = cv2.calcHist(gray, [0], None, [256], (0,255))

plt.figure() # Create new figure for the histogram plot
plt.plot(histr)
plt.show()

【讨论】:

    猜你喜欢
    • 2012-03-12
    • 1970-01-01
    • 2017-11-10
    • 2018-06-02
    • 2013-10-12
    • 1970-01-01
    • 2015-09-20
    • 1970-01-01
    • 2015-05-29
    相关资源
    最近更新 更多