histograms.rst 24.7 KB
Newer Older
1 2 3
Histograms
==========

4 5
.. highlight:: cpp

6

7

8
calcHist
9
------------
10 11
Calculates a histogram of a set of arrays.

12
.. ocv:function:: void 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 )
13

14
.. ocv:function:: void 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 )
15

16 17 18
.. ocv:pyfunction:: cv2.calcHist(images, channels, mask, histSize, ranges[, hist[, accumulate]]) -> hist

.. ocv:cfunction:: void cvCalcHist( IplImage** image, CvHistogram* hist, int accumulate=0, const CvArr* mask=NULL )
19

20
    :param images: Source arrays. They all should have the same depth,  ``CV_8U``  or  ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels.
21

22
    :param nimages: Number of source images.
23

24
    :param 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.
25

26
    :param mask: 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.
27

28
    :param hist: Output histogram, which is a dense or sparse  ``dims`` -dimensional array.
29

30
    :param dims: Histogram dimensionality that must be positive and not greater than  ``CV_MAX_DIMS`` (equal to 32 in the current OpenCV version).
31

32
    :param histSize: Array of histogram sizes in each dimension.
33

34
    :param 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  :math:`L_0`  of the 0-th histogram bin and the upper (exclusive) boundary  :math:`U_{\texttt{histSize}[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:  :math:`L_0, U_0=L_1, U_1=L_2, ..., U_{\texttt{histSize[i]}-2}=L_{\texttt{histSize[i]}-1}, U_{\texttt{histSize[i]}-1}` . The array elements, that are not between  :math:`L_0`  and  :math:`U_{\texttt{histSize[i]}-1}` , are not counted in the histogram.
35

36
    :param uniform: Flag indicating whether the histogram is uniform or not (see above).
37

38
    :param accumulate: 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.
39

40
The functions ``calcHist`` calculate the histogram of one or more
41 42 43
arrays. The elements of a tuple used to increment
a histogram bin are taken from the corresponding
input arrays at the same location. The sample below shows how to compute a 2D Hue-Saturation histogram for a color image. ::
44

45 46
    #include <opencv2/imgproc.hpp>
    #include <opencv2/highgui.hpp>
47

48
    using namespace cv;
49

50 51 52 53 54
    int main( int argc, char** argv )
    {
        Mat src, hsv;
        if( argc != 2 || !(src=imread(argv[1], 1)).data )
            return -1;
55

56
        cvtColor(src, hsv, COLOR_BGR2HSV);
57

58
        // Quantize the hue to 30 levels
59 60 61 62 63 64 65 66 67 68 69 70
        // and the saturation to 32 levels
        int hbins = 30, sbins = 32;
        int histSize[] = {hbins, sbins};
        // hue varies from 0 to 179, see cvtColor
        float hranges[] = { 0, 180 };
        // saturation varies from 0 (black-gray-white) to
        // 255 (pure spectrum color)
        float sranges[] = { 0, 256 };
        const float* ranges[] = { hranges, sranges };
        MatND hist;
        // we compute the histogram from the 0-th and 1-st channels
        int channels[] = {0, 1};
71

72 73 74 75 76 77
        calcHist( &hsv, 1, channels, Mat(), // do not use mask
                 hist, 2, histSize, ranges,
                 true, // the histogram is uniform
                 false );
        double maxVal=0;
        minMaxLoc(hist, 0, &maxVal, 0, 0);
78

79 80
        int scale = 10;
        Mat histImg = Mat::zeros(sbins*scale, hbins*10, CV_8UC3);
81

82 83 84 85 86 87 88 89 90 91
        for( int h = 0; h < hbins; h++ )
            for( int s = 0; s < sbins; s++ )
            {
                float binVal = hist.at<float>(h, s);
                int intensity = cvRound(binVal*255/maxVal);
                rectangle( histImg, Point(h*scale, s*scale),
                            Point( (h+1)*scale - 1, (s+1)*scale - 1),
                            Scalar::all(intensity),
                            CV_FILLED );
            }
92

93 94
        namedWindow( "Source", 1 );
        imshow( "Source", src );
95

96 97 98 99
        namedWindow( "H-S Histogram", 1 );
        imshow( "H-S Histogram", histImg );
        waitKey();
    }
100

101
.. note::
102

103
   * An example for creating histograms of an image can be found at opencv_source_code/samples/cpp/demhist.cpp
104

105 106
   * (Python) An example for creating color histograms can be found at opencv_source/samples/python2/color_histogram.py
   * (Python) An example illustrating RGB and grayscale histogram plotting can be found at opencv_source/samples/python2/hist.py
107

108

109
calcBackProject
110
-------------------
111 112
Calculates the back projection of a histogram.

113
.. ocv:function:: void calcBackProject( const Mat* images, int nimages, const int* channels, InputArray hist, OutputArray backProject, const float** ranges, double scale=1, bool uniform=true )
114

115
.. ocv:function:: void calcBackProject( const Mat* images, int nimages, const int* channels, const SparseMat& hist, OutputArray backProject, const float** ranges, double scale=1, bool uniform=true )
116

117
.. ocv:pyfunction:: cv2.calcBackProject(images, channels, hist, ranges, scale[, dst]) -> dst
118 119

.. ocv:cfunction:: void cvCalcBackProject( IplImage** image, CvArr* backProject, const CvHistogram* hist )
120

121
    :param images: Source arrays. They all should have the same depth,  ``CV_8U``  or  ``CV_32F`` , and the same size. Each of them can have an arbitrary number of channels.
122

123
    :param nimages: Number of source images.
124

125
    :param channels: The list of channels used to compute the back projection. The number of channels must match the histogram dimensionality. 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.
126

127
    :param hist: Input histogram that can be dense or sparse.
128

129
    :param backProject: Destination back projection array that is a single-channel array of the same size and depth as  ``images[0]`` .
130

131
    :param ranges: Array of arrays of the histogram bin boundaries in each dimension. See  :ocv:func:`calcHist` .
132

133
    :param scale: Optional scale factor for the output back projection.
134

135
    :param uniform: Flag indicating whether the histogram is uniform or not (see above).
136

137
The functions ``calcBackProject`` calculate the back project of the histogram. That is, similarly to ``calcHist`` , at each location ``(x, y)`` the function collects the values from the selected channels in the input images and finds the corresponding histogram bin. But instead of incrementing it, the function reads the bin value, scales it by ``scale`` , and stores in ``backProject(x,y)`` . In terms of statistics, the function computes probability of each element value in respect with the empirical probability distribution represented by the histogram. See how, for example, you can find and track a bright-colored object in a scene:
138 139

#.
140
    Before tracking, show the object to the camera so that it covers almost the whole frame. Calculate a hue histogram. The histogram may have strong maximums, corresponding to the dominant colors in the object.
141 142

#.
143
    When tracking, calculate a back projection of a hue plane of each input video frame using that pre-computed histogram. Threshold the back projection to suppress weak colors. It may also make sense to suppress pixels with non-sufficient color saturation and too dark or too bright pixels.
144 145 146 147

#.
    Find connected components in the resulting picture and choose, for example, the largest component.

148
This is an approximate algorithm of the
149
:ocv:func:`CamShift` color object tracker.
150

151
.. seealso:: :ocv:func:`calcHist`
152
.. _compareHist:
153

154
compareHist
Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
155
-----------
156
Compares two histograms.
Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
157

158
.. ocv:function:: double compareHist( InputArray H1, InputArray H2, int method )
159

160
.. ocv:function:: double compareHist( const SparseMat& H1,  const SparseMat& H2, int method )
161

162 163 164
.. ocv:pyfunction:: cv2.compareHist(H1, H2, method) -> retval

.. ocv:cfunction:: double cvCompareHist( const CvHistogram* hist1, const CvHistogram* hist2, int method )
165

166
    :param H1: First compared histogram.
167

168
    :param H2: Second compared histogram of the same size as  ``H1`` .
169

170
    :param method: Comparison method that could be one of the following:
171

172
            * **CV_COMP_CORREL**     Correlation
173

174
            * **CV_COMP_CHISQR**     Chi-Square
175

176 177
            * **CV_COMP_CHISQR_ALT**     Alternative Chi-Square

178
            * **CV_COMP_INTERSECT**     Intersection
179

180
            * **CV_COMP_BHATTACHARYYA**     Bhattacharyya distance
181

182
            * **CV_COMP_HELLINGER**     Synonym for ``CV_COMP_BHATTACHARYYA``
183

184 185
            * **CV_COMP_KL_DIV**     Kullback-Leibler divergence

186
The functions ``compareHist`` compare two dense or two sparse histograms using the specified method:
187

188
* Correlation (``method=CV_COMP_CORREL``)
189

190
    .. math::
191 192 193

        d(H_1,H_2) =  \frac{\sum_I (H_1(I) - \bar{H_1}) (H_2(I) - \bar{H_2})}{\sqrt{\sum_I(H_1(I) - \bar{H_1})^2 \sum_I(H_2(I) - \bar{H_2})^2}}

194
    where
195

196
    .. math::
197 198 199 200

        \bar{H_k} =  \frac{1}{N} \sum _J H_k(J)

    and
201
    :math:`N`     is a total number of histogram bins.
202

203
* Chi-Square (``method=CV_COMP_CHISQR``)
204

205
    .. math::
206

207
        d(H_1,H_2) =  \sum _I  \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)}
208

209 210 211 212 213 214 215 216
* Alternative Chi-Square (``method=CV_COMP_CHISQR_ALT``)

    .. math::

        d(H_1,H_2) =  2 * \sum _I  \frac{\left(H_1(I)-H_2(I)\right)^2}{H_1(I)+H_2(I)}

    This alternative formula is regularly used for texture comparison. See e.g. [Puzicha1997]_.

217
* Intersection (``method=CV_COMP_INTERSECT``)
218

219
    .. math::
220 221

        d(H_1,H_2) =  \sum _I  \min (H_1(I), H_2(I))
222

223
* Bhattacharyya distance (``method=CV_COMP_BHATTACHARYYA`` or ``method=CV_COMP_HELLINGER``). In fact, OpenCV computes Hellinger distance, which is related to Bhattacharyya coefficient.
224

225 226
    .. math::

227
        d(H_1,H_2) =  \sqrt{1 - \frac{1}{\sqrt{\bar{H_1} \bar{H_2} N^2}} \sum_I \sqrt{H_1(I) \cdot H_2(I)}}
228

229 230 231 232 233 234
* Kullback-Leibler divergence (``method=CV_COMP_KL_DIV``).

    .. math::

        d(H_1,H_2) = \sum _I H_1(I) \log \left(\frac{H_1(I)}{H_2(I)}\right)

235 236
The function returns
:math:`d(H_1, H_2)` .
237

238
While the function works well with 1-, 2-, 3-dimensional dense histograms, it may not be suitable for high-dimensional sparse histograms. In such histograms,  because of aliasing and sampling problems, the coordinates of non-zero histogram bins can slightly shift. To compare such histograms or more general sparse configurations of weighted points, consider using the
239
:ocv:func:`EMD` function.
240 241


242

243 244 245

EMD
------
246
Computes the "minimal work" distance between two weighted point configurations.
247

248
.. ocv:function:: float EMD( InputArray signature1, InputArray signature2, int distType, InputArray cost=noArray(), float* lowerBound=0, OutputArray flow=noArray() )
249

250 251
.. ocv:cfunction:: float cvCalcEMD2( const CvArr* signature1, const CvArr* signature2, int distance_type, CvDistanceFunction distance_func=NULL, const CvArr* cost_matrix=NULL, CvArr* flow=NULL, float* lower_bound=NULL, void* userdata=NULL )

252
    :param signature1: First signature, a  :math:`\texttt{size1}\times \texttt{dims}+1`  floating-point matrix. Each row stores the point weight followed by the point coordinates. The matrix is allowed to have a single column (weights only) if the user-defined cost matrix is used.
253

254
    :param signature2: Second signature of the same format as  ``signature1`` , though the number of rows may be different. The total weights may be different. In this case an extra "dummy" point is added to either  ``signature1``  or  ``signature2`` .
255

256
    :param distType: Used metric.  ``CV_DIST_L1, CV_DIST_L2`` , and  ``CV_DIST_C``  stand for one of the standard metrics.  ``CV_DIST_USER``  means that a pre-calculated cost matrix ``cost``  is used.
257

258
    :param distance_func: Custom distance function supported by the old interface. ``CvDistanceFunction`` is defined as: ::
259

260 261
            typedef float (CV_CDECL * CvDistanceFunction)( const float* a,
                                const float* b, void* userdata );
262

263
        where ``a`` and ``b`` are point coordinates and ``userdata`` is the same as the last parameter.
264

265
    :param cost: User-defined  :math:`\texttt{size1}\times \texttt{size2}`  cost matrix. Also, if a cost matrix is used, lower boundary  ``lowerBound``  cannot be calculated because it needs a metric function.
266

267
    :param lowerBound: Optional input/output parameter: lower boundary of a distance between the two signatures that is a distance between mass centers. The lower boundary may not be calculated if the user-defined cost matrix is used, the total weights of point configurations are not equal, or if the signatures consist of weights only (the signature matrices have a single column). You  **must**  initialize  ``*lowerBound`` . If the calculated distance between mass centers is greater or equal to  ``*lowerBound``  (it means that the signatures are far enough), the function does not calculate EMD. In any case  ``*lowerBound``  is set to the calculated distance between mass centers on return. Thus, if you want to calculate both distance between mass centers and EMD,  ``*lowerBound``  should be set to 0.
268

269
    :param flow: Resultant  :math:`\texttt{size1} \times \texttt{size2}`  flow matrix:  :math:`\texttt{flow}_{i,j}`  is a flow from  :math:`i`  -th point of  ``signature1``  to  :math:`j` -th point of  ``signature2``  .
270

271
    :param userdata: Optional pointer directly passed to the custom distance function.
272

273
The function computes the earth mover distance and/or a lower boundary of the distance between the two weighted point configurations. One of the applications described in [RubnerSept98]_ is multi-dimensional histogram comparison for image retrieval. EMD is a transportation problem that is solved using some modification of a simplex algorithm, thus the complexity is exponential in the worst case, though, on average it is much faster. In the case of a real metric the lower boundary can be calculated even faster (using linear-time algorithm) and it can be used to determine roughly whether the two signatures are far enough so that they cannot relate to the same object.
274 275


276
equalizeHist
277
----------------
278 279
Equalizes the histogram of a grayscale image.

280
.. ocv:function:: void equalizeHist( InputArray src, OutputArray dst )
281

282 283 284
.. ocv:pyfunction:: cv2.equalizeHist(src[, dst]) -> dst

.. ocv:cfunction:: void cvEqualizeHist( const CvArr* src, CvArr* dst )
285

286
    :param src: Source 8-bit single channel image.
287

288
    :param dst: Destination image of the same size and type as  ``src`` .
Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
289

290 291 292
The function equalizes the histogram of the input image using the following algorithm:

#.
293 294
    Calculate the histogram
    :math:`H`     for ``src``  .
295 296

#.
297
    Normalize the histogram so that the sum of histogram bins is 255.
298 299

#.
300
    Compute the integral of the histogram:
301

302
    .. math::
303 304

        H'_i =  \sum _{0  \le j < i} H(j)
305 306

#.
307
    Transform the image using
308
    :math:`H'`     as a look-up table:
