主要用到了matplotlib 库
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('img1.jpg',1)
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,256])
plt.show()
分别显示效果如下:
B 像素矩阵分布直方图
G像素矩阵分布直方图
R像素矩阵分布直方图
在同一张图中显示如下:
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('img1.jpg',1)
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[256],[0,256])
plt.plot(histr,color = col)
plt.xlim([0,256])
plt.show()
若要显示为填充式,则如下:
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('img1.jpg',1)
plt.hist(img.ravel(),256,[0,256])
plt.show()