Home > SaliencyToolbox > guiSaliency.m

guiSaliency

PURPOSE ^

guiSaliency - a graphical user interface (GUI) version of the saliency code.

SYNOPSIS ^

function varargout = guiSaliency(varargin)

DESCRIPTION ^

 guiSaliency - a graphical user interface (GUI) version of the saliency code.

 guiSaliency
    Starts the GUI and lets you select an image via the controls.

 guiSaliency(inputImage)
    Uses inputImage as the image.
       inputImage: the filename of the image,
                   or the image data themselves,
                   or an initialized Image structure (see initializeImage).

 guiSaliency(...,saliencyParams)
    Uses the parameters specified in saliencyParams instead of the default
    parameters.

 See also runSaliency, batchSaliency, initializeImage, defaultSaliencyParams,
          guiLevelParams, dataStructures.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % guiSaliency - a graphical user interface (GUI) version of the saliency code.
0002 %
0003 % guiSaliency
0004 %    Starts the GUI and lets you select an image via the controls.
0005 %
0006 % guiSaliency(inputImage)
0007 %    Uses inputImage as the image.
0008 %       inputImage: the filename of the image,
0009 %                   or the image data themselves,
0010 %                   or an initialized Image structure (see initializeImage).
0011 %
0012 % guiSaliency(...,saliencyParams)
0013 %    Uses the parameters specified in saliencyParams instead of the default
0014 %    parameters.
0015 %
0016 % See also runSaliency, batchSaliency, initializeImage, defaultSaliencyParams,
0017 %          guiLevelParams, dataStructures.
0018 
0019 % This file is part of the SaliencyToolbox - Copyright (C) 2006-2013
0020 % by Dirk B. Walther and the California Institute of Technology.
0021 % See the enclosed LICENSE.TXT document for the license agreement.
0022 % More information about this project is available at:
0023 % http://www.saliencytoolbox.net
0024 
0025 function varargout = guiSaliency(varargin)
0026 % GUI initialization code
0027 gui_Singleton = 1;
0028 gui_State = struct('gui_Name',       mfilename, ...
0029                    'gui_Singleton',  gui_Singleton, ...
0030                    'gui_OpeningFcn', @guiSaliency_OpeningFcn, ...
0031                    'gui_OutputFcn',  @guiSaliency_OutputFcn, ...
0032                    'gui_LayoutFcn',  [], ...
0033                    'gui_Callback',   []);
0034 
0035 stack = dbstack;
0036 if nargin && ischar(varargin{1}) && ismember([mfilename '.m'],{stack(1:end-1).file})
0037   gui_State.gui_Callback = str2func(varargin{1});
0038 end
0039 
0040 if nargout
0041     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0042 else
0043     gui_mainfcn(gui_State, varargin{:});
0044 end
0045 
0046 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0047 % opening code executes just before guiSaliency is made visible.
0048 function guiSaliency_OpeningFcn(hObject, eventdata, handles, varargin)
0049 
0050 handles.output = hObject;
0051 guidata(hObject, handles);
0052 
0053 % set the close callback for the main window
0054 set(hObject,'CloseRequestFcn',@MainWindowCloseCallback);
0055 
0056 % define the needed global variables
0057 declareGlobal;
0058 global globalVars;
0059 globalVars = 'global img params state salMap salData wta lastWinner winner shapeData';
0060 eval(globalVars);
0061 state = 'NoImage';
0062 
0063 % try to use user-given image
0064 if (length(varargin) >= 1)
0065   switch class(varargin{1})
0066     case 'struct'
0067       newImg = varargin{1};
0068       err = '';
0069       state = 'ImageLoaded';
0070     case {'char','uint8','double'}
0071       [newImg,err] = initializeImage(varargin{1});
0072     otherwise
0073       err = 1;
0074   end
0075   if isempty(err)
0076     img = checkImageSize(newImg,'GUI');
0077     if isnan(img.filename)
0078       imgName = '(from input arguments)';
0079     else
0080       imgName = img.filename;
0081     end
0082     set(handles.ImageName,'String',imgName);
0083     state = 'ImageLoaded';
0084   else
0085     beep;
0086     if ischar(varargin{1})
0087       name = varargin{1};
0088     else
0089       name = 'This';
0090     end
0091     uiwait(warndlg([name ' is not a valid image!'],...
0092                    'Not a valid image','modal'));
0093   end
0094 end
0095 
0096 % use user-given parameters if given
0097 if (length(varargin) >= 2)
0098   if isstruct(varargin{2})
0099     params = varargin{2};
0100   else
0101     params = defaultSaliencyParams(img.size);
0102   end
0103 else
0104   if isempty(img);
0105     params = defaultSaliencyParams;
0106   else
0107     params = defaultSaliencyParams(img.size);
0108   end
0109 end
0110 
0111 % some more initializations
0112 setState(handles);
0113 checkColorParams(handles);
0114 fillParams(handles);
0115 initializeVisFigures(handles);
0116 updateImg(handles);
0117 updateLocImg(handles);
0118 debugMsg(sprintf('%s initialized in state: %s.',mfilename,state));
0119 
0120 % this waits until the "Quit" button is pressed
0121 uiwait(handles.figure1);
0122 
0123 % clean up
0124 cleanupVisFigures(handles);
0125 eval(['clear ' globalVars 'globalVars']);
0126 debugMsg('Global variables cleared - bye.');
0127 
0128 try
0129   delete(handles.figure1);
0130 catch
0131   % nothing to do
0132 end
0133 % that's it, bye bye.
0134 return;
0135 
0136 
0137 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0138 % Outputs from this function are returned to the command line.
0139 function varargout = guiSaliency_OutputFcn(hObject, eventdata, handles)
0140 varargout{1} = hObject;
0141 
0142 
0143 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0144 % update the GUI according to the current state
0145 function setState(h,newState)
0146 global state;
0147 if (nargin >= 2)
0148   state = newState;
0149 end
0150 
0151 debugMsg(['Setting state: ' state]);
0152 switch state
0153   case 'NoImage'
0154     set(h.figure1,'Pointer','arrow');
0155     setEnable(0,[h.Restart,h.NextLoc,h.SaveMaps]);
0156     set(h.NextLoc,'String','Start');
0157   case 'ImageLoaded'
0158     set(h.figure1,'Pointer','arrow');
0159     setEnable(0,[h.Restart,h.SaveMaps]);
0160     setEnable(1,h.NextLoc);
0161     set(h.NextLoc,'String','Start');
0162   case 'MapsComputed'
0163     set(h.figure1,'Pointer','arrow');
0164     setEnable(1,[h.Restart,h.NextLoc,h.SaveMaps]);
0165     set(h.NextLoc,'String','Next Location');
0166   case 'Busy'
0167     set(h.figure1,'Pointer','watch');
0168     setEnable(0,[h.Restart,h.NextLoc,h.SaveMaps]);
0169   otherwise
0170     debugMsg(['Unknown state:' state]);
0171 end
0172 drawnow;
0173 return;
0174 
0175 
0176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0177 % set color features according to image type
0178 function checkColorParams(handles)
0179 global params img;
0180 if ~isempty(img)
0181   switch img.dims
0182     case 2
0183       % gray-scale image: no color features
0184       params = removeColorFeatures(params,0);
0185       setEnable(0,[handles.Color,handles.WeightCol,...
0186                    handles.Skin,handles.WeightSkin]);
0187       debugMsg('Gray scale image - removed color features.');
0188     case 3
0189       % color image
0190       setEnable(1,[handles.Color,handles.Skin]);
0191       setFeature(handles.Color,handles.WeightCol);
0192       setFeature(handles.Skin,handles.WeightSkin);
0193     otherwise
0194       debugMsg(sprintf('Unknown image format with %d dimensions.',img.dims));
0195   end
0196 end
0197 return;
0198 
0199                
0200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0201 % fill the GUI with the parameters from the global variable params
0202 function fillParams(handles)
0203 global params DEBUG_FID;
0204 setFeature(handles.Color,handles.WeightCol);
0205 setFeature(handles.Intensities,handles.WeightInt);
0206 setFeature(handles.Orientations,handles.WeightOri);
0207 setFeature(handles.Skin,handles.WeightSkin);
0208 setEnable(get(handles.Orientations,'Value'),[handles.NumOriText,handles.NumOri]);
0209 set(handles.NumOri,'String',num2str(numel(params.oriAngles)));
0210 setNormType(handles);
0211 setShapeMode(handles);
0212 set(handles.ToggleDebug,'Value',DEBUG_FID);
0213 
0214 styleStrings = {'Contour','ContrastModulate','None'};
0215 style = strmatch(params.visualizationStyle,styleStrings);
0216 if isempty(style)
0217   style = 3;
0218 end
0219 set(handles.VisStyle,'Value',style,'UserData',styleStrings);
0220 
0221 return;
0222 
0223 
0224 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0225 % check with user that parameters can be changed
0226 function response = confirmParamsChange(handles)
0227 global state;
0228 switch state
0229   case {'NoImage','ImageLoaded'}
0230     response = 1;
0231   case 'MapsComputed'
0232     button = questdlg({'Changing the parameters now will reset the computation.',...
0233                        'Would you like to proceed anyway?'},...
0234                        'Change parameters?',...
0235                        'Yes','No','Yes');
0236     response = strcmp(button,'Yes');
0237     if response
0238       setState(handles,'ImageLoaded');
0239       fprintf('---------------------------\n');
0240     end
0241   otherwise
0242     debugMsg(['Unknown state: ' state]);
0243     response = 0;
0244 end
0245 
0246 
0247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0248 % Loading an image
0249 function NewImage_Callback(hObject, eventdata, handles)
0250 declareGlobal;
0251 global img params state;
0252 prevState = state;
0253 setState(handles,'Busy');
0254 
0255 if isempty(img)
0256   defName = '';
0257 else
0258   defName = img.filename;
0259 end
0260 
0261 err = 1;
0262 while ~isempty(err)
0263   [newName,newPath] = uigetfile('*.*','Select an new image',defName);
0264   if (newName == 0)
0265     % User pressed 'cancel' - keep old file
0266     setState(handles,prevState);
0267     return;
0268   end
0269   
0270   [newImg,err] = initializeImage([newPath newName]);
0271   if ~isempty(err)
0272     beep;
0273     uiwait(warndlg(sprintf('%s is not a valid image!',newName),...
0274                    'Not a valid image','modal'));
0275     defName = '';
0276   end
0277 end
0278 
0279 % image is okay, set as img for analyses
0280 img = checkImageSize(newImg,'GUI');
0281 set(handles.ImageName,'String',newName);
0282 if (params.foaSize < 0)
0283   p = defaultSaliencyParams(img.size);
0284   params.foaSize = p.foaSize;
0285   setShapeMode(handles);
0286 end
0287 
0288 % Replacing an old image? output separator
0289 if strcmp(prevState,'MapsComputed')
0290   fprintf('---------------------------\n');
0291 end
0292 
0293 % some house keeping
0294 state = 'ImageLoaded';
0295 checkColorParams(handles);
0296 updateImg(handles);
0297 updateLocImg(handles);
0298 setState(handles);
0299 debugMsg(sprintf('Loaded image %s.\n',img.filename));
0300 return;
0301 
0302 
0303 
0304 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0305 % Feature selection and weights                                  %
0306 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0307 
0308 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0309 % get the values for a particular feature from the GUI controls
0310 function getFeature(hSelect,hWeight,handles)
0311 global params;
0312 if ~confirmParamsChange(handles)
0313   return;
0314 end
0315 name = get(hSelect,'Tag');
0316 idx = strmatch(name,params.features);
0317 
0318 if get(hSelect,'Value')
0319   set(hWeight,'Enable','on');
0320 
0321   % need to add this feature?
0322   if isempty(idx)
0323     params.features = {params.features{:},name};
0324     params.weights = [params.weights 1];
0325     idx = strmatch(name,params.features);
0326   end
0327   
0328   % get weight value from text box
0329   w = str2num(get(hWeight,'String'));
0330   if ~isempty(w)
0331     params.weights(idx(1)) = w(1);
0332   end
0333 else
0334   set(hWeight,'Enable','off');
0335   
0336   % need to remove this feature?
0337   if ~isempty(idx)
0338     newIdx = setdiff([1:length(params.features)],idx);
0339     params.features = {params.features{newIdx}};
0340     parmas.weights = [params.weights(newIdx)];
0341   end
0342 end
0343 return;
0344 
0345 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0346 % set the GUI controls for a particular feature
0347 function setFeature(hSelect,hWeight)
0348 global params;
0349 name = get(hSelect,'Tag');
0350 idx = strmatch(name,params.features);
0351 
0352 if isempty(idx)
0353   set(hSelect,'Value',0);
0354   set(hWeight,'Enable','off');
0355 else
0356   set(hSelect,'Value',1);
0357   set(hWeight,'Enable','on','String',num2str(params.weights(idx(1))));
0358 end
0359 return;
0360 
0361 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0362 % enable/disable a vector of GUI elements
0363 function setEnable(value,hs)
0364 enableStrings = {'off','on'};
0365 for h = 1:length(hs)
0366   set(hs(h),'Enable',enableStrings{value+1});
0367 end
0368 return;
0369 
0370 
0371 %%%% Color %%%%
0372 
0373 % Color checkbox
0374 function Color_Callback(hObject, eventdata, handles)
0375 getFeature(handles.Color,handles.WeightCol,handles);
0376 setFeature(handles.Color,handles.WeightCol);
0377 
0378 % Color weight textbox
0379 function WeightCol_Callback(hObject, eventdata, handles)
0380 getFeature(handles.Color,handles.WeightCol,handles);
0381 setFeature(handles.Color,handles.WeightCol);
0382 
0383 % Create color weight textbox
0384 function WeightCol_CreateFcn(hObject, eventdata, handles)
0385 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0386     set(hObject,'BackgroundColor','white');
0387 end
0388 
0389 
0390 %%%% Intensities %%%%
0391 
0392 % Intensities checkbox
0393 function Intensities_Callback(hObject, eventdata, handles)
0394 getFeature(handles.Intensities,handles.WeightInt,handles);
0395 setFeature(handles.Intensities,handles.WeightInt);
0396 
0397 % Intensities weight textbox
0398 function WeightInt_Callback(hObject, eventdata, handles)
0399 getFeature(handles.Intensities,handles.WeightInt,handles);
0400 setFeature(handles.Intensities,handles.WeightInt);
0401 
0402 % create Intensities weight textbox
0403 function WeightInt_CreateFcn(hObject, eventdata, handles)
0404 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0405     set(hObject,'BackgroundColor','white');
0406 end
0407 
0408 
0409 %%%% Orientations %%%%
0410 
0411 % Orientations checkbox
0412 function Orientations_Callback(hObject, eventdata, handles)
0413 getFeature(handles.Orientations,handles.WeightOri,handles);
0414 setFeature(handles.Orientations,handles.WeightOri);
0415 setEnable(get(hObject,'Value'),[handles.NumOriText,handles.NumOri]);
0416 
0417 % Orientaions weight textbox
0418 function WeightOri_Callback(hObject, eventdata, handles)
0419 getFeature(handles.Orientations,handles.WeightOri,handles);
0420 setFeature(handles.Orientations,handles.WeightOri);
0421 
0422 % create Orientations weight textbox
0423 function WeightOri_CreateFcn(hObject, eventdata, handles)
0424 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0425     set(hObject,'BackgroundColor','white');
0426 end
0427 
0428 % number of orientations textbox
0429 function NumOri_Callback(hObject, eventdata, handles)
0430 global params
0431 if confirmParamsChange(handles)
0432   n = str2num(get(hObject,'String'));
0433   if ~isempty(n)
0434     n = max(round(n(1)),1);
0435     params.oriAngles = [0:(n-1)] * 180 / n;
0436   end
0437 end
0438 set(hObject,'String',num2str(numel(params.oriAngles)));
0439 
0440 % create number of orientations textbox
0441 function NumOri_CreateFcn(hObject, eventdata, handles)
0442 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0443     set(hObject,'BackgroundColor','white');
0444 end
0445 
0446 
0447 %%%% Skin hue %%%%
0448 
0449 % skin hue checkbox
0450 function Skin_Callback(hObject, eventdata, handles)
0451 getFeature(handles.Skin,handles.WeightSkin,handles);
0452 setFeature(handles.Skin,handles.WeightSkin);
0453 
0454 % skin hue weight textbox
0455 function WeightSkin_Callback(hObject, eventdata, handles)
0456 getFeature(handles.Skin,handles.WeightSkin,handles);
0457 setFeature(handles.Skin,handles.WeightSkin);
0458 
0459 % create skin hue weight textbox
0460 function WeightSkin_CreateFcn(hObject, eventdata, handles)
0461 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0462     set(hObject,'BackgroundColor','white');
0463 end
0464 
0465 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0466 %                       Parameters                                         %
0467 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0468 
0469 % SetPyrLevels button
0470 function SetPyrLevels_Callback(hObject, eventdata, handles)
0471 global params
0472 if confirmParamsChange(handles)
0473   params.levelParams = guiLevelParams(params.levelParams);
0474 end
0475 
0476 % set the GUI normtype controls to parameters
0477 function setNormType(handles)
0478 global params;
0479 normTypes = get(handles.NormType,'String');
0480 idx = strmatch(params.normtype,normTypes);
0481 if isempty(idx)
0482   params.normtype = normTypes{get(handles.NormType,'Value')};
0483 else
0484   set(handles.NormType,'Value',idx(1));
0485 end
0486 isIter = strcmp(params.normtype,'Iterative');
0487 setEnable(isIter,[handles.NumIterText,handles.NumIter])
0488 set(handles.NumIter,'String',num2str(params.numIter));
0489 
0490 % get the normtype parameters from the GUI controls
0491 function getNormType(handles)
0492 global params;
0493 if ~confirmParamsChange(handles)
0494   return;
0495 end
0496 normTypes = get(handles.NormType,'String');
0497 params.normtype = normTypes{get(handles.NormType,'Value')};
0498 niter = str2num(get(handles.NumIter,'String'));
0499 if ~isempty(niter)
0500   niter = round(niter(1));
0501   if (niter < 0)
0502     niter = 0;
0503   end
0504   params.numIter = niter;
0505 end
0506 
0507 % NormType drop-down list
0508 function NormType_Callback(hObject, eventdata, handles)
0509 getNormType(handles);
0510 setNormType(handles);
0511 
0512 % create NormType drop-down list
0513 function NormType_CreateFcn(hObject, eventdata, handles)
0514 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0515     set(hObject,'BackgroundColor','white');
0516 end
0517 
0518 % NumIter textbox
0519 function NumIter_Callback(hObject, eventdata, handles)
0520 getNormType(handles);
0521 setNormType(handles);
0522 
0523 % create NumIter textbox
0524 function NumIter_CreateFcn(hObject, eventdata, handles)
0525 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0526     set(hObject,'BackgroundColor','white');
0527 end
0528 
0529 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0530 % setting shape mode                                               %
0531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0532 
0533 % get the shape mode parameters form the GUI controls
0534 function getShapeMode(handles)
0535 global params;
0536 if ~confirmParamsChange(handles)
0537   return;
0538 end
0539 shapeModes = {'None','shapeSM','shapeCM','shapeFM','shapePyr'};
0540 params.shapeMode = shapeModes{get(handles.ShapeMode,'Value')};
0541 
0542 newFS = str2num(get(handles.FOAsize,'String'));
0543 if ~isempty(newFS)
0544   if (newFS < 0)
0545     newFS = 0;
0546   end
0547   params.foaSize = newFS;
0548 end
0549 return;
0550 
0551 % set the shape mode GUI controls according to the parameters
0552 function setShapeMode(handles)
0553 global params;
0554 shapeModes = {'None','shapeSM','shapeCM','shapeFM','shapePyr'};
0555 mode = strmatch(params.shapeMode,shapeModes);
0556 if ~isempty(mode)
0557   set(handles.ShapeMode,'Value',mode(1));
0558 end
0559 
0560 isNone = strcmp(params.shapeMode,shapeModes{1});
0561 setEnable(isNone,[handles.FOAsize,handles.FOAsizeText]);
0562 if (params.foaSize >= 0)
0563   set(handles.FOAsize,'String',num2str(params.foaSize));
0564 else
0565   set(handles.FOAsize,'String','');
0566 end
0567 return;
0568 
0569 % ShapeMode drop-down list
0570 function ShapeMode_Callback(hObject, eventdata, handles)
0571 getShapeMode(handles);
0572 setShapeMode(handles);
0573 
0574 % create ShapeMode drop-down list
0575 function ShapeMode_CreateFcn(hObject, eventdata, handles)
0576 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0577     set(hObject,'BackgroundColor','white');
0578 end
0579 
0580 
0581 % FOAsize textbox
0582 function FOAsize_Callback(hObject, eventdata, handles)
0583 getShapeMode(handles);
0584 setShapeMode(handles);
0585 
0586 
0587 % create FOAsize textbox
0588 function FOAsize_CreateFcn(hObject, eventdata, handles)
0589 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0590     set(hObject,'BackgroundColor','white');
0591 end
0592 
0593 
0594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0595 % setting visualizations                                           %
0596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0597 
0598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0599 % initializes plot windows
0600 function initializeVisFigures(handles)
0601 visHandles = [handles.VisImg,handles.VisSM,handles.VisCM,...
0602               handles.VisShape,handles.VisLoc];
0603 for h = visHandles
0604   visStrings = {'off','on'};
0605   figH = figure;
0606   vis = get(h,'Value')+1;
0607   set(figH,'Name',['STB: ' get(h,'String')],...
0608            'NumberTitle','off',...
0609            'CloseRequestFcn',@VisFigureCloseCallback,...
0610            'UserData',h,...
0611            'Visible',visStrings{vis});
0612   set(h,'UserData',figH);
0613 end
0614 
0615 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0616 % delete the visualization figures, e.g. when the 'Quit' button is pressed
0617 function cleanupVisFigures(handles)
0618 visHandles = [handles.VisImg,handles.VisSM,handles.VisCM,...
0619               handles.VisShape,handles.VisLoc];
0620 for h = visHandles
0621   figH = get(h,'UserData');
0622   delete(figH);
0623 end
0624 return;
0625 
0626 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0627 % callback function for closing figures - just make them invisible
0628 function VisFigureCloseCallback(hSrc,event)
0629 hObject = get(hSrc,'UserData');
0630 set(hObject,'Value',0);
0631 set(hSrc,'Visible','off');
0632 
0633 
0634 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0635 % set the GUI controls and figure visibility
0636 function setVisFigure(hObject,handles)
0637 enableStrings = {'off','on'};
0638 figH = get(hObject,'UserData');
0639 val = get(hObject,'Value')+1;
0640 try
0641   set(figH,'Visible',enableStrings{val});
0642 catch
0643   figH = figure;
0644   set(figH,'Visible',enableStrings{val});
0645   set(hObject,'UserData',figH);
0646 end
0647 
0648 
0649 % do the above for all visualization figures
0650 function setAllVisFigures(handles)
0651 visHandles = [handles.VisImg,handles.VisSM,handles.VisCM,...
0652               handles.VisShape,handles.VisLoc];
0653 for h = visHandles
0654   setVisFigure(h,handles);
0655 end
0656 
0657 
0658 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0659 % update the 'image' visualization figure
0660 function updateImg(handles)
0661 global state img;
0662 figH = get(handles.VisImg,'UserData');
0663 if strcmp(get(figH,'Visible'),'on')
0664   switch state
0665     case {'ImageLoaded','MapsComputed'}
0666       figure(figH);
0667       displayImage(img);
0668       figure(handles.figure1);
0669     otherwise
0670       % do nothing
0671   end
0672 end
0673 
0674 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0675 % update the 'saliency map' visualization figure
0676 function updateSM(handles)
0677 global state salMap wta img;
0678 figH = get(handles.VisSM,'UserData');
0679 if strcmp(get(figH,'Visible'),'on')
0680   switch state
0681     case 'MapsComputed'
0682       figure(figH);
0683       wtaMap = emptyMap(img.size(1:2),'Winner Take All');
0684       wtaMap.data = imresize(wta.sm.V,img.size(1:2),'bilinear');
0685       displayMaps([salMap,wtaMap],1);
0686       figure(handles.figure1);
0687     otherwise
0688       % do nothing
0689   end
0690 end
0691 
0692 
0693 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0694 % update the 'conspicuity maps' visualization figure
0695 function updateCM(handles)
0696 global state salData;
0697 figH = get(handles.VisCM,'UserData');
0698 if strcmp(get(figH,'Visible'),'on')
0699   switch state
0700     case 'MapsComputed'
0701       figure(figH);
0702       displayMaps([salData(:).CM],1);
0703       figure(handles.figure1);
0704     otherwise
0705       % do nothing
0706   end
0707 end
0708 
0709 
0710 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0711 % update the 'shape maps' visualization figure
0712 function winLabel = updateShape(handles)
0713 global state shapeData;
0714 if isempty(shapeData)
0715   winLabel = '';
0716 else
0717   winLabel = [' - ' shapeData.winningMap.label];
0718   figH = get(handles.VisShape,'UserData');
0719   if strcmp(get(figH,'Visible'),'on')
0720     switch state
0721       case 'MapsComputed'
0722         figure(figH);
0723         displayMaps({shapeData.winningMap,shapeData.segmentedMap,...
0724                      shapeData.binaryMap,shapeData.shapeMap});
0725         figure(handles.figure1);
0726       otherwise
0727         % do nothing
0728     end
0729   end
0730 end
0731 
0732 
0733 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0734 % update the 'attended location' visualization figure
0735 function updateLoc(handles)
0736 global globalVars;
0737 eval(globalVars);
0738 figH = get(handles.VisLoc,'UserData');
0739 if strcmp(get(figH,'Visible'),'on')
0740   switch state
0741     case 'ImageLoaded'
0742       updateLocImg(handles);
0743     case 'MapsComputed'
0744       figure(figH);
0745       plotSalientLocation(winner,lastWinner,img,params,shapeData);
0746       if ~isempty(shapeData)
0747         title(['shape from: ' shapeData.winningMap.label]);
0748       end
0749       figure(handles.figure1);
0750     otherwise
0751       % do nothing
0752   end
0753 end
0754 
0755 
0756 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0757 % update the image in the 'attended location' visualization figure
0758 function updateLocImg(handles)
0759 global state img params;
0760 figH = get(handles.VisLoc,'UserData');
0761 if strcmp(get(figH,'Visible'),'on')
0762   switch state
0763     case {'ImageLoaded','MapsComputed'}
0764       figure(figH);
0765       displayImage(img);
0766       setVisFigure(handles.VisLoc,handles);
0767       figure(handles.figure1);
0768     otherwise
0769       % do nothing
0770   end
0771 end
0772 
0773 
0774 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0775 % GUI controls for the visualization figures
0776 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0777 
0778 % visualize image checkbox
0779 function VisImg_Callback(hObject, eventdata, handles)
0780 setVisFigure(hObject,handles);
0781 updateImg(handles);
0782 
0783 % visualize SM checkbox
0784 function VisSM_Callback(hObject, eventdata, handles)
0785 setVisFigure(hObject,handles);
0786 updateSM(handles);
0787 
0788 % visualize CM checkbox
0789 function VisCM_Callback(hObject, eventdata, handles)
0790 setVisFigure(hObject,handles);
0791 updateCM(handles);
0792 
0793 % visualize Shape checkbox
0794 function VisShape_Callback(hObject, eventdata, handles)
0795 setVisFigure(hObject,handles);
0796 updateShape(handles);
0797 
0798 % visualize location checkbox
0799 function VisLoc_Callback(hObject, eventdata, handles)
0800 global lastWinner;
0801 lastWinner = [-1,-1];
0802 setVisFigure(hObject,handles);
0803 updateLoc(handles);
0804 
0805 % visualization style drop-down list
0806 function VisStyle_Callback(hObject, eventdata, handles)
0807 global globalVars;
0808 eval(globalVars);
0809 styleStrings = get(hObject,'UserData');
0810 val = get(hObject,'Value');
0811 params.visualizationStyle = styleStrings{val};
0812 lastWinner = [-1,-1];
0813 set(handles.VisLoc,'Value',1);
0814 setVisFigure(handles.VisLoc,handles);
0815 updateLocImg(handles);
0816 updateLoc(handles);
0817 
0818 function VisStyle_CreateFcn(hObject, eventdata, handles)
0819 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0820     set(hObject,'BackgroundColor','white');
0821 end
0822 
0823 
0824 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0825 % parameters management
0826 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0827 
0828 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0829 % reset parameters to the default
0830 function DefaultSettings_Callback(hObject, eventdata, handles)
0831 global params img;
0832 if confirmParamsChange(handles)
0833   if isempty(img)
0834     params = defaultSaliencyParams;
0835   else
0836     params = defaultSaliencyParams(img.size);
0837   end
0838   checkColorParams(handles);
0839   fillParams(handles);
0840 end
0841 
0842 
0843 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0844 % save parameters
0845 function SaveSettings_Callback(hObject, eventdata, handles)
0846 global params;
0847 debugMsg('Saving settings.');
0848 [filename,path] = uiputfile('*.mat','Save parameters as ...',...
0849                             'parameters.mat');
0850 if (filename ~= 0)
0851   save([path filename],'params');
0852 end
0853 
0854 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0855 % load parameters
0856 function LoadSettings_Callback(hObject, eventdata, handles)
0857 global params;
0858 if confirmParamsChange(handles)
0859   debugMsg('Loading settings.');
0860   [filename,path] = uigetfile('*.mat','Loading parameters from ...',...
0861                               'parameters.mat');
0862   if (filename ~= 0)
0863     try
0864       in = load([path filename]);
0865     catch
0866       uiwait(warndlg([filename ' is not a data file!'],...
0867              'Not a valid data file','modal'));
0868       return;
0869     end
0870     fnames = fieldnames(in);
0871     if strmatch('params',fnames)
0872       % we have a params field - great, let's take it
0873       params = in.params;
0874       fillParams(handles);
0875     elseif (length(fnames) == 1)
0876       % just one field - let's use this one
0877       params = getfield(in,fnames{1});
0878       fillParams(handles);
0879     else
0880       % couldn't find params in this file
0881       uiwait(warndlg(['Could not find params in ' filename],...
0882              'Params not found','modal'));
0883     end
0884     checkColorParams(handles);
0885   end
0886 end
0887 
0888 
0889 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0890 % save maps
0891 function SaveMaps_Callback(hObject, eventdata, handles)
0892 global salMap wta salData shapeData;
0893 debugMsg('Saving maps.');
0894 [filename,path] = uiputfile('*.mat','Save maps in ...',...
0895                             'maps.mat');
0896 if (filename ~= 0)
0897   save([path filename],'salMap','wta','salData','shapeData');
0898 end
0899 
0900 
0901 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0902 % Switch Debugging messages on/off
0903 function ToggleDebug_Callback(hObject, eventdata, handles)
0904 global DEBUG_FID
0905 DEBUG_FID = get(hObject,'Value');
0906 
0907 
0908 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0909 % Reset button
0910 function Restart_Callback(hObject, eventdata, handles)
0911 setState(handles,'ImageLoaded');
0912 fprintf('---------------------------\n');
0913 
0914 
0915 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0916 % saliency computation functions and controls
0917 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0918 
0919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0920 % Start / Next Location button
0921 function NextLoc_Callback(hObject, eventdata, handles)
0922 global globalVars;
0923 eval(globalVars);
0924 switch state
0925   case 'ImageLoaded'
0926     debugMsg('Computing new maps ...');
0927     setState(handles,'Busy');
0928     [salMap,salData] = makeSaliencyMap(img,params);
0929     wta = initializeWTA(salMap,params);
0930     state = 'MapsComputed';
0931     winner = [-1,-1];
0932     updateCM(handles);
0933     updateLocImg(handles);
0934     NextLoc_Callback(hObject, eventdata, handles);
0935   case 'MapsComputed'
0936     debugMsg('Going to the next location ...');
0937     setState(handles,'Busy');
0938     lastWinner = winner;
0939     thisWinner = [-1,-1];
0940     while (thisWinner(1) == -1)
0941       [wta,thisWinner] = evolveWTA(wta);
0942     end
0943     shapeData = estimateShape(salMap,salData,thisWinner,params);
0944     wta = applyIOR(wta,thisWinner,params,shapeData);
0945     winner = winnerToImgCoords(thisWinner,params);
0946     state = 'MapsComputed';
0947     updateSM(handles);
0948     winLabel = updateShape(handles);
0949     updateLoc(handles);
0950     fprintf('winner: %i,%i; t = %4.1f ms%s\n',...
0951             winner(2),winner(1),wta.exc.time*1000,winLabel);
0952   otherwise
0953     debugMsg(['Unexpected state: ' state]);
0954 end
0955 setState(handles);
0956 return;
0957 
0958 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0959 % About button
0960 function About_Callback(hObject, eventdata, handles)
0961 uiwait(msgbox({...
0962   'SaliencyToolbox 2.2',...
0963   'http://www.saliencytoolbox.net','',...
0964   'Copyright 2006-2008 by Dirk B. Walther and',... 
0965   'the California Institutute of Technology','',...
0966   'Type ''STBlicense'' to view the license agreement.',''},...
0967   'About SaliencyToolbox','modal'));
0968 
0969 
0970 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0971 % Quit button
0972 function Quit_Callback(hObject, eventdata, handles)
0973 setState(handles,'Busy');
0974 uiresume(handles.figure1);
0975 
0976 % Close button on the main window
0977 function MainWindowCloseCallback(hObject,event)
0978 handles = guidata(hObject);
0979 setState(handles,'Busy');
0980 uiresume(hObject);
0981

Generated on Thu 18-Jul-2013 06:10:46 by m2html © 2005