home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 8 / CDASC08.ISO / VRAC / CUJJUN93.ZIP / 1106082A < prev    next >
Text File  |  1993-04-08  |  1KB  |  45 lines

  1.      /*******************************************
  2.      *
  3.      *   find_cutoff_point(..
  4.      *
  5.      *   This function looks at a histogram
  6.      *   and sets a cuttoff point at a given
  7.      *   percentage of pixels.
  8.      *   For example, if percent=0.6, you
  9.      *   start at 0 in the histogram and count
  10.      *   up until you've hit 60% of the pixels.
  11.      *   Then you stop and return that pixel
  12.      *   value.
  13.      *
  14.      ********************************************/
  15.  
  16. find_cutoff_point(histogram, percent, cutoff)
  17.    unsigned long histogram[];
  18.    float    percent;
  19.    short    *cutoff;
  20. {
  21.    float  fd, fsum, sum_div;
  22.    int    i, looking;
  23.    long   lc, lr, num=0, sum=0;
  24.  
  25.    sum     = 0;
  26.    i       = 0;
  27.    lr      = (long)(ROWS);
  28.    lc      = (long)(COLS);
  29.    num     = lr*lc;
  30.    fd      = (float)(num);
  31.    while(looking){
  32.       fsum    = (float)(sum);
  33.       sum_div = fsum/fd;
  34.       if(sum_div >= percent)
  35.          looking = 0;
  36.       else
  37.          sum = sum + histogram[i++];
  38.    }  /* ends while looking */
  39.  
  40.    if(i >= 256) i = 255;
  41.    *cutoff = i;
  42.    printf("\nCutoff is %d sum=%ld", *cutoff, sum);
  43. }  /* ends find_cutoff_point */
  44.  
  45.