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

Generated on Fri 07-Sep-2007 14:42:18 by m2html © 2003