Basic Manipulations with Histograms

Now that we have this great data structure, we will naturally want to do some fun stuff with it. First let's hit some of the basics that will be used over and over; then we'll move on to some more complicated features that are used for more specialized tasks.

When dealing with a histogram, we typically just want to accumulate information into its various bins. Once we have done this, however, it is often desirable to work with the histogram in normalized form, so that individual bins will then represent the fraction of the total number of events assigned to the entire histogram:

cvNormalizeHist( CvHistogram* hist, double factor );

Here hist is your histogram and factor is the number to which you would like to normalize the histogram (which will usually be 1). If you are following closely then you may have noticed that the argument factor is a double although the internal data type of CvHistogram is always float—further evidence that OpenCV is a work in progress!

The next handy function is the threshold function:

cvThreshHist( CvHistogram* hist, double factor );

The argument factor is the cutoff for the threshold. The result of thresholding a histogram is that all bins whose value is below the threshold factor are set to 0. Recalling the image thresholding function cvThreshold(), we might say that the histogram thresholding function is analogous to calling the image threshold function with the argument threshold_type set to CV_THRESH_TOZERO. Unfortunately, ...

Get Learning OpenCV now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.