Home > mfiles > displayImage.m

displayImage

PURPOSE ^

displayImage - displays an image in a convenient way in the current axes.

SYNOPSIS ^

function displayImage(img,doNormalize)

DESCRIPTION ^

 displayImage - displays an image in a convenient way in the current axes.

 displayImage(img) - displays image in a new window
    img can be of any numerical type or a logical, and it
        must have two (gray-scale) or three (RGB) dimensions.
    img can be an Image structure (see initializeImage).
    The image is scaled appropriately.

 displayImage(img,doNormalize)
    If doNormalize is 1, the image is maximum-normalized 
    (default: 0).

 See also displayMap, displayMaps, showImage, initializeImage, dataStructures.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % displayImage - displays an image in a convenient way in the current axes.
0002 %
0003 % displayImage(img) - displays image in a new window
0004 %    img can be of any numerical type or a logical, and it
0005 %        must have two (gray-scale) or three (RGB) dimensions.
0006 %    img can be an Image structure (see initializeImage).
0007 %    The image is scaled appropriately.
0008 %
0009 % displayImage(img,doNormalize)
0010 %    If doNormalize is 1, the image is maximum-normalized
0011 %    (default: 0).
0012 %
0013 % See also displayMap, displayMaps, showImage, initializeImage, dataStructures.
0014 
0015 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2007
0016 % by Dirk B. Walther and the California Institute of Technology.
0017 % See the enclosed LICENSE.TXT document for the license agreement.
0018 % More information about this project is available at:
0019 % http://www.saliencytoolbox.net
0020 
0021 function displayImage(img,doNormalize)
0022 
0023 if (nargin < 2)
0024   doNormalize = 0;
0025 end
0026 
0027 if (isa(img,'struct'))
0028   displayImage(loadImage(img),doNormalize);
0029   return;
0030 end
0031 
0032 if (isa(img,'logical'))
0033   img = double(img);
0034 end
0035 
0036 if (~isa(img,'double'))
0037   img = im2double(img);
0038 end
0039 
0040 img = squeeze(img);
0041 num_dims = length(size(img));
0042 
0043 if ((num_dims ~= 2) & (num_dims ~= 3))
0044   disp([mfilename ' error - unknown image format: ' class(img)]);
0045   return;
0046 end
0047 
0048 mx = max(img(:));
0049 mn = min(img(:));
0050 
0051 if (doNormalize & (mx > mn))
0052   img = mat2gray(img);
0053   %img = (img - mn) / (mx - mn);
0054 end
0055 
0056 if (num_dims == 2)
0057   % gray scale image -> RGB
0058   img = reshape(img,size(img,1),size(img,2),1);
0059   img(:,:,2) = img(:,:,1);
0060   img(:,:,3) = img(:,:,1);
0061 end
0062 
0063 mx = max(max(max(img))); mn = min(min(min(img)));
0064 if ((mx > 1.0) | (mn < 0.0))
0065   disp('showImage.m: image out of range 0.0 ... 1.0');
0066   fprintf('(max: %g; min: %g)\n',mx,mn);
0067   disp ('cutting off ...');
0068   img(find(img > 1.0)) = 1.0;
0069   img(find(img < 0.0)) = 0.0;
0070 end
0071 
0072 % display the RGB image
0073 image(img);
0074 axis image;

Generated on Fri 07-Sep-2007 14:42:18 by m2html © 2003