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

📄 image_morph.m

📁 matlab处理图像的一些基本方法。其中有一部分mex程序需要安装编译
💻 M
字号:
function image_morph(command)%IMAGE_MORPH Performs morphological operations on binary images.%%		IMAGE_MORPH(COMMAND)%%		Valid Commands:%			START      - Inizialize the button frame%			DOIT       - Do the actual image tranformation%			SETCICLES  - Set the number of cicles%			UNDO       - Undo the image tranformation.%%	Claudio Nov. 6 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_btglobal prev_cicles cicles_ed methods prev_methodif isempty(I)  return;endif nargin==0  command='START';endif ~isbw(I) & strcmp(command,'UNDO')~=1  message('||         Image must be binary');  return;endfigure(Handlefig);if strcmp(command,'START')	% 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.25 uiwidth, uithick];	exec_pos = [middle pos(2)+0.35 uiwidth, uithick];	mp_pos = [middle pos(2)+.48 uiwidth uithick];	mt_pos = [middle-.005 pos(2)+.52 uiwidth+.005 uithick];	ctxt_pos = [middle-.005 pos(2)+.67 uiwidth+.005 uithick];	ced_pos = [middle-.005 pos(2)+.63 uiwidth+.005 uithick];	%--------------------------------------------------------		%  Callbacks for the buttons  ---------------------------	exec_cbk = 'image_morph(''DOIT'');'; 	undo_cbk = 'image_morph(''UNDO'');';	cicle_cbk= 'image_morph(''SETCICLES'');';	%--------------------------------------------------------	methods=[	'bothat  ';...				'bridge  ';...				'clean   ';...				'close   ';...				'diag    ';...				'dilate  ';...				'erode   ';...				'fatten  ';...				'fill    ';...				'hbreak  ';...				'majority';...				'perim4  ';... 				'perim8  ';...				'open    ';...				'remove  ';...				'shrink  ';...				'skel    ';...				'spur    ';...				'thicken ';...				'thin    ';...				'tophat  ';];	method_str='';	for i=1:size(methods,1)	  str=strrep(methods(i,:), ' ', '');	  str(1)=upper(str(1));	  method_str=[method_str ' ' str '|'];	end	method_str(length(method_str))='';	if ~isimage  		setviewmode('TOPVIEW');  		showimage;	end		if isempty(prev_cicles)	  prev_cicles=1;	end	if isempty(prev_method)	  prev_method=1;	end		initbuttons('Image Morphology', 'Done');	uicontrol(Handlefig,'Style','text',...		'String','N. cicles',...		'Units','normalized',...		'Horiz', 'center',...		'BackgroundColor', Uibgcolor,...		'Position',ctxt_pos);			cicles_ed=uicontrol(Handlefig,'Style','edit',...		'String', int2str(prev_cicles),...		'Units','normalized',...		'value', prev_cicles,...		'Horiz', 'center',...		'Position',ced_pos,...		'CallBack', cicle_cbk);	exe_bt = uicontrol(Handlefig,'Style','push',...		'String', 'Execute',...		'Units', 'normalized', ...		'Position', exec_pos,...		'CallBack',exec_cbk);	undo_bt = uicontrol(Handlefig,'Style','push',...		'String','Undo',...		'Units', 'normalized', ...		'Enable', 'off',...		'Position', undo_pos,...		'CallBack',undo_cbk);	uicontrol(Handlefig,'Style','text',...		'String','Method',...		'Units','normalized',...		'Horiz', 'center',...		'BackgroundColor', Uibgcolor,...		'Position',mt_pos);	method_pop=uicontrol(Handlefig, 'Style', 'popup',...		'Units', 'normalized',...		'position', mp_pos,...		'value', prev_method,...		'Horiz', 'left',...		'String', method_str,...		'Callback', 'global prev_method;prev_method=get(gco, ''value'');');end	% STARTif strcmp(command,'DOIT')	f=watchon;	statusbar('Performing binary morphological analysis, please wait...');    v=get(method_pop, 'value');	m=methods(v,:);	m=strrep(m, ' ', '');    setimage(abs(bwmorph(I,m, prev_cicles)));    set(undo_bt, 'Enable', 'on');	set(exe_bt, 'String', 'Re-Execute');	clearstatusbar;	watchoff(f);end	% DOITif strcmp(command,'SETCICLES')  cicles=str2num(get(cicles_ed, 'string'));  cicles=fix(cicles);  if isempty(cicles), cicles=1;end  if cicles>10, cicles=10;end  if cicles<1 , cicles=1;end  set(cicles_ed, 'value', cicles, 'string', int2str(cicles));  prev_cicles=cicles;end  %SETCICLESif strcmp(command,'UNDO')	undo;	set(undo_bt, 'Enable', 'off');end	% UNDOreturn

⌨️ 快捷键说明

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