本文共 701 字,大约阅读时间需要 2 分钟。
灰度直方图概括了图像的灰度级信息,简单的来说就是每个灰度级图像中的像素个数以及占有率
import cv2import matplotlib.pyplot as pltimport numpy as npimg = cv2.imread('hand.jpg',1)ori = img.copy()color = ['b','g','r']plt.subplot(221)img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)plt.imshow(img),plt.title('original'),plt.xticks([]),plt.yticks([])plt.subplot(222)for n ,col in enumerate(color): histr = cv2.calcHist([img],[n],None,[256],[0,256]) plt.plot(histr, color=col) plt.xlim([0, 256])image = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)plt.subplot(223)plt.imshow(image,'gray'),plt.title('original'),plt.xticks([]),plt.yticks([])plt.subplot(224)hist_full = cv2.calcHist([image],[0],None,[256],[0,256])plt.plot(hist_full),plt.xlim([0,256])plt.show()
转载地址:http://chben.baihongyu.com/