histogram: how to find bins values for certain range of data(at Y-axis)?

asked 2019-11-27 12:52:54 -0600

michlvl gravatar image

Hello,

I'm not very familar with math, not sure what exactly shoud to search (peaks not exactly what I need).

I have some histogram and I have set certain ranges of Y-axis data (values), yellow on picture:

image description

for (int i = 0; i < bins; i++)
{
    int px_qty = cvRound(hist.at<float>(i)*h / 255.0);

    if (i == 0) // white
    {
        rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
            Scalar(255, 255, 255), FILLED);
    }
    else if (i < 12 && i != 0) //red
    {
        rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
            Scalar(0, 0, 255), FILLED);
    }
    else if (i >= 12 && i < 60)//green
    {
        if (px_qty > 120) // px intencity is high enough, paint in YELLOW
        {
            rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
                Scalar(0, 255, 255), FILLED);
        }
        else // paint green
        {
            rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
                Scalar(0, 255, 0), FILLED);
        }
    }
    else if (i >= 60 && i < 100) //blue
    {
        rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
            Scalar(255, 0, 0), FILLED);
    }
    else
    {
        //white
        rectangle(histImg, Point(i*bin_w, h), Point((i + 1)*bin_w, h - px_qty),
            Scalar(255, 255, 255), FILLED);
    }
}

I know how to find "begining" of yellow range (just first match with condifition px_qty > 120 ).

But how about "end" ?

I need to know both X1 and X2:

image description

Just want to note, that during whole predefined range its possible to get some nadirs of data:

image description

But still I would like to get "last" one sample.

Regards!

edit retag flag offensive close merge delete

Comments

Any ways for solution of this problem?

michlvl gravatar imagemichlvl ( 2019-12-03 07:28:43 -0600 )edit