直方圖最需要理解的是伞辛,bin大小和,range范圍即可夯缺。
bin的數(shù)目往往是range的最大值蚤氏。
def plot_demo(image):
"""
matplotlib里面的函數(shù)
ravel(),即對(duì)image的矩陣進(jìn)行拷貝踊兜,對(duì)其修改竿滨,原矩陣也會(huì)變化
bins = 256
range = [0,256]
"""
plt.hist(image.ravel(), 256, [0, 256])
plt.show("直方圖")
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()