function g=gscale(f,varargin)
if length(varargin)==0
method='full8';
else method=varargin{1};
end
if strcmp(class(f),'double')&(max(f(:))>1 | min(f(:))<0)
f=mat2gray(f);
end
switch method
case 'full8'
g=im2uint8(mat2gray(double(f)));
case 'full16'
g=im2uint16(mat2gray(double(f)));
case 'minmax'
low = varargin{2};high = varargin{3};
if low>1 | low<0 |high>1 | high<0
error('Parameters low and high must be in the range [0,1]')
end
if strcmp(class(f),'double')
low_in=min(f(:));
high_in=max(f(:));
elseif strcmp(class(f),'uint8')
low_in=double(min(f(:)))./255;
if length(varargin)==0
method='full8';
else method=varargin{1};
end
if strcmp(class(f),'double')&(max(f(:))>1 | min(f(:))<0)
f=mat2gray(f);
end
switch method
case 'full8'
g=im2uint8(mat2gray(double(f)));
case 'full16'
g=im2uint16(mat2gray(double(f)));
case 'minmax'
low = varargin{2};high = varargin{3};
if low>1 | low<0 |high>1 | high<0
error('Parameters low and high must be in the range [0,1]')
end
if strcmp(class(f),'double')
low_in=min(f(:));
high_in=max(f(:));
elseif strcmp(class(f),'uint8')
low_in=double(min(f(:)))./255;