定义
- cv2.calcHist(images, channels, mask, histSize, ranges)
- np.histogram(input,bins)
用法
函数作用 | 返回一个histSize*1的矩阵,每一个值代表了每个灰度值对应的像素点数目 |
images | 输入图像 |
channels | 进行直方图统计的通道 |
mask | 掩膜图像,默认为None |
histSize | bin的数目 |
ranges | 像素值范围常为 [0 256] |
函数作用 | 返回输入矩阵(或图像)的直方图对应的y轴和bin |
input | 输入的矩阵(或图像) |
bins | bin |
示例
cv2.calcHist()
import cv2
img = cv2.imread('D:/Images/Lena.jpg',0)
hist = cv2.calcHist(img,[0],None,[256],[0.0,255.0])
print(hist.shape)
>>>(256, 1)
hist效果图
np.histogram()
import numpy as np
a = np.array([22,87,5,43,56,73,55,54,11,20,51,5,79,31,27])
hist,bins = np.histogram(a,bins=[0,20,40,60,80,100])
print (hist)
print (bins)
>>>[3 4 5 2 1]
[ 0 20 40 60 80 100]