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

📄 profile.m

📁 matlab处理图像的一些基本方法。其中有一部分mex程序需要安装编译
💻 M
字号:
function profile(command)
%PROFILE Analyze the image profile
%
%	Claudio Oct. 14 1995
%

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

global I H Handlefig Handleimgax Extramap B_frame prof_autoname prev_ascii
global Prof_line Xprofile Yprofile undo_bt clear_bt save_bt auto_name plot_bt
global savepath Fname Fprofext Uibgcolor Undofun ascii

if nargin==0
  command='START';
end

Zline=max(max(I))+1000;
fmode=['   -mat';' -ascii'];
ext=['*.mat';'*.txt'];

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

	if ~isimage
		setviewmode('TOPVIEW');
		showimage;
	end
	
	if isempty(prof_autoname)
	  prof_autoname=0;
	end
	if isempty(prev_ascii)
	  prev_ascii=0;
	end

    Xprofile=[NaN];
	Yprofile=[NaN];
	
	% Position variables------------------------------------
	pos=get(B_frame, 'Position');
	uiwidth=0.12;
	uithick=0.035;
	middle=pos(1)+(pos(3)-uiwidth)/2;
	%-------------------------------------------------------
	
	% Positions of buttons ---------------------------------
	fr1_pos = [middle - 0.02 pos(2)+0.39 uiwidth+0.04 0.32];
	fr2_pos = [middle - 0.02 pos(2)+0.11 uiwidth+0.04 0.20];
	section_pos = [middle pos(2)+.65 uiwidth uithick];
	undo_pos = [middle pos(2)+0.57 uiwidth, uithick];
	clear_pos = [middle pos(2)+0.49 uiwidth, uithick];
	plot_pos = [middle pos(2)+0.41 uiwidth, uithick];
	save_pos = [middle pos(2)+0.25 uiwidth, uithick];
	radio_pos = [middle pos(2)+0.18 uiwidth, 0.03];
	ascii_pos = [middle pos(2)+0.13 uiwidth, 0.03];
	%-------------------------------------------------------
	
	%  Callbacks for the buttons  --------------------------
	save_cbk = 'profile(''SAVE'');';
	section_cbk='profile(''PROFILE'');';
	clear_cbk='profile(''DONE'');';
	plot_cbk='profile(''MULTI'');';
	undo_cbk = 'profile(''UNDO'');';
	Undofun = 'profile(''UNDO'');';
	whendone='profile(''DONE'');';
	%-------------------------------------------------------
	
	initbuttons('Image Profile', 'Done', whendone);
	
	uicontrol(Handlefig, 'Style', 'frame',...
			'Units', 'normalized',...
			'Position',fr1_pos,...
			'BackgroundColor', Uibgcolor);
			
	uicontrol(Handlefig, 'Style', 'frame',...
			'Units', 'normalized',...
			'Position',fr2_pos,...
			'BackgroundColor', Uibgcolor);


	uicontrol(Handlefig,'Style','push',...
			'String', 'Get profile',...
			'Inter', 'on',...
			'Units', 'normalized', ...
			'Position', section_pos,...
			'CallBack',section_cbk);

	undo_bt=uicontrol(Handlefig,'Style','push',...
			'String','Undo',...
			'Enable', 'off',...
			'Units', 'normalized', ...
			'Position', undo_pos,...
			'CallBack',undo_cbk);
			
	clear_bt=uicontrol(Handlefig,'Style','push',...
			'String','Clear',...
			'Enable', 'off',...
			'Units', 'normalized', ...
			'Position', clear_pos,...
			'CallBack',clear_cbk);
			
	plot_bt=uicontrol(Handlefig,'Style','push',...
			'String','Single Plot',...
			'UserData', 0,...
			'Enable', 'off',...
			'Units', 'normalized', ...
			'Position', plot_pos,...
			'CallBack', plot_cbk);
			
	save_bt=uicontrol(Handlefig,'Style','push',...
			'String', 'Save',...
			'Enable', 'off',...
			'Units', 'normalized', ...
			'Position', save_pos,...
			'CallBack',save_cbk);
			
   auto_name=uicontrol(Handlefig, 'Style', 'check', ...
			'String', 'Auto Name', ...
			'Units', 'normalized', ...
			'value', prof_autoname,...
			'Position', radio_pos,...
			'CallBack', 'global prof_autoname;prof_autoname=get(gco, ''value'');');

   ascii=uicontrol(Handlefig, 'Style', 'check', ...
			'String', 'Ascii File', ...
			'Units', 'normalized', ...
			'value', prev_ascii,...
			'Position', ascii_pos,...
			'CallBack', 'global prev_ascii;prev_ascii=get(gco, ''value'');');

