Histogram Normalization
When dealing with a histogram, we first need 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 represent the fraction of the total number of events assigned to the entire histogram. In
the C++ API, this can be accomplished simply using the array algebra operators and operations:
cv::Mat normalized = my_hist / my_hist.Sum();
or:
my_hist /= my_hist.Sum()
Histogram Threshold
It is also common that you wish to threshold a histogram, and (for example) throw away all bins whose
entries contain less than some minimum number of counts. Like normalization, this operation can be
accomplished without the use of any particular special histogram routine. Instead, you can use the standard
array threshold function:
cv::threshold(
my_hist, // input histogram
my_thresholded_hist, // result with all values<threshold set to zero
threshold, // cutoff value
0, // value does not matter in this case
cv::THRESH_TOZERO // threshold type
);
Finding the Most Populated Bin
In some cases, you would like to find the bins that are above some threshold, and throw away the others. In
other cases, you would like to simply find the one bin that has the most weight in it. This is particul ...