batchSaliency - batch processing of lists of images. salMaps = batchSaliency(images) Computes the saliency maps for a number of images. images can be one of the following: - a vector of Image structures as obtained from initializeImage - a cell array of file names of image files - the name of a directory - using all image files in that directory [salMaps,fixations] = batchSaliency(images,numFixations) Computes the saliency maps and the coordinates of the first numFixations fixations. fixations is a cell array with one cell for each image. Each cell is of size numFixations x 2. [salMaps,fixations] = batchSaliency(images,numFixations,params) Uses params as the saliency parameters. By default, the parameters from defaultSaliencyParams are used. See also initializeImage, makeSaliencyMap, defaultSaliencyParams, runSaliency, dataStructures.
0001 % batchSaliency - batch processing of lists of images. 0002 % 0003 % salMaps = batchSaliency(images) 0004 % Computes the saliency maps for a number of images. 0005 % images can be one of the following: 0006 % - a vector of Image structures as obtained from initializeImage 0007 % - a cell array of file names of image files 0008 % - the name of a directory - using all image files 0009 % in that directory 0010 % 0011 % [salMaps,fixations] = batchSaliency(images,numFixations) 0012 % Computes the saliency maps and the coordinates of the first 0013 % numFixations fixations. fixations is a cell array with one cell 0014 % for each image. Each cell is of size numFixations x 2. 0015 % 0016 % [salMaps,fixations] = batchSaliency(images,numFixations,params) 0017 % Uses params as the saliency parameters. By default, the parameters 0018 % from defaultSaliencyParams are used. 0019 % 0020 % See also initializeImage, makeSaliencyMap, defaultSaliencyParams, 0021 % runSaliency, dataStructures. 0022 0023 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2008 0024 % by Dirk B. Walther and the California Institute of Technology. 0025 % See the enclosed LICENSE.TXT document for the license agreement. 0026 % More information about this project is available at: 0027 % http://www.saliencytoolbox.net 0028 0029 function [salMaps,fixations] = batchSaliency(images,numFixations,params) 0030 0031 if (nargin < 2) 0032 numFixations = 0; 0033 end 0034 0035 if (nargin < 3) 0036 params = defaultSaliencyParams; 0037 end 0038 0039 % convert images input argument into Image structures 0040 switch class(images) 0041 case 'cell' 0042 imgList = []; 0043 for f = 1:length(images) 0044 [imgStruct,err] = initializeImage(images{f}); 0045 if isempty(err) 0046 imgList = [imgList imgStruct]; 0047 else 0048 fprintf(['Error reading image file ' images{f} ': ' err.message ' = skipping\n']); 0049 end 0050 end 0051 fprintf('Found %d images.\n',length(imgList)); 0052 case 'struct' 0053 imgList = images; 0054 case 'char' 0055 d = dir(images); 0056 imgFiles = {d(~[d.isdir]).name}; 0057 if isempty(imgFiles) 0058 fprintf(['No image files found in ' images '\n']); 0059 salMaps = []; fixations = {}; 0060 return; 0061 end 0062 imgList = []; 0063 for f = 1:length(imgFiles) 0064 [imgStruct,err] = initializeImage(fullfile(images,imgFiles{f})); 0065 if isempty(err) 0066 imgList = [imgList imgStruct]; 0067 end 0068 end 0069 fprintf('Found %d images.\n',length(imgList)); 0070 otherwise 0071 error(['Type ' class(images) 'not valid for images input argument.']); 0072 end 0073 0074 % loop over all images 0075 numImg = length(imgList); 0076 fixations = {}; 0077 for f = 1:numImg 0078 fprintf('Processing image %d of %d: computing saliency map ...',f,numImg); 0079 0080 % make sure that we don't use color features if we don't have a color image 0081 myParams = params; 0082 if (imgList(f).dims == 2) 0083 myParams = removeColorFeatures(myParams); 0084 end 0085 0086 % compute the saliency map 0087 [salMaps(f),salData] = makeSaliencyMap(imgList(f),myParams); 0088 0089 % need to compute fixations? 0090 if (numFixations > 0) 0091 fprintf(' computing %d fixations ',numFixations); 0092 wta = initializeWTA(salMaps(f),myParams); 0093 0094 % loop over the fixations 0095 for fix = 1:numFixations 0096 0097 % evolve WTA until we have the next winner 0098 winner = [-1,-1]; 0099 while(winner(1) == -1) 0100 [wta,winner] = evolveWTA(wta); 0101 end 0102 fprintf('.'); 0103 0104 % get shape data and apply inhibition of return 0105 shapeData = estimateShape(salMaps(f),salData,winner,myParams); 0106 wta = applyIOR(wta,winner,myParams,shapeData); 0107 0108 % convert the winner to image coordinates 0109 fixations{f}(fix,:) = winnerToImgCoords(winner,myParams); 0110 end 0111 end 0112 fprintf(' done.\n'); 0113 end 0114