Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate image histogram of 32bit floating point image in OPenCV

I want to calculate histogram of an image hows pixels are of type 32F (32 bit floating point). What should be the parameter values of "calcHist" function for: - dims - bins - range

like image 206
user3319734 Avatar asked Dec 14 '25 06:12

user3319734


1 Answers

Well I've done this many times. Something like so:

cv::Mat matSrc;    // this is a CV_32FC1 normalised image

int nHistSize = 65536;
float fRange[] = { 0.0f, 1.0f };
const float* fHistRange = { fRange };

cv::Mat matHist;
cv::calcHist(&matSrc, 1, 0, cv::Mat(), matHist, 1, &nHistSize, &fHistRange);

As it says in the documentation describing the source arrays:

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.

So CV_32F is supported. In this situation, the range (in my example 0.0 to 1.0) is binned into the number of bins required (in my example 65536).

like image 78
Roger Rowland Avatar answered Dec 16 '25 22:12

Roger Rowland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!