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

📄 image_resize.m

📁 matlab处理图像的一些基本方法。其中有一部分mex程序需要安装编译
💻 M
字号:
function image_resize(command)
%IMAGE_RESIZE - resizes the current view to be the current image
%
%		IMAGE_RESIZE(COMMAND)
%
%			COMMAND - valid commands:
%
%				START - set up the button frame and initialize
%				RESIZE - do the actual resizing
%
%	Mark Young  spring of 1995
%

%
% Copyright (c) 1995 by Claudio Rivetti and Mark Young
% claudio@alice.uoregon.edu,    mark@alice.uoregon.edu
%

global I H Uibgcolor method_pop pixels_ed undo_bt Handleimg Handlefig B_frame Handleimgax
global OZFactor OCenter OldH Undofun


if strcmp(upper(command),'START')

	if ~isimage
		setviewmode('TOPVIEW');
		showimage;
	end
	
	% 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)+.45 uiwidth uithick];
	mt_pos = [middle pos(2)+.49 uiwidth+.002 uithick];
	pixtxt_pos = [middle pos(2)+.59 uiwidth+.012 uithick];
	pixed_pos = [middle pos(2)+.55 uiwidth uithick];
	fr_pos = [middle - 0.02 pos(2)+0.20 uiwidth+0.04 0.45];
	%--------------------------------------------------------------------
	
	%  Callbacks for the buttons  ---------------------------------------
	exec_cbk = 'image_resize(''RESIZE'');';  
	undo_cbk = 'image_resize(''UNDO'');';
	pixed_cbk = 'global pixels_ed; editstr2value(pixels_ed, 1, 1024);';
	%--------------------------------------------------------------------

	initbuttons('Image resize', 'Done');

	uicontrol(Handlefig, 'Style', 'frame',...
		'Units', 'normalized',...
		'Position',fr_pos,...
		'BackgroundColor', Uibgcolor);

	uicontrol(Handlefig, 'Style', 'text',...
		'String', 'Pixels/line',...
		'Units', 'normalized',...
		'Position',pixtxt_pos,...
		'BackgroundColor', Uibgcolor,...
		'HorizontalAlignment', 'center');
	
	pixels_ed  = uicontrol(Handlefig, 'Style', 'edit',...
		'String', num2str(size(I,1)),...
		'Value', size(I,1),...
		'Units', 'normalized',...
		'Position',pixed_pos,...
		'HorizontalAlignment', 'center',...
		'CallBack',pixed_cbk);

	uicontrol(Handlefig,'Style','text',...
		'String','Method',...
		'Units','normalized',...
		'BackgroundColor', Uibgcolor,...
		'Position',mt_pos);
	
	
	method_pop=uicontrol(Handlefig, 'Style', 'popup',...
		'Units', 'normalized',...
		'position', mp_pos,...
		'String', 'bicubic|nearest|bilinear',...
		'Value', 1,...
		'Userdata', str2mat('bicubic', 'nearest', 'bilinear'));

	
	uicontrol(Handlefig,'Style','push',...
		'String', 'Execute',...
		'Units', 'normalized', ...
		'Position', exec_pos,...
		'CallBack',exec_cbk);
	
	undo_bt=uicontrol(Handlefig,'Style','push',...
		'String','Undo',...
		'Enable', 'off',...
		'Units', 'normalized', ...
		'Position', undo_pos,...
		'CallBack',undo_cbk);

end	% START


if strcmp(upper(command),'RESIZE')
	f=watchon;
	statusbar('Resizing image...');
	OldH=H;
	[OZFactor, OCenter]=getzoom(Handleimgax);
	[M, Curr_pos]= getview;
	ax = axis;
	scan_size = ax(2)-ax(1);

	% resize the image
	px=get(pixels_ed, 'value');
	m=get(method_pop, 'userdata');
	i=get(method_pop, 'value');
	method=m(i,:);
	M = imresize(M, [px px], method);
	
	%   Set parameters in the header
	[s,un]=scansize(H);
	if strcmp(un, 'px')
	  H = setparameter(H,'Scan size',[px ' ' un]);
	  H = setparameter(H,'Samps/line',[px px]);
	else  
	  H = setparameter(H,'Scan size',[num2str(scan_size) ' ' un]);
	  H = setparameter(H,'X offset',[num2str(ax(1)) ' ' un]);
	  H = setparameter(H,'Y offset',[num2str(ax(3)) ' ' un]);
	  H = setparameter(H,'Samps/line',[px px]);
	end
	
	delete(Handleimg);
	setimage(M,inf,1);
	Undofun='image_resize(''UNDO'');';
	set(undo_bt, 'Enable', 'on');
	clearstatusbar;
	watchoff(f);

end	% RESIZE


if strcmp(upper(command),'UNDO')
  
  H=OldH;
  delete(Handleimg);
  setimage(getclipboard,inf,0);
  setclipboard([]);
  %zoom(OZFactor, OCenter);
  zoom(OZFactor);
  set(undo_bt, 'Enable', 'off');

end %UNDO


return

⌨️ 快捷键说明

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