309 310
    :math:`\texttt{dst}(x,y) = H'(\texttt{src}(x,y))`

Vadim Pisarevsky's avatar
Vadim Pisarevsky committed
311
The algorithm normalizes the brightness and increases the contrast of the image.
312 313 314 315 316


Extra Histogram Functions (C API)
---------------------------------

317
The rest of the section describes additional C functions operating on ``CvHistogram``.
318 319 320 321 322 323 324

CalcBackProjectPatch
--------------------
Locates a template within an image by using a histogram comparison.

.. ocv:cfunction:: void cvCalcBackProjectPatch( IplImage** images, CvArr* dst, CvSize patch_size, CvHistogram* hist, int method, double factor )

325 326 327 328 329 330 331 332 333 334 335 336
    :param images: Source images (though, you may pass CvMat** as well).

    :param dst: Destination image.

    :param patch_size: Size of the patch slid though the source image.

    :param hist: Histogram.

    :param method: Comparison method passed to  :ocv:cfunc:`CompareHist`  (see the function description).

    :param factor: Normalization factor for histograms that affects the normalization scale of the destination image. Pass 1 if not sure.

337
The function calculates the back projection by comparing histograms of the source image patches with the given histogram. The function is similar to :ocv:func:`matchTemplate`, but instead of comparing the raster patch with all its possible positions within the search window, the function ``CalcBackProjectPatch`` compares histograms. See the algorithm diagram below:
338 339 340 341 342 343 344 345

