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 - all files in that directory are assumed to be images [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 - all files in that directory are assumed 0009 % to be images 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-2007 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 for f = 1:length(images) 0043 [imgStruct,err] = initializeImage(images{f}); 0044 if isempty(err) 0045 imgList(f) = imgStruct; 0046 else 0047 fatal(['Error reading image file ' images{f} ': ' err.message]); 0048 end 0049 end 0050 case 'struct' 0051 imgList = images; 0052 case 'char' 0053 d = dir(images); 0054 imgFiles = {d(~[d.isdir]).name}; 0055 if isempty(imgFiles) 0056 fatal(['No image files found in ' images]); 0057 end 0058 for f = 1:length(imgFiles) 0059 [imgStruct,err] = initializeImage(fullfile(images,imgFiles{f})); 0060 if isempty(err) 0061 imgList(f) = imgStruct; 0062 else 0063 fatal(['Error reading image file ' images{f} ': ' err.message]); 0064 end 0065 end 0066 otherwise 0067 fatal(['Type ' class(images) 'not valid for images input argument.']); 0068 end 0069 0070 % loop over all images 0071 numImg = length(imgList); 0072 fixations = {}; 0073 for f = 1:numImg 0074 fprintf('Processing image %d of %d: computing saliency map ...',f,numImg); 0075 0076 % make sure that we don't use color features if we don't have a color image 0077 myParams = params; 0078 if (imgList(f).dims == 2) 0079 myParams = removeColorFeatures(myParams); 0080 end 0081 0082 % compute the saliency map 0083 [salMaps(f),salData] = makeSaliencyMap(imgList(f),myParams); 0084 0085 % need to compute fixations? 0086 if (numFixations > 0) 0087 fprintf(' computing %d fixations ',numFixations); 0088 wta = initializeWTA(salMaps(f),myParams); 0089 0090 % loop over the fixations 0091 for fix = 1:numFixations 0092 0093 % evolve WTA until we have the next winner 0094 winner = [-1,-1]; 0095 while(winner(1) == -1) 0096 [wta,winner] = evolveWTA(wta); 0097 end 0098 fprintf('.'); 0099 0100 % get shape data and apply inhibition of return 0101 shapeData = estimateShape(salMaps(f),salData,winner,myParams); 0102 wta = applyIOR(wta,winner,myParams,shapeData); 0103 0104 % convert the winner to image coordinates 0105 fixations{f}(fix,:) = winnerToImgCoords(winner,myParams); 0106 end 0107 end 0108 fprintf(' done.\n'); 0109 end 0110