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