function stretched_image = stretch( source_image ); % STRETCH full-scale contrast stretch a bitmapped image. % OBSOLETE -- you probably want to use the built-in Matlab function IMAGESC() instead. % assumes source_image is a array of pixels which can have values from -inf to +inf. % creates image of same size with each pixel run through a linear transformation % to scale it so pixels range in value from 0 to 255, % with the darkest pixels at exactly 0.0 black, and the brightest pixels at % exactly 255. % (If you start with a uniformly distributed ("random") image % with many, many more than 256 distinct values, % then use round(stretch(image)) to convert to integers, % the histogram will be somwhat flat -- % pixels from 1 .. 254 will have the same frequencies, % but pixels 0 and 255 will only be half that many. % by David Cary 1998-02-18 brightest = max(max(source_image)); darkest = min(min(source_image)); scale = 255/(brightest-darkest); stretched_image = (source_image - darkest) .* scale; % end stretch.m