美文网首页
2018-03-16 直方图基本函数

2018-03-16 直方图基本函数

作者: JavenYang | 来源:发表于2018-03-16 18:16 被阅读0次

    1、直方图计算  ——  calcHist()

    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  )

    共有10个参数,各参数说明如下:

    images:源图像,注意这里的格式是const Mat*,也就是说,你要传入一个地址,传入的可以是一张图片也可以是多张图片,要求具有同深度同尺寸。

    nimages:输入图像的个数。

    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位且和image[i]尺寸相同。

    hist:输出的直方图,二维数组。

    dims:需要统计的直方图维度(特征数目),必须是正数,且不大于CV_MAX_DIMS(这个版本opencv3.1里面是32)

    histSize:存放每个维度的直方图尺寸的数组。

    ranges:每一维数值的取值范围。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:表示直方图是否均匀。

    accumulate:累计标识符,若为ture,直方图在配置阶段不会被清零。

    2、寻找最值  ——  minMaxLoc()

    函数的作用就是再数组里面找到全局最大值和最小值。且这个函数对多通道的数组无效,因此多通道的要转化为单通道再来使用。

    void cv::minMaxLoc ( InputArray src,  double *  minVal,   double *  maxVal = 0,

                                              Point *  minLoc = 0,  Point *  maxLoc = 0,  InputArray  mask = noArray() 

    6个参数:

        src:输入单通道数组(图像)   

        minVal:指向最大值的指针

        maxVal:指向最小值的指针

        minLoc:最小值位置的指针(二维下)   

        maxLoc:最大值位置的指针(二维下)   

        Mask:掩膜

    3、直方图归一化  ——  normalize()

    void cv::normalize (InputArray src,   InputOutputArray  dst,  double  alpha = 1,  double  beta = 0,

                                          int  norm_type = NORM_L2,   int  dtype = -1,   InputArray  mask = noArray() )              

    7个参数:

        src :输入数组

        Dst:输出数组(支持原地运算)

        Alpha:range normalization模式的最小值

        Beta:range normalization模式的最大值,不用于norm normalization(范数归一化)模式。

        normType:归一化的类型,可以有以下的取值:

            NORM_MINMAX:数组的数值被平移或缩放到一个指定的范围,线性归一化,一般较常用。

            NORM_INF: 此类型的定义没有查到,根据OpenCV 1的对应项,可能是归一化数组的C-范数(绝对值的最大值)

            NORM_L1 :  归一化数组的L1-范数(绝对值的和)

            NORM_L2: 归一化数组的(欧几里德)L2-范数

        Dtype:dtype为负数时,输出数组的type与输入数组的type相同;否则,输出数组与输入数组只是通道数相同,而tpye=CV_MAT_DEPTH(dtype).

        Mask:操作掩膜,用于指示函数是否仅仅对指定的元素进行操作。

    相关文章

      网友评论

          本文标题:2018-03-16 直方图基本函数

          本文链接:https://www.haomeiwen.com/subject/lkqrqftx.html