0001 function g=gscale(f,method,low,high)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
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
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