Results 1 to 4 of 4

Math Help - calculate percentiles from a histogram

  1. #1
    Newbie
    Joined
    Feb 2010
    Posts
    2

    calculate percentiles from a histogram

    Hi,
    I need to compute the percentile of a histogram , but I'm not sure how to accomplish that. After computing the color histogram of an image I have an 256 size arrays that contains the distribution of pixel colors (Red ,
    Green or Blue). Given a percentile , the number of pixels in the
    image :n ,my idea was first to sort the vector increasingly and than
    start adding the elements of the array until I got a sum closest to
    p*n . The index of the array where I stopped adding was considered to
    be the intensity color that matched the searched percentile. The
    thing is that I'm really not sure whether this is correct , so any hints on this would be greatly appreciated.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rantravee View Post
    Hi,
    I need to compute the percentile of a histogram , but I'm not sure how to accomplish that. After computing the color histogram of an image I have an 256 size arrays that contains the distribution of pixel colors (Red ,
    Green or Blue). Given a percentile , the number of pixels in the
    image :n ,my idea was first to sort the vector increasingly and than
    start adding the elements of the array until I got a sum closest to
    p*n . The index of the array where I stopped adding was considered to
    be the intensity color that matched the searched percentile. The
    thing is that I'm really not sure whether this is correct , so any hints on this would be greatly appreciated.
    something like:

    Code:
    ll=length(data);  %length of data set assumed a linear array
     
    data1=sort(data);  %sort the data set
     
    nn=round(ll*percentile/100); %caluclate the
                                 %index for the approximate
                                 %percentile position
    if nn<=0
      nn=1
    elseif nn>ll
      nn=ll
    end
     
     
    xx=data1(nn);  %approximate percentile
    CB
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Newbie
    Joined
    Feb 2010
    Posts
    2
    something more like this :

    [PHP]
    int calculatePercentile(int v[], int nrTotalPixeli,int procent)
    {
    int limita=(procent*nrTotalPixeli)/100;
    boolean contCond=true;
    int sum=0;
    int index=0;

    while(contCond)
    {
    sum=sum+v[index];
    if(sum>limita)
    {
    sum=sum-v[index];
    contCond=false;
    index--;
    }
    else
    {
    index++;
    }
    }

    return index
    [/PHP]
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by rantravee View Post
    something more like this :

    [php]
    int calculatePercentile(int v[], int nrTotalPixeli,int procent)
    {
    int limita=(procent*nrTotalPixeli)/100;
    boolean contCond=true;
    int sum=0;
    int index=0;

    while(contCond)
    {
    sum=sum+v[index];
    if(sum>limita)
    {
    sum=sum-v[index];
    contCond=false;
    index--;
    }
    else
    {
    index++;
    }
    }

    return index
    [/php]
    So you have a 256 element array v with the pixel count of those pixels with value n in v(n)? Then what you have looks about right-ish. Why not do a hand calculation to compare with the code result?

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. How can you calculate percentiles from a cdf?
    Posted in the Advanced Statistics Forum
    Replies: 1
    Last Post: October 28th 2009, 09:26 PM
  2. Percentiles of a continuous pdf
    Posted in the Advanced Statistics Forum
    Replies: 1
    Last Post: October 20th 2009, 04:29 PM
  3. Percentiles
    Posted in the Advanced Statistics Forum
    Replies: 5
    Last Post: May 14th 2009, 12:01 AM
  4. calculate errors in histogram
    Posted in the Statistics Forum
    Replies: 0
    Last Post: November 27th 2008, 07:09 PM
  5. percentiles... UGH
    Posted in the Algebra Forum
    Replies: 1
    Last Post: June 12th 2008, 04:08 AM

Search Tags


/mathhelpforum @mathhelpforum