/*************************************************************************** * Func: auto_contrast_stretch * * * * Desc: performs basic contrast stretching on an image * * * * Params: source - pointer to source image * * cols - number of columns in the image * * rows - height of image * ***************************************************************************/ void auto_contrast_stretch(image_ptr source, int cols, int rows) { long i; /* loop variable */ long number_of_pixels; /* total number of pixels in image */ long histogram[256]; /* image histogram */ unsigned char LUT[256]; /* Look-up table for point process */ int lowthresh, highthresh; /* lower and upper thresholds */ float scale_factor; /* scaling factor for contrast stretch */ /* compute histogram */ number_of_pixels = (long)cols * rows; for(i=0; i<256; i++) histogram[i]=0; for(i=0; i0; i--) if(histogram[i]) { highthresh = i; break; } printf("Low threshold is %d High threshold is %d\n", lowthresh,highthresh); /* compute new LUT */ for(i=0; ihighthresh; i--) LUT[i]=255; scale_factor = 255.0 / (highthresh-lowthresh); for(i=lowthresh; i<=highthresh; i++) LUT[i]=(unsigned char)((i - lowthresh) * scale_factor); /* transfer new image */ for(i=0; i