Ask Your Question
0

Why does OpenCV calcHistDemo differ from other histogram generators

asked 2019-12-12 05:11:15 -0600

Jaleks gravatar image

Using the OpenCV calcHistDemo the generated histogram differs from every other (matplotlib, Gimp, Geeqie) histogram I checked against. As you can see below, the blue part in OpenCV is shifted to the left and lower than in the other versions.

Why does the OpenCV version differ?

histogram comparisons:

differences

Base file:

base .png file

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2019-12-12 08:32:09 -0600

kbarni gravatar image

In the OpenCV RGB histogram the three channels are individually scaled between 0..histimage.rows (see the three normalize() lines). As the blue has a lot of saturated values in the sky (255), it will be scaled lower in the histogram.

You can correct this by getting the global maximum (the highest value of r_hist, g_hist and b_hist) and using this value to normalize the three histograms using this value:

b_hist=b_hist*histimage.rows/global_max;
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-12-12 05:11:15 -0600

Seen: 136 times

Last updated: Dec 12 '19