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-2007 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 fatal('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 fatal(['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 end 0071 0072 case {'uint8','double'} 0073 Img.filename = NaN; 0074 Img.data = varargin{1}; 0075 Img.type = varargin{2}; 0076 0077 otherwise 0078 fatal(['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_DIR 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 = timeString;