How to calculate histogram using every nth pixel opencv

asked 2015-04-22 01:40:12 -0500

asanka gravatar image

I'm using this opencv function for calculate the histogram(For blue color).

calcHist( &bgr_planes[0], 1, 0, Mat(), b_hist, 1, &histSize, &histRange, uniform, accumulate );

Here we use all pixels in the image for calculate the histogram. Assume that I need to calculate the histogram using every 10th pixel or 100th pixel. Is there an efficient way to do this? I need to do this because I think it may increase the performances in histogram calculation even though some details are lossed.

edit retag flag offensive close merge delete


I dont think you can choose pixels from images to be used to calculate Histogram. You can select every nth pixel as per your requirement and save it to seperate image. Its histogram is what you are looking for. Hope this helps!

tomnjerry gravatar imagetomnjerry ( 2015-04-22 01:44:54 -0500 )edit

" I need to do this because I think it may increase the performances" - i very much doubt so.

also, this "every n'th pixel" sampling has problem of its own, since wou will miss peaks/valleys.

berak gravatar imageberak ( 2015-04-22 02:01:37 -0500 )edit

Maybe you can resize your image and compute the histogram on the resized image ?

Eduardo gravatar imageEduardo ( 2015-04-22 07:09:36 -0500 )edit

^^ much better idea.

berak gravatar imageberak ( 2015-04-22 07:11:23 -0500 )edit