function image_erode(command) %IMAGE_ERODE - Erode the current binary image % % IMAGE_ERODE(COMMAND) % % COMMAND - valid commands: % % START - set up the button frame and initialize % DOIT - do the actual erosion % UNDO - undo the erosion % % Claudio 28 Sept. 1995 % % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % global I Handlefig Uibgcolor B_frame method_pop Undofun undo_bt exe_bt if isempty(I) return; end if ~isbw(I) message('|| Image must be binary'); return; end if nargin==0 command='START'; end figure(Handlefig); % Position variables------------------------------------- pos=get(B_frame, 'Position'); uiwidth=0.12; uithick=0.035; middle=pos(1)+(pos(3)-uiwidth)/2; %-------------------------------------------------------- % Positions of buttons ---------------------------------- undo_pos = [middle pos(2)+0.35 uiwidth, uithick]; exec_pos = [middle pos(2)+0.45 uiwidth, uithick]; mp_pos = [middle pos(2)+.55 uiwidth uithick]; mt_pos = [middle-.005 pos(2)+.59 uiwidth+.005 uithick]; %-------------------------------------------------------- % Callbacks for the buttons --------------------------- exec_cbk = 'image_erode(''DOIT'');'; undo_cbk = 'image_erode(''UNDO'');'; %-------------------------------------------------------- if strcmp(command,'START') if ~isimage setviewmode('TOPVIEW'); showimage; end initbuttons('Image Erosion', 'Done'); exe_bt = uicontrol(gcf,'Style','push',... 'String', 'Execute',... 'Units', 'normalized', ... 'Position', exec_pos,... 'CallBack',exec_cbk); undo_bt = uicontrol(gcf,'Style','push',... 'String','Undo',... 'Units', 'normalized', ... 'Enable', 'off',... 'Position', undo_pos,... 'CallBack',undo_cbk); uicontrol(gcf,'Style','text',... 'String','Method',... 'Units','normalized',... 'Horiz', 'center',... 'BackgroundColor', Uibgcolor,... 'Position',mt_pos); method_pop=uicontrol(gcf, 'Style', 'popup',... 'Units', 'normalized',... 'position', mp_pos,... 'String', 'Erode|Skeleton|Shrink|Thin',... 'Value', 1); end % START if strcmp(command,'DOIT') f=watchon; methods=['Erode ';'Skeleton';'Shrink ';'Thin ']; statusbar('Eroding binary image...'); v=get(method_pop, 'value'); m=methods(v,:); m=strrep(m, ' ', ''); setimage(erode(I,m)); set(undo_bt, 'Enable', 'on'); set(exe_bt, 'String', 'Re-Execute'); clearstatusbar; watchoff(f); end % DOIT if strcmp(command,'UNDO') undo; set(undo_bt, 'Enable', 'off'); end % UNDO return