⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 guisaliency.m

📁 显著区域检测。求的图像中感兴趣区域的位置
💻 M
📖 第 1 页 / 共 2 页
字号:
% 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.% This file is part of the SaliencyToolbox - Copyright (C) 2006-2007% by Dirk B. Walther and the California Institute of Technology.% See the enclosed LICENSE.TXT document for the license agreement. % More information about this project is available at: % http://www.saliencytoolbox.netfunction varargout = guiSaliency(varargin)% GUI initialization codegui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @guiSaliency_OpeningFcn, ...                   'gui_OutputFcn',  @guiSaliency_OutputFcn, ...                   'gui_LayoutFcn',  [], ...                   'gui_Callback',   []);if nargin && ischar(varargin{1})   gui_State.gui_Callback = str2func(varargin{1});endif nargout    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});else    gui_mainfcn(gui_State, varargin{:});end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% opening code executes just before guiSaliency is made visible.function guiSaliency_OpeningFcn(hObject, eventdata, handles, varargin)handles.output = hObject;guidata(hObject, handles);% define the needed global variablesdeclareGlobal;global globalVars;globalVars = 'global img params state salMap salData wta lastWinner winner shapeData';eval(globalVars);state = 'NoImage';% try to use user-given imageif (length(varargin) >= 1)  switch class(varargin{1})    case 'struct'      newImg = varargin{1};      err = '';      state = 'ImageLoaded';    case {'char','uint8','double'}      [newImg,err] = initializeImage(varargin{1});    otherwise      err = 1;  end  if isempty(err)    img = checkImageSize(newImg,'GUI');    if isnan(img.filename)      imgName = '(from input arguments)';    else      imgName = img.filename;    end    set(handles.ImageName,'String',imgName);    state = 'ImageLoaded';  else    beep;    if ischar(varargin{1})      name = varargin{1};    else      name = 'This';    end    uiwait(warndlg([name ' is not a valid image!'],...                   'Not a valid image','modal'));  endend% use user-given parameters if givenif (length(varargin) >= 2)  if isstruct(varargin{2})    params = varargin{2};  else    params = defaultSaliencyParams(img.size);  endelse  if isempty(img);    params = defaultSaliencyParams;  else    params = defaultSaliencyParams(img.size);  endend% some more initializationssetState(handles);checkColorParams(handles);fillParams(handles);initializeVisFigures(handles);updateImg(handles);updateLocImg(handles);debugMsg(sprintf('%s initialized in state: %s.',mfilename,state));% this waits until the "Quit" button is presseduiwait(handles.figure1);% clean upcleanupVisFigures(handles);eval(['clear ' globalVars 'globalVars']);debugMsg('Global variables cleared - bye.');try  delete(handles.figure1);catch  % nothing to doend% that's it, bye bye.return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Outputs from this function are returned to the command line.function varargout = guiSaliency_OutputFcn(hObject, eventdata, handles)varargout{1} = hObject;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% update the GUI according to the current statefunction setState(h,newState)global state;if (nargin >= 2)  state = newState;enddebugMsg(['Setting state: ' state]);switch state  case 'NoImage'    set(h.figure1,'Pointer','arrow');    setEnable(0,[h.Restart,h.NextLoc,h.SaveMaps]);    set(h.NextLoc,'String','Start');  case 'ImageLoaded'    set(h.figure1,'Pointer','arrow');    setEnable(0,[h.Restart,h.SaveMaps]);    setEnable(1,h.NextLoc);    set(h.NextLoc,'String','Start');  case 'MapsComputed'    set(h.figure1,'Pointer','arrow');    setEnable(1,[h.Restart,h.NextLoc,h.SaveMaps]);    set(h.NextLoc,'String','Next Location');  case 'Busy'    set(h.figure1,'Pointer','watch');    setEnable(0,[h.Restart,h.NextLoc,h.SaveMaps]);  otherwise    debugMsg(['Unknown state:' state]);enddrawnow;return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set color features accoring to image typefunction checkColorParams(handles)global params img;if ~isempty(img)  switch img.dims    case 2      % gray-scale image: no color features      params = removeColorFeatures(params,0);      setEnable(0,[handles.Color,handles.WeightCol,...                   handles.Skin,handles.WeightSkin]);      debugMsg('Gray scale image - removed color features.');    case 3      % color image      setEnable(1,[handles.Color,handles.Skin]);      setFeature(handles.Color,handles.WeightCol);      setFeature(handles.Skin,handles.WeightSkin);    otherwise      debugMsg(sprintf('Unknown image format with %d dimensions.',img.dims));  endendreturn;               %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fill the GUI with the parameters from the global variable paramsfunction fillParams(handles)global params DEBUG_FID;setFeature(handles.Color,handles.WeightCol);setFeature(handles.Intensities,handles.WeightInt);setFeature(handles.Orientations,handles.WeightOri);setFeature(handles.Skin,handles.WeightSkin);setEnable(get(handles.Orientations,'Value'),[handles.NumOriText,handles.NumOri]);set(handles.NumOri,'String',num2str(numel(params.oriAngles)));setNormType(handles);setShapeMode(handles);set(handles.ToggleDebug,'Value',DEBUG_FID);styleStrings = {'Contour','ContrastModulate','None'};style = strmatch(params.visualizationStyle,styleStrings);if isempty(style)  style = 3;endset(handles.VisStyle,'Value',style,'UserData',styleStrings);return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% check with user that parameters can be changedfunction response = confirmParamsChange(handles)global state;switch state  case {'NoImage','ImageLoaded'}    response = 1;  case 'MapsComputed'    button = questdlg({'Changing the parameters now will reset the computation.',...                       'Would you like to proceed anyway?'},...                       'Change parameters?',...                       'Yes','No','Yes');    response = strcmp(button,'Yes');    if response      setState(handles,'ImageLoaded');      fprintf('---------------------------\n');    end  otherwise    debugMsg(['Unknown state: ' state]);    response = 0;end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Loading an imagefunction NewImage_Callback(hObject, eventdata, handles)declareGlobal;global img params state;prevState = state;setState(handles,'Busy');if isempty(img)  defName = '';else  defName = img.filename;enderr = 1;while ~isempty(err)  [newName,newPath] = uigetfile('*.*','Select an new image',defName);  if (newName == 0)    % User pressed 'cancel' - keep old file    setState(handles,prevState);    return;  end    [newImg,err] = initializeImage([newPath newName]);  if ~isempty(err)    beep;    uiwait(warndlg(sprintf('%s is not a valid image!',newName),...                   'Not a valid image','modal'));    defName = '';  endend% image is okay, set as img for analysesimg = checkImageSize(newImg,'GUI');set(handles.ImageName,'String',newName);if (params.foaSize < 0)  p = defaultSaliencyParams(img.size);  params.foaSize = p.foaSize;  setShapeMode(handles);end% Replacing an old image? output separatorif strcmp(prevState,'MapsComputed')  fprintf('---------------------------\n');end% some house keepingstate = 'ImageLoaded';checkColorParams(handles);updateImg(handles);updateLocImg(handles);setState(handles);debugMsg(sprintf('Loaded image %s.\n',img.filename));return;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Feature selection and weights                                  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% get the values for a particular feature from the GUI controlsfunction getFeature(hSelect,hWeight,handles)global params;if ~confirmParamsChange(handles)  return;endname = get(hSelect,'Tag');idx = strmatch(name,params.features);if get(hSelect,'Value')  set(hWeight,'Enable','on');  % need to add this feature?  if isempty(idx)    params.features = {params.features{:},name};    params.weights = [params.weights 1];    idx = strmatch(name,params.features);  end    % get weight value from text box  w = str2num(get(hWeight,'String'));  if ~isempty(w)    params.weights(idx(1)) = w(1);  endelse  set(hWeight,'Enable','off');    % need to remove this feature?  if ~isempty(idx)    newIdx = setdiff([1:length(params.features)],idx);    params.features = {params.features{newIdx}};    parmas.weights = [params.weights(newIdx)];  endendreturn;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% set the GUI controls for a particular featurefunction setFeature(hSelect,hWeight)global params;name = get(hSelect,'Tag');idx = strmatch(name,params.features);if isempty(idx)  set(hSelect,'Value',0);  set(hWeight,'Enable','off');else  set(hSelect,'Value',1);  set(hWeight,'Enable','on','String',num2str(params.weights(idx(1))));endreturn;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% enable/disable a vector of GUI elementsfunction setEnable(value,hs)enableStrings = {'off','on'};for h = 1:length(hs)  set(hs(h),'Enable',enableStrings{value+1});endreturn;%%%% Color %%%%% Color checkboxfunction Color_Callback(hObject, eventdata, handles)getFeature(handles.Color,handles.WeightCol,handles);setFeature(handles.Color,handles.WeightCol);% Color weight textboxfunction WeightCol_Callback(hObject, eventdata, handles)getFeature(handles.Color,handles.WeightCol,handles);setFeature(handles.Color,handles.WeightCol);% Create color weight textboxfunction WeightCol_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end%%%% Intensities %%%%% Intensities checkboxfunction Intensities_Callback(hObject, eventdata, handles)getFeature(handles.Intensities,handles.WeightInt,handles);setFeature(handles.Intensities,handles.WeightInt);% Intensities weight textboxfunction WeightInt_Callback(hObject, eventdata, handles)getFeature(handles.Intensities,handles.WeightInt,handles);setFeature(handles.Intensities,handles.WeightInt);% create Intensities weight textboxfunction WeightInt_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end%%%% Orientations %%%%% Orientations checkboxfunction Orientations_Callback(hObject, eventdata, handles)getFeature(handles.Orientations,handles.WeightOri,handles);setFeature(handles.Orientations,handles.WeightOri);setEnable(get(hObject,'Value'),[handles.NumOriText,handles.NumOri]);% Orientaions weight textboxfunction WeightOri_Callback(hObject, eventdata, handles)getFeature(handles.Orientations,handles.WeightOri,handles);setFeature(handles.Orientations,handles.WeightOri);% create Orientations weight textboxfunction WeightOri_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end% number of orientations textboxfunction NumOri_Callback(hObject, eventdata, handles)global paramsif confirmParamsChange(handles)  n = str2num(get(hObject,'String'));  if ~isempty(n)    n = max(round(n(1)),1);    params.oriAngles = [0:(n-1)] * 180 / n;  endendset(hObject,'String',num2str(numel(params.oriAngles)));% create number of orientations textboxfunction NumOri_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end%%%% Skin hue %%%%% skin hue checkboxfunction Skin_Callback(hObject, eventdata, handles)getFeature(handles.Skin,handles.WeightSkin,handles);setFeature(handles.Skin,handles.WeightSkin);% skin hue weight textboxfunction WeightSkin_Callback(hObject, eventdata, handles)getFeature(handles.Skin,handles.WeightSkin,handles);setFeature(handles.Skin,handles.WeightSkin);% create skin hue weight textboxfunction WeightSkin_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))    set(hObject,'BackgroundColor','white');end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%                       Parameters                                         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% SetPyrLevels buttonfunction SetPyrLevels_Callback(hObject, eventdata, handles)global paramsif confirmParamsChange(handles)  params.levelParams = guiLevelParams(params.levelParams);end% set the GUI normtype controls to parametersfunction setNormType(handles)global params;normTypes = get(handles.NormType,'String');idx = strmatch(params.normtype,normTypes);if isempty(idx)  params.normtype = normTypes{get(handles.NormType,'Value')};else  set(handles.NormType,'Value',idx(1));endisIter = strcmp(params.normtype,'Iterative');setEnable(isIter,[handles.NumIterText,handles.NumIter])set(handles.NumIter,'String',num2str(params.numIter));% get the normtype parameters from the GUI controlsfunction getNormType(handles)global params;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -