% IMWRITESC - combines images rescaling and writing into the one function
%
% Usage:   imwritesc(im,name)
%         
% Floating point image values are rescaled to the range 0-1 so that no
% overflow occurs when writing 8-bit intensity values.  The image format to
% use is determined by MATLAB from the file ending.
% If the image type is of uint8 no rescaling is performed.

% Peter Kovesi October 1999

function imwritesc(im,name)

    if strcmp(class(im), 'double')
	im = im - min(min(im));       % Offset so that min value is 0.
	im = im./(max(max(im)));      % Rescale so that max is 1.
    end
    imwrite(im,name);
