Home > SaliencyToolbox > initializeImage.m

initializeImage

PURPOSE ^

initializeImage - initializes an image structure.

SYNOPSIS ^

function [Img,err] = initializeImage(varargin);

DESCRIPTION ^

 initializeImage - initializes an image structure.

 [Image,err] = initializeImage(filename);
    Initializes an Image structure given an image file name.
    If there is an error in reading the file, it is returned
    in err.

 Image = initializeImage(imgData);
    Initialize an Image structure with the image
    content instead of the file name.

 [Image,err] = initializeImage(filename,imgData);
    Initialize an Image structure with both the image
    content and the file name.

 [Image,err] = initializeImage(...,type);
    Gives Image the text label type. Default is 'unknown'.

 The Image structure has the following members:
   filename - the filename 
   data - the actual content of the image
          Each image structure has to contain the filename or the data
          field. It can have both.
   type - some text label
   size - the size of the image
   dims - the number of dimensions of the image (2 or 3)
   date - the time and date this structure was created

 See also dataStructures.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % initializeImage - initializes an image structure.
0002 %
0003 % [Image,err] = initializeImage(filename);
0004 %    Initializes an Image structure given an image file name.
0005 %    If there is an error in reading the file, it is returned
0006 %    in err.
0007 %
0008 % Image = initializeImage(imgData);
0009 %    Initialize an Image structure with the image
0010 %    content instead of the file name.
0011 %
0012 % [Image,err] = initializeImage(filename,imgData);
0013 %    Initialize an Image structure with both the image
0014 %    content and the file name.
0015 %
0016 % [Image,err] = initializeImage(...,type);
0017 %    Gives Image the text label type. Default is 'unknown'.
0018 %
0019 % The Image structure has the following members:
0020 %   filename - the filename
0021 %   data - the actual content of the image
0022 %          Each image structure has to contain the filename or the data
0023 %          field. It can have both.
0024 %   type - some text label
0025 %   size - the size of the image
0026 %   dims - the number of dimensions of the image (2 or 3)
0027 %   date - the time and date this structure was created
0028 %
0029 % See also dataStructures.
0030 
0031 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0032 % by Dirk B. Walther and the California Institute of Technology.
0033 % See the enclosed LICENSE.TXT document for the license agreement.
0034 % More information about this project is available at:
0035 % http://www.saliencytoolbox.net
0036 
0037 function [Img,err] = initializeImage(varargin);
0038 
0039 declareGlobal;
0040 err = [];
0041 
0042 if (nargin < 1)
0043   error('Must have at least one argument!');
0044 elseif (nargin < 2)
0045   switch class(varargin{1})
0046     case 'char'
0047       Img.filename = varargin{1};
0048       Img.data = NaN;
0049       Img.type = 'unknown';
0050     case {'uint8','double'}
0051       Img.filename = NaN;
0052       Img.data = varargin{1};
0053       Img.type = 'unknown';
0054     otherwise
0055       error(['Don''t know how to handle data of class' class(varargin{1})]);
0056   end
0057 elseif (nargin < 3)
0058   switch class(varargin{1})
0059     case 'char'
0060       Img.filename = varargin{1};
0061       switch class(varargin{2})
0062         case 'char'
0063           Img.data = NaN;
0064           Img.type = varargin{2};
0065         case {'uint8','double'}
0066           Img.data = varargin{2};
0067           Img.type = 'unknown';
0068         otherwise
0069           error('Don''t know how to handle image data of class %s.',class(varargin{2}));  
0070       end
0071       
0072     case {'uint8','double'}
0073       Img.filename = NaN;
0074       Img.data = varargin{1};
0075       Img.type = varargin{2};
0076       
0077     otherwise
0078       error(['Don''t know how to handle data of class' class(varargin{1})]);
0079   end
0080 else
0081   Img.filename = varargin{1};
0082   Img.data = varargin{2};
0083   Img.type = varargin{3};
0084 end
0085 
0086 if (isnan(Img.data))
0087   try
0088     im = imread(Img.filename);
0089   catch
0090     Img = [];
0091     err = lasterror;
0092     if (nargout < 2)
0093       rethrow(err);
0094     end
0095     return;
0096   end
0097   Img.data = im;
0098   Img.size = size(im);
0099 else
0100   Img.size = size(Img.data);
0101 end
0102 
0103 Img.dims = length(Img.size);
0104 Img.date = clock;

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005