Ask Your Question
0

Question about histogram output.

asked 2013-03-15 23:20:53 -0600

Nihad gravatar image

I have following code to create histogram, but it gave wrong output. In the program input_vector read 100 double numbers. I want to create a histogram with bin size=5. Output is [0;0;0;0;0]. Can anybody help me to figure out the problem?

vector<double>three_dimensional_shape_retreival_Hough_Transform:: histogram_creation(vector<double> input_vector)
{

    long int i;
    long int j;

    Mat histogram_input(input_vector);

    cout<<"Histogram Input Matrix:"<<histogram_input<<endl;

    int histSize =5;

    float max_distance= *max_element(input_vector.begin(), input_vector.end());
    float min_distance= *min_element(input_vector.begin(), input_vector.end());

    cout<<"Max Element:"<<max_distance<<" "<<"Min Element:"<<min_distance<<endl;

    float range[] = { min_distance,max_distance};
    const float* histRange = { range };

    bool uniform = true;
    bool accumulate = false;

    Mat histogram_output;

    calcHist(&histogram_input,1,0, Mat(), histogram_output,1,&histSize,&histRange,uniform,accumulate);

    cout<<"Histogram Output Matrix:"<<histogram_output<<endl;
}
edit retag flag offensive close merge delete

Comments

might not be the entire solution, but :

float range[] = { min_distance, max_distance + 1 };

the upper border should be 1 higher than the max element you want in your hist

berak gravatar imageberak ( 2013-03-16 04:28:09 -0600 )edit

sorry, still output is [0;0;0;0;0]

Nihad gravatar imageNihad ( 2013-03-16 05:10:02 -0600 )edit

what are the values for min_distance, max_distance ? (e.g it might be hard to find histogram bins, if your data is in the [0..1] range)

berak gravatar imageberak ( 2013-03-16 05:25:34 -0600 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2013-03-16 05:33:44 -0600

berak gravatar image

from the docs

"images – Source arrays. They all should have the same depth, CV_8U or CV_32F"

so vector<double> is not a valid input. vector<float> should do.

edit flag offensive delete link more

Comments

Thnx. ya, you are correct. It works.

Nihad gravatar imageNihad ( 2013-03-16 05:39:44 -0600 )edit

Question Tools

Stats

Asked: 2013-03-15 23:20:53 -0600

Seen: 137 times

Last updated: Mar 16 '13