.. image:: pics/backprojectpatch.png


CalcProbDensity
---------------
Divides one histogram by another.

346 347 348 349 350 351
.. ocv:cfunction:: void cvCalcProbDensity( const CvHistogram* hist1, const CvHistogram* hist2, CvHistogram* dst_hist, double scale=255 )

    :param hist1: First histogram (the divisor).

    :param hist2: Second histogram.

352
    :param dst_hist: Destination histogram.
353 354 355

    :param scale: Scale factor for the destination histogram.

356
The function calculates the object probability density from two histograms as:
357 358 359

.. math::

360
    \texttt{disthist} (I)= \forkthree{0}{if $\texttt{hist1}(I)=0$}{\texttt{scale}}{if $\texttt{hist1}(I) \ne 0$ and $\texttt{hist2}(I) > \texttt{hist1}(I)$}{\frac{\texttt{hist2}(I) \cdot \texttt{scale}}{\texttt{hist1}(I)}}{if $\texttt{hist1}(I) \ne 0$ and $\texttt{hist2}(I) \le \texttt{hist1}(I)$}
361 362 363 364 365 366 367 368


ClearHist
---------
Clears the histogram.

.. ocv:cfunction:: void cvClearHist( CvHistogram* hist )

369
    :param hist: Histogram.
