Ask Your Question
1

How can I normalize histogram?

asked 2013-06-03 18:19:19 -0600

Nihad gravatar image

updated 2013-06-03 18:31:10 -0600

berak gravatar image

I want to normalize histogram between 0 and 1. Here is my code segment. It gave all zero output. Your help highly appreciable.

int main()
{
// .....................................
float histogram_sample[1][6]={2.0,2.0,3.0,4.0,1.0,2.0};

    Mat histogram(1,6,CV_32F,(void*)histogram_sample);

    cout<<"Histogram Matrix:"<<histogram<<endl;

    int histSize = 4;
    float start=1.0;
    float end=4.0;
    float range[] = { start,end+1.0 } ;
    const float* histRange = { range };

    bool uniform = true; bool accumulate = false;

    Mat hist;

    calcHist( &histogram, 1, 0, Mat(), hist, 1, &histSize, &histRange, uniform, accumulate );

    cout<<"hist:"<<hist<<endl;

    normalize(hist, hist, 0, 1, NORM_L2, -1, Mat());

    cout<<"Normalize hist:"<<hist<<endl;

}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-06-03 18:26:38 -0600

berak gravatar image

updated 2013-06-03 18:29:52 -0600

tricky one!

you messed up alpha and beta in normalize().

try:

normalize(hist, hist, 1, 0, NORM_L2, -1, Mat());

instead


Histogram Matrix:[2, 2, 3, 4, 1, 2]
hist:[1; 3; 1; 1]
Normalize hist:[0.28867513; 0.86602539; 0.28867513; 0.28867513]
edit flag offensive delete link more

Comments

Thank you.

Nihad gravatar imageNihad ( 2013-06-03 20:15:20 -0600 )edit

Question Tools

Stats

Asked: 2013-06-03 18:19:19 -0600

Seen: 7,304 times

Last updated: Jun 03 '13