/************************************************************************** * Func: e_i_contrast * * * * Desc: perform ends-in contrast stretch on image * * * * Params: source - pointer to the source image * * cols - number of columns in image * * rows - number of rows in image * * low - percentage of pixels to set to 0 * * high - percentage of pixels to set to 255 * **************************************************************************/ void e_i_contrast( image_ptr source, int cols, int rows, float low, float high) { long i; /* loop variable */ long number_of_pixels; /* total number of pixels in image */ long hist[256]; /* image histogram */ unsigned char LUT[256]; /* Look-up table for final transformation */ int lowthresh, highthresh; /* lower and upper thresholds */ long runsum; /* sum used to compute thresholds */ float scale_factor; /* scaling factor to compute new LUT values */ /* calculate histogram */ number_of_pixels = (long) cols * rows; for(i=0; i<256; i++) hist[i]=0; for(i=0; i= low) { lowthresh=i; break; } } runsum=0; highthresh=255; for(i=255; i>=0; i--) { runsum += hist[i]; if((runsum*100.0/number_of_pixels) >= high) { highthresh=i; break; } } printf("Low threshold is %d High threshold is %d\n",lowthresh,highthresh); for(i=0; ihighthresh; i--) LUT[i]=255; scale_factor = 255.0 / (highthresh - lowthresh); for(i=lowthresh; i<=highthresh; i++) LUT[i]=(i - lowthresh) * scale_factor; /* transfer new image */ for(i=0; i