370

371
The function sets all of the histogram bins to 0 in case of a dense histogram and removes all histogram bins in case of a sparse array.
372 373 374 375 376 377 378 379


CopyHist
--------
Copies a histogram.

.. ocv:cfunction:: void cvCopyHist( const CvHistogram* src, CvHistogram** dst )

380 381 382 383
    :param src: Source histogram.

    :param dst: Pointer to the destination histogram.

384
The function makes a copy of the histogram. If the second histogram pointer ``*dst`` is NULL, a new histogram of the same size as  ``src`` is created. Otherwise, both histograms must have equal types and sizes. Then the function copies the bin values of the source histogram to the destination histogram and sets the same bin value ranges as in ``src``.
385

386
.. _createhist:
387 388 389 390 391 392 393

CreateHist
----------
Creates a histogram.

.. ocv:cfunction:: CvHistogram* cvCreateHist( int dims, int* sizes, int type, float** ranges=NULL, int uniform=1 )

394 395 396 397 398 399 400
    :param dims: Number of histogram dimensions.

    :param sizes: Array of the histogram dimension sizes.

    :param type: Histogram representation format.  ``CV_HIST_ARRAY``  means that the histogram data is represented as a multi-dimensional dense array CvMatND.  ``CV_HIST_SPARSE``  means that histogram data is represented as a multi-dimensional sparse array ``CvSparseMat``.

    :param ranges: Array of ranges for the histogram bins. Its meaning depends on the  ``uniform``  parameter value. The ranges are used when the histogram is calculated or backprojected to determine which histogram bin corresponds to which value/tuple of values from the input image(s).
