gscale

PURPOSE ^

GSCALE adjusts the scale of an image.

SYNOPSIS ^

function g=gscale(f,method,low,high)

DESCRIPTION ^

 GSCALE adjusts the scale of an image.
 
 GSCALE returns the input image with the scale adjusted according to the
 input specifications.

 USAGE:
     g=gscale(f,'minmax'); adjusts the image to the default min and max of
     class of the input image
     
     g=gscale(f,'full8'); adjusts the image to a 8bit scale
 
     g=gscale(f,'full16'); adjsuts the image to a 16bit scale
 
 INPUTS:
     f: grayscale image (any class)
     method: scaling method
 
 OUTPUTS:
     g: adjusted image

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function g=gscale(f,method,low,high)
0002 % GSCALE adjusts the scale of an image.
0003 %
0004 % GSCALE returns the input image with the scale adjusted according to the
0005 % input specifications.
0006 %
0007 % USAGE:
0008 %     g=gscale(f,'minmax'); adjusts the image to the default min and max of
0009 %     class of the input image
0010 %
0011 %     g=gscale(f,'full8'); adjusts the image to a 8bit scale
0012 %
0013 %     g=gscale(f,'full16'); adjsuts the image to a 16bit scale
0014 %
0015 % INPUTS:
0016 %     f: grayscale image (any class)
0017 %     method: scaling method
0018 %
0019 % OUTPUTS:
0020 %     g: adjusted image
0021 
0022 % input error checking
0023 if ~exist('f','var') || isempty(f)
0024     error('Please Input Image');
0025 end
0026 if ~exist('method','var') || isempty(method)
0027     error('Please Specify Method');
0028 end
0029 if ~exist('low','var') || isempty(low)
0030     low=0;
0031 end
0032 if ~exist('high','var') || isempty(high)
0033     high=1;
0034 end
0035 if numel(low)>1 || numel(high)>1
0036     error('Low and High should be scalars');
0037 end
0038 if low>1 || low<0 || high>1 || high<0
0039     error('Low and High should be between 0 and 1');
0040 end
0041 
0042 g=double(f);
0043 low=double(low);
0044 high=double(high);
0045 gmin=min(g(:));
0046 gmax=max(g(:));
0047 
0048 %Adjust to [0,1]
0049 g=(g-gmin)./(gmax-gmin);
0050 
0051 
0052 switch method
0053     case 'full8'
0054         g=im2uint8(g);
0055     case 'full16'
0056         g=im2uint16(g);
0057     case 'minmax'
0058         g=g.*(high-low)+low;
0059         switch class(f)
0060             case 'uint8'
0061                 g=im2uint8(g);
0062             case 'uint16'
0063                 g=im2uint16(g);
0064             case 'double'
0065                 g=im2double(g);
0066             otherwise
0067                 error('Unsupported Format, Supported Formats: unit8, uint16, double');
0068         end
0069     otherwise
0070         error('Invalid Method');
0071 end

Generated on Sun 04-Apr-2010 17:13:59 by m2html © 2005