9、图像直方图(histogram)
2019-01-04 本文已影响0人
BigBigGuy
bin大小 image.png直方图最需要理解的是,bin大小和,range范围即可。
bin的数目往往是range的最大值。
def plot_demo(image):
"""
matplotlib里面的函数
ravel(),即对image的矩阵进行拷贝,对其修改,原矩阵也会变化
bins = 256
range = [0,256]
"""
plt.hist(image.ravel(), 256, [0, 256])
plt.show("直方图")
plot三通道直方图
def image_hist(image):
color = ('blue', 'green', 'red')
for i, color in enumerate(color):
'''
channel = i
mask = None
histSize = 256
range = [0,256]
'''
hist = cv.calcHist([image], [i], None, [256], [0, 256])
plt.plot(hist, color=color)
plt.xlim([0, 256])
plt.show()
每个通道的直方图