401

402
    :param uniform: Uniformity flag. If not zero, the histogram has evenly
403
        spaced bins and for every  :math:`0<=i<cDims`   ``ranges[i]``
404 405 406
        is an array of two numbers: lower and upper boundaries for the i-th
        histogram dimension.
        The whole range [lower,upper] is then split
407
        into  ``dims[i]``  equal parts to determine the  ``i``-th  input
408
        tuple value ranges for every histogram bin. And if  ``uniform=0`` ,
409
        then  the ``i``-th  element of the ``ranges``  array contains ``dims[i]+1``  elements: :math:`\texttt{lower}_0, \texttt{upper}_0,
410 411
        \texttt{lower}_1, \texttt{upper}_1 = \texttt{lower}_2,
        ...
412 413
        \texttt{upper}_{dims[i]-1}`
        where :math:`\texttt{lower}_j`  and  :math:`\texttt{upper}_j`
414
        are lower and upper
415
        boundaries of  the ``i``-th  input tuple value for  the ``j``-th
416
        bin, respectively. In either case, the input values that are beyond
417
        the specified range for a histogram bin are not counted by :ocv:cfunc:`CalcHist`  and filled with 0 by :ocv:cfunc:`CalcBackProject`.
418

419
The function creates a histogram of the specified size and returns a pointer to the created histogram. If the array ``ranges`` is 0, the histogram bin ranges must be specified later via the function  :ocv:cfunc:`SetHistBinRanges`. Though :ocv:cfunc:`CalcHist` and :ocv:cfunc:`CalcBackProject` may process 8-bit images without setting bin ranges, they assume they are equally spaced in 0 to 255 bins.
420 421 422 423 424 425 426