end  %START



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

	if length(find(isnan(Xprofile)==1))-1 >= 12
	  oldf=findobj(0, 'name', 'Profile');
	  if ~isempty(oldf)
		 figure(oldf);
	  end 
	  return;
	end
	
		
	figure(Handlefig);
	axes(Handleimgax);
	[x,y]=getline(gcf);
	x=x(1:length(x)-1);
	y=y(1:length(y)-1);
	z=x*0+Zline;
	
	if length(x) < 2
		return;
	end
	
	[xi,yi]=nm2ind(x,y);
	p=improfile(I,xi,yi);
	len=llength(x,y);
	xp=(1:len/length(p):len)';

	lpp=length(find(isnan(Xprofile)==1))-1;
	c=Extramap(lpp+2, :);
	Prof_line=[Prof_line line(x,y,z, 'color', c, 'EraseMode', 'Background')];
	drawnow;
	
	Xprofile=[Xprofile;xp;NaN];
	Yprofile=[Yprofile;p;NaN];

    if strcmp(get(undo_bt, 'Enable'), 'off')
		set(undo_bt, 'Enable', 'on');
		setclipboard(1);
		set(clear_bt, 'Enable', 'on');
		set(plot_bt, 'Enable', 'on');
		set(save_bt, 'Enable', 'on');
	end

    profile('PLOT');	
end %PROFILE



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

  if get(plot_bt, 'UserData')==1
	set(plot_bt, 'UserData', 0);
    set(plot_bt, 'string', 'Single Plot');
  else
    set(plot_bt, 'UserData', 1);
    set(plot_bt, 'string', 'Multi Plot');
  end
  
  profile('PLOT');
end %MULTI

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

  nn=find(isnan(Xprofile)==1);
  lpp=length(nn)-1;
  if lpp == 0
     profile('DONE');
	 return;
  end
  
  pos=[50 780 650 150];
  oldf=findobj(0, 'name', 'Profile');
  if isempty(oldf)
	oldf=figure('position', pos, 'name', 'Profile', 'NumberTitle', 'off'); 
  else
    figure(oldf);
	clg;
  end
  
  if get(plot_bt, 'UserData')==1
    profile('SINGLE_PLOT');
    return;
  end
  
  p=get(oldf,'pos');
  p(2)=pos(2)-150*(ceil(lpp/ceil(lpp/6))-1);
  p(4)=pos(4)+150*(ceil(lpp/ceil(lpp/6))-1);
  set(oldf, 'position', p);

  [ss, xlab]=scansize(H);
  ylab='';
  if strcmp(getparameter(H, 'Image data', 1), 'Height')
    ylab='nm';
  end
  
  for i=1:lpp
    subplot(ceil(lpp/ceil(lpp/6)),ceil(lpp/6),i);
    plot(Xprofile(nn(i):nn(i+1)), Yprofile(nn(i):nn(i+1)), 'color', Extramap(i+1,:));
    grid on;zoom on
    ylabel(ylab);
	if i==lpp-1 & ceil(lpp/6)==2
	  xlabel(xlab);
	end
  end
  xlabel(xlab);
  
end



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


  oldf=findobj(0, 'name', 'Profile');
  p=get(oldf,'pos');
  p(2)=680;
  p(4)=250;
  set(oldf, 'position', p);
  
  [ss, xlab]=scansize(H);
  ylab='';
  if strcmp(getparameter(H, 'Image data', 1), 'Height')
    ylab='nm';
  end
  
  nn=find(isnan(Xprofile)==1);
  lpp=length(nn)-1;
  
  for i=1:lpp
    plot(Xprofile(nn(i):nn(i+1)), Yprofile(nn(i):nn(i+1)), 'color', Extramap(i+1,:));
	hold on;grid on;zoom on
  end
  
  [ss, xlab]=scansize(H);
  ylab='';
  if strcmp(getparameter(H, 'Image data', 1), 'Height')
    ylab='nm';
  end
  
  xlabel(xlab);
  ylabel(ylab);
  
end




if strcmp(upper(command), 'DONE')
  oldf=findobj(0, 'name', 'Profile');
  if ~isempty(oldf)
     close(oldf);
  end

  if ~isempty(Prof_line)
    delete(Prof_line);
  end
  Prof_line=[];
  Xprofile=[NaN];
  Yprofile=[NaN];
  %refresh(Handlefig);
  refresh;
  set(undo_bt, 'Enable', 'off');
  setclipboard([]);
  set(clear_bt, 'Enable', 'off');
  set(save_bt, 'Enable', 'off');
  set(plot_bt, 'Enable', 'off');
end


if strcmp(upper(command), 'UNDO')
  if ~isobj(Prof_line(1)) | isempty(findobj('string', 'Image Profile'))
    return;
  end
  delete(Prof_line(length(Prof_line)));
  Prof_line=Prof_line(1:length(Prof_line)-1);
  %refresh(Handlefig);
  refresh;
  
  nn=find(isnan(Xprofile)==1);
  Xprofile=Xprofile(1:nn(length(nn)-1));
  Yprofile=Yprofile(1:nn(length(nn)-1));
  
  profile('PLOT');
end




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

  if get(auto_name, 'value')
    fext=Fprofext;
    if ~isempty(findstr(fext,'.mat')) & get(ascii,'value')==1
      fext=strrep(fext, '.mat', '.txt');
    end
    fname = [savepath Fname fext];
  else
    [name, p] = uiputfile([savepath ext(get(ascii, 'value')+1,:)]);
    if ~isempty(name) & name ~= 0
      fname = [p name];
    end
  end

  if ~isempty(fname)
    f=watchon;
	Profile=[Xprofile Yprofile];
    eval(['save ' fname ' Profile ' fmode(get(ascii, 'value')+1,:)]);
	statusbar(['X and Y profile values saved in ' fname]);
    watchoff(f);
    clearstatusbar('WAIT');
  end

end  % SAVE

⌨️ 快捷键说明

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