cv2.calcHist()和np.histogram()简要介绍

定义

  • cv2.calcHist(images, channels, mask, histSize, ranges)
  • np.histogram(input,bins)

用法

cv2.calcHist(images, channels, mask, histSize, ranges)
函数作用返回一个histSize*1的矩阵,每一个值代表了每个灰度值对应的像素点数目
images输入图像
channels进行直方图统计的通道
mask掩膜图像,默认为None
histSizebin的数目
ranges像素值范围常为 [0 256]
np.histogram(input,bins)
函数作用返回输入矩阵(或图像)的直方图对应的y轴和bin
input

输入的矩阵(或图像)

binsbin

示例

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]
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值