runSaliency - compute and display saliency map and fixations. runSaliency(inputImage,saliencyParams) Runs a demonstration of the entire process of computing the saliency map, winner-take-all evolution with inhibition of return, shape estimation, and fixation to the attended region. inputImage: the file name of the image relative to IMG_DIR, or the image data themselves, or an initialized Image structure (see initializeImage); saliencyParams: the saliency parameter set for the operations. runSaliency(inputImage) Uses defaultSaliencyParams as parameters. See also guiSaliency, batchSaliency, initializeGlobal, initializeImage, makeSaliencyMap, initializeWTA, evolveWTA, applyIOR, estimateShape, dataStructures, defaultSaliencyParams.
0001 % runSaliency - compute and display saliency map and fixations. 0002 % 0003 % runSaliency(inputImage,saliencyParams) 0004 % Runs a demonstration of the entire process of computing 0005 % the saliency map, winner-take-all evolution with 0006 % inhibition of return, shape estimation, and fixation 0007 % to the attended region. 0008 % inputImage: the file name of the image relative to IMG_DIR, 0009 % or the image data themselves, 0010 % or an initialized Image structure (see initializeImage); 0011 % saliencyParams: the saliency parameter set for the operations. 0012 % 0013 % runSaliency(inputImage) 0014 % Uses defaultSaliencyParams as parameters. 0015 % 0016 % See also guiSaliency, batchSaliency, initializeGlobal, initializeImage, 0017 % makeSaliencyMap, initializeWTA, evolveWTA, applyIOR, estimateShape, 0018 % dataStructures, defaultSaliencyParams. 0019 0020 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2007 0021 % by Dirk B. Walther and the California Institute of Technology. 0022 % See the enclosed LICENSE.TXT document for the license agreement. 0023 % More information about this project is available at: 0024 % http://www.saliencytoolbox.net 0025 0026 function runSaliency(inputImage,varargin) 0027 0028 declareGlobal; 0029 0030 % initialize the Image structure if necessary 0031 if (isa(inputImage,'struct')) 0032 img = inputImage; 0033 else 0034 img = initializeImage(inputImage); 0035 end 0036 0037 % check that image isn't too huge 0038 img = checkImageSize(img,'Prompt'); 0039 0040 % use the default saliency parameters if the user didn't specify any 0041 if isempty(varargin) 0042 params = defaultSaliencyParams(img.size,'dyadic'); 0043 else 0044 params = varargin{1}; 0045 end 0046 0047 % make sure that we don't use color features if we don't have a color image 0048 if (img.dims == 2) 0049 params = removeColorFeatures(params); 0050 end 0051 0052 % create the saliency map 0053 [salmap,salData] = makeSaliencyMap(img,params); 0054 0055 % display the conspicuity maps 0056 figure('Name','STB: conspicuity maps','NumberTitle','off'); 0057 displayMaps({salData.CM},2); 0058 0059 % initialize the winner-take-all network 0060 wta = initializeWTA(salmap,params); 0061 0062 % display the input image 0063 imgFig = showImage(img); 0064 0065 % display the current WTA 0066 salFig = figure('Name','STB: Saliency Map and WTA','NumberTitle','off'); 0067 wtaMap = emptyMap(img.size(1:2),'Winner Take All'); 0068 wtaMap.data = imresize(wta.sm.V,img.size(1:2),'bilinear'); 0069 displayMaps([salmap,wtaMap],1); 0070 0071 shapeFig = -1; 0072 lastWinner = [-1,-1]; 0073 reply = ''; 0074 0075 % loop over the successive fixations, until user enters 'q' or 'Q' 0076 while (~strcmp(reply,'q') & ~strcmp(reply,'Q')) 0077 winner = [-1,-1]; 0078 0079 % evolve WTA until we have a winner 0080 while (winner(1) == -1) 0081 [wta,winner] = evolveWTA(wta); 0082 end 0083 0084 % update the WTA plot 0085 figure(salFig); 0086 wtaMap = emptyMap(img.size(1:2),'Winner Take All'); 0087 wtaMap.data = imresize(wta.sm.V,img.size(1:2),'bilinear'); 0088 displayMaps([salmap,wtaMap],1); 0089 0090 % run the shape estimator to get proro-objects 0091 shapeData = estimateShape(salmap,salData,winner,params); 0092 0093 % trigger inhibition of return 0094 wta = applyIOR(wta,winner,params,shapeData); 0095 0096 % convert the winner's location to image coordinates 0097 win2 = winnerToImgCoords(winner,params); 0098 0099 % plot the currently attended region into the image figure 0100 figure(imgFig); 0101 plotSalientLocation(win2,lastWinner,img,params,shapeData); 0102 0103 lastWinner = win2; 0104 0105 % in case we have shape data, create a plot 0106 % to display various processing steps 0107 if ~isempty(shapeData) 0108 0109 % need to open a new figure or use the previous one? 0110 if (shapeFig == -1) 0111 shapeFig = figure('Name','STB: shape maps','NumberTitle','off'); 0112 else 0113 figure(shapeFig); 0114 end 0115 0116 % draw the various maps 0117 displayMaps({shapeData.winningMap,shapeData.segmentedMap,... 0118 shapeData.binaryMap,shapeData.shapeMap}); 0119 0120 % find the right label for the figure window 0121 winLabel = [' - ' shapeData.winningMap.label]; 0122 if any(isnan(img.filename)) 0123 lab = winLabel; 0124 else 0125 lab = [img.filename winLabel]; 0126 end 0127 set(imgFig,'Name',lab); 0128 else 0129 winLabel = ''; 0130 end 0131 0132 % make sure everything gets drawn 0133 drawnow; 0134 0135 % write out the details for our winner 0136 txt = sprintf('winner: %i,%i; t = %4.1f ms%s',... 0137 win2(2),win2(1),wta.exc.time*1000,winLabel); 0138 0139 % wait for user input - return for next fixation, 'q' to terminate 0140 reply = input(txt,'s'); 0141 end