GetMinMaxHistValue
------------------
Finds the minimum and maximum histogram bins.

.. ocv:cfunction:: void cvGetMinMaxHistValue(  const CvHistogram* hist, float* min_value, float* max_value, int* min_idx=NULL, int* max_idx=NULL )
427

428
    :param hist: Histogram.
429 430 431 432 433 434 435 436 437

    :param min_value: Pointer to the minimum value of the histogram.

    :param max_value: Pointer to the maximum value of the histogram.

    :param min_idx: Pointer to the array of coordinates for the minimum.

    :param max_idx: Pointer to the array of coordinates for the maximum.

438
The function finds the minimum and maximum histogram bins and their positions. All of output arguments are optional. Among several extremas with the same value the ones with the minimum index (in the lexicographical order) are returned. In case of several maximums or minimums, the earliest in the lexicographical order (extrema locations) is returned.
439 440 441 442 443 444 445


MakeHistHeaderForArray
----------------------
Makes a histogram out of an array.

.. ocv:cfunction:: CvHistogram*  cvMakeHistHeaderForArray(  int dims, int* sizes, CvHistogram* hist, float* data, float** ranges=NULL, int uniform=1 )
446 447 448 449 450 451 452 453 454

    :param dims: Number of the histogram dimensions.

    :param sizes: Array of the histogram dimension sizes.

    :param hist: Histogram header initialized by the function.

    :param data: Array used to store histogram bins.

455
    :param ranges: Histogram bin ranges. See  :ocv:cfunc:`CreateHist` for details.
456

457
    :param uniform: Uniformity flag. See  :ocv:cfunc:`CreateHist` for details.
458

459 460 461 462 463 464 465
The function initializes the histogram, whose header and bins are allocated by the user. :ocv:cfunc:`ReleaseHist` does not need to be called afterwards. Only dense histograms can be initialized this way. The function returns ``hist``.

NormalizeHist
-------------
Normalizes the histogram.

.. ocv:cfunction:: void cvNormalizeHist( CvHistogram* hist, double factor )
466 467 468 469 470

    :param hist: Pointer to the histogram.

    :param factor: Normalization factor.

471
The function normalizes the histogram bins by scaling them so that the sum of the bins becomes equal to  ``factor``.
472 473 474 475 476 477 478


ReleaseHist
-----------
Releases the histogram.

.. ocv:cfunction:: void cvReleaseHist( CvHistogram** hist )
479 480 481

    :param hist: Double pointer to the released histogram.

482 483 484 485 486 487 488 489 490
The function releases the histogram (header and the data). The pointer to the histogram is cleared by the function. If ``*hist`` pointer is already ``NULL``, the function does nothing.


SetHistBinRanges
----------------
Sets the bounds of the histogram bins.

.. ocv:cfunction:: void cvSetHistBinRanges(  CvHistogram* hist, float** ranges, int uniform=1 )

491 492
    :param hist: Histogram.

493
    :param ranges: Array of bin ranges arrays. See  :ocv:cfunc:`CreateHist` for details.
494 495 496

    :param uniform: Uniformity flag. See  :ocv:cfunc:`CreateHist` for details.

497
This is a standalone function for setting bin ranges in the histogram. For a more detailed description of the parameters ``ranges`` and ``uniform``, see the :ocv:cfunc:`CalcHist` function that can initialize the ranges as well. Ranges for the histogram bins must be set before the histogram is calculated or the backproject of the histogram is calculated.
498 499 500 501 502 503 504


ThreshHist
----------
Thresholds the histogram.

.. ocv:cfunction:: void cvThreshHist( CvHistogram* hist, double threshold )
505 506 507 508 509

    :param hist: Pointer to the histogram.

    :param threshold: Threshold level.

510 511 512
The function clears histogram bins that are below the specified threshold.


513
.. [RubnerSept98] Y. Rubner. C. Tomasi, L.J. Guibas. *The Earth Mover’s Distance as a Metric for Image Retrieval*. Technical Report STAN-CS-TN-98-86, Department of Computer Science, Stanford University, September 1998.
514
.. [Puzicha1997] Puzicha, J., Hofmann, T., and Buhmann, J. *Non-parametric similarity measures for unsupervised texture segmentation and image retrieval.* In Proc. IEEE Conf. Computer Vision and Pattern Recognition, San Juan, Puerto Rico, pp. 267-272, 1997.