function range = getrangefromclass(I)
%GETRANGEFROMCLASS Get dynamic range of image based on its class.
%   RANGE = GETRANGEFROMCLASS(I) returns the dynamic range of the 
%   image I, based on its class type. 
%
%   Class Support
%   -------------
%   I can be uint8, uint16, int16, logical, single, or double. RANGE
%   is a two-element vector of doubles.
%
%   Note
%   ----
%   For single and double data, GETRANGEFROMCLASS returns the range [0 1],
%   to be consistent with the way double and single images are interpreted
%   in MATLAB.  For integer data, GETRANGEFROMCLASS returns the range of
%   the class. For example, if the class is uint8, the dynamic range is
%   [0 255].
%
%   Example
%   -------
%       % Get the dynamic range of an int16 image.
%       CT = dicomread('CT-MONO2-16-ankle.dcm');
%       r = getrangefromclass(CT)
%
%   See also INTMIN, INTMAX.
  
%   Copyright 1993-2004 The MathWorks, Inc.
%   $Revision: 1.1.8.1 $  $Date: 2004/08/10 01:50:44 $
  
iptchecknargin(1,1,nargin,mfilename);
iptcheckinput(I,{'uint8','uint16','int16','logical','single','double'},{}, ...
              mfilename,'I',1);

classType = class(I);

switch classType
  case 'uint8'
    range = [0 255];
  
  case 'uint16'
    range = [0 65535];

  case 'int16'
    range = [-32768 32767];
    
 otherwise
 % logical,single, or double
    range = [0 1];
end
