【OpenCV4】图像直方图生成函数calcHist()使用详解

calcHist() 函数有 3 个构造函数

第一个构造函数:

calcHist() [1/3]
void cv::calcHist	(	const Mat * 	images,
int 	nimages,
const int * 	channels,
InputArray 	mask,
OutputArray 	hist,
int 	dims,
const int * 	histSize,
const float ** 	ranges,
bool 	uniform = true,
bool 	accumulate = false 
)		

参数说明:

images
一组图片数据,需要有相同的位深,相同的尺寸大小。但是通道数可以不同。
Source arrays. They all should have the same depth, CV_8U, CV_16U or CV_32F , and the same size. Each of them can have an arbitrary number of channels.

nimages
该组图片的数量。
Number of source images.

channels
通道列表,对应每张图片选择那个通道进行直方图的计算。
List of the dims channels used to compute the histogram. The first array channels are numerated from 0 to images[0].channels()-1 , the second array channels are counted from images[0].channels() to images[0].channels() + images[1].channels()-1, and so on.

mask
可选。尺寸和图片尺寸相同,位深 8-bit。掩膜内非 0 元素对应的区域会被统计进直方图。
Optional mask. If the matrix is not empty, it must be an 8-bit array of the same size as images[i] . The non-zero mask elements mark the array elements counted in the histogram.

hist
输出直方图
Output histogram, which is a dense or sparse dims -dimensional array.

dims
直方图的维度数量。比较常见的统计一个通道的直方图,会设置成 1。最大值为 32,即 OpenCV 中纬度最大值。
Histogram dimensionality that must be positive and not greater than CV_MAX_DIMS (equal to 32 in the current OpenCV version).

histSize
直方图尺寸。直方图在每一个维度上的大小。即在某个维度上分段个数,如果把 0~255 每个像素分成一段,那总共有 256 段,该值为 256。
Array of histogram sizes in each dimension.

ranges
每个维度上的边界。histSize确定的是分割成几段,ranges确定的是选择范围。比如上面分成了 256 段,ranges 设置成 [0, 255] 即可。注意这里的数据类型有 2 个 * 号,表示这是一个数组的数组,可以理解为 [[0, 255], [0, 255], [1, 254]...] 这样的形式。
如果histSize设置成 256,ranges 设置成 [0, 50],会增加很多 0 的插值,为了把 51 个灰阶分成 256 段。
Array of the dims arrays of the histogram bin boundaries in each dimension. When the histogram is uniform ( uniform =true), then for each dimension i it is enough to specify the lower (inclusive) boundary L0 of the 0-th histogram bin and the upper (exclusive) boundary UhistSize[i]−1 for the last histogram bin histSize[i]-1 . That is, in case of a uniform histogram each of ranges[i] is an array of 2 elements. When the histogram is not uniform ( uniform=false ), then each of ranges[i] contains histSize[i]+1 elements: L0,U0=L1,U1=L2,…,UhistSize[i]−2=LhistSize[i]−1,UhistSize[i]−1 . The array elements, that are not between L0 and UhistSize[i]−1 , are not counted in the histogram.

uniform
数据一致的标志位。当为 true 的时候,ranges 的范围是 0 ~ histSize-1。
Flag indicating whether the histogram is uniform or not (see above).

accumulate
用于从多个图片数组计算直方图的标志位,有迭代跟新效果。通常设置为 false。
Accumulation flag. If it is set, the histogram is not cleared in the beginning when it is allocated. This feature enables you to compute a single histogram from several sets of arrays, or to update the histogram in time.

第二个构造函数:

void cv::calcHist	(	const Mat * 	images,
int 	nimages,
const int * 	channels,
InputArray 	mask,
SparseMat & 	hist,
int 	dims,
const int * 	histSize,
const float ** 	ranges,
bool 	uniform = true,
bool 	accumulate = false 
)		

第三个构造函数:

void cv::calcHist	(	InputArrayOfArrays 	images,
const std::vector< int > & 	channels,
InputArray 	mask,
OutputArray 	hist,
const std::vector< int > & 	histSize,
const std::vector< float > & 	ranges,
bool 	accumulate = false 
)	
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值