function image_recon(command) %IMAGE_RECON preform the image/tip reconstruction % % Copyright (c) 1995 by Claudio Rivetti and Mark Young % claudio@alice.uoregon.edu, mark@alice.uoregon.edu % global prevtype prevmode prevpath prevfname prevradius mtt radius_ed find_bt fname_ed fname_txt global Handlefig H I B_frame Uibgcolor readpath radio_unit Runits if nargin==0 command='START'; end 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 ----------------------------------------------------- rbframe_pos = [pos(1)+0.01, pos(2)+.45, pos(3)-0.02 0.25]; sp=rbframe_pos(4)/5; txrbframe_pos=[rbframe_pos(1), rbframe_pos(2)+rbframe_pos(4), rbframe_pos(3), uithick]; modetxt_pos=[rbframe_pos(1), rbframe_pos(2)+2*sp+0.05, rbframe_pos(3), uithick]; tt_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+4*sp+0.02, rbframe_pos(3)-0.01, uithick]; rb1_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+2*sp+0.02, rbframe_pos(3)-0.01, uithick]; rb2_pos=[rbframe_pos(1)+0.005, rbframe_pos(2)+1*sp+0.02, rbframe_pos(3)-0.01, uithick]; fname_txt_pos=[rbframe_pos(1), rbframe_pos(2)-0.01, rbframe_pos(3), uithick]; fname_ed_pos=[rbframe_pos(1), rbframe_pos(2)-0.01-uithick, rbframe_pos(3), uithick]; radius_ed_pos=[rbframe_pos(1), rbframe_pos(2)-0.01-uithick, 0.08, uithick]; radius_ed_pos=[middle rbframe_pos(2)-0.01-uithick uiwidth, uithick]; find_pos = [middle pos(2)+0.35 uiwidth, uithick]; undo_pos = [middle pos(2)+0.15 uiwidth, uithick]; exec_pos = [middle pos(2)+0.25 uiwidth, uithick]; areatxt_pos = [middle-.01 pos(2)+0.55 uiwidth+.02, uithick]; areaed_pos = [middle pos(2)+0.52 uiwidth, uithick]; %--------------------------------------------------------------------------- % Callbacks for the buttons --------------------------------------------------- whendone='image_recon(''SET'');'; tt_cbk='image_recon(''SET'');'; find_cbk ='image_recon(''FIND'');'; exec_cbk = 'image_recon(''RECON'');'; rb_cbk='image_recon(''RADIO'');'; undo_cbk = 'undo;'; %------------------------------------------------------------------------------- if strcmp(upper(command), 'START') if isempty(prevtype), prevtype=1;end if isempty(prevradius), prevradius=20;end if isempty(prevmode), prevmode=1;end initbuttons('Reconstruction', 'Done', whendone); uicontrol(Handlefig, 'Style', 'text',... 'String', 'Tip Shape',... 'Units', 'Normalized',... 'Position', txrbframe_pos,... 'HorizontalAlignment', 'center',... 'BackgroundColor', Uibgcolor); mtt=uicontrol(Handlefig, 'Style', 'popup',... 'String', 'Parabola|Ellipse|Circle|From File...',... 'Units', 'normalized',... 'Position', tt_pos,... 'Value', prevtype,... 'CallBack', tt_cbk,... 'UserData', ['PARABOLIC';'ELLIPTIC ';'CIRCULAR ';'FILE '],... 'HorizontalAlignment', 'left'); uicontrol(Handlefig, 'Style', 'text',... 'String', 'Mode',... 'Units', 'Normalized',... 'Position', modetxt_pos,... 'HorizontalAlignment', 'center',... 'BackgroundColor', Uibgcolor); radio_unit=[0;0]; radio_unit(1) = uicontrol(Handlefig, 'Style', 'radio',... 'String', 'Image - Tip',... 'Units', 'Normalized',... 'Position', rb1_pos,... 'HorizontalAlignment', 'left',... 'Call', rb_cbk,... 'Value', prevmode); radio_unit(2) = uicontrol(Handlefig, 'Style', 'radio',... 'String', 'Image + Tip',... 'Units', 'Normalized',... 'Position', rb2_pos,... 'HorizontalAlignment', 'left',... 'Call', rb_cbk,... 'Value', ~prevmode); [s, Runits]=scansize(H); Runits=strrep(Runits, ' ', ''); if strcmp(Runits, 'pixels') ~=1 Runits='nm'; end fname_txt=uicontrol(Handlefig, 'Style', 'text',... 'String', ['Radius in' Runits],... 'Units', 'normalized',... 'Position', fname_txt_pos,... 'BackgroundColor', Uibgcolor,... 'HorizontalAlignment', 'center'); fname_ed = uicontrol(Handlefig, 'Style', 'edit',... 'String', prevfname,... 'Units', 'normalized',... 'Position', fname_ed_pos,... 'Visible', 'off',... 'HorizontalAlignment', 'left',... 'UserData', prevpath,... 'CallBack', 'set(gco, ''UserData'', '''');'); radius_ed = uicontrol(Handlefig, 'Style', 'edit',... 'String', num2str(prevradius),... 'Units', 'normalized',... 'Position', radius_ed_pos,... 'Visible', 'on',... 'Value', prevradius,... 'HorizontalAlignment', 'center',... 'CallBack', 'editstr2value(gco, 0, inf);'); find_bt=uicontrol(Handlefig,'Style','push',... 'String', 'Find file',... 'Units', 'normalized', ... 'Position', find_pos,... 'Visible', 'off',... 'CallBack',find_cbk); exec = uicontrol(Handlefig,'Style','push',... 'String', 'Execute',... 'Units', 'normalized', ... 'Position', exec_pos,... 'Interruptible', 'yes',... 'CallBack',exec_cbk); undo = uicontrol(Handlefig,'Style','push',... 'String','Undo',... 'Units', 'normalized', ... 'Position', undo_pos,... 'CallBack',undo_cbk); image_recon('SET'); end %START if strcmp(upper(command), 'RADIO') set(radio_unit(find(radio_unit ~= gco)), 'value', 0); set(gco, 'value', 1); image_recon('SET'); end if strcmp(upper(command), 'SET') prevtype=get(mtt, 'value'); prevmode=get(radio_unit(1), 'value'); prevfname=get(fname_ed, 'string'); prevpath=get(fname_ed, 'UserData'); prevradius=get(radius_ed, 'value'); if prevtype==4 set(fname_txt, 'string', 'Tip file name'); set(find_bt, 'Visible', 'on'); set(radius_ed, 'Visible', 'off'); set(fname_ed, 'Visible', 'on'); else set(fname_txt, 'string', ['Radius in ' Runits]); set(find_bt, 'Visible', 'off'); set(fname_ed, 'Visible', 'off'); set(radius_ed, 'Visible', 'on'); end end %SET if strcmp(upper(command), 'FIND') [f,p]=uigetfile([readpath '*.tip']); if ~isempty(f) & f ~= 0 set(fname_ed, 'string', f, 'Userdata', p); end end %FIND if strcmp(upper(command), 'RECON') f=watchon; % Measure the image limits. di=max(size(I)); vmax=max(max(I)); vmin=min(min(I)); scale=1; [ss xu]=scansize(H); [zs zu]=zscale(H); if strcmp(xu, '~m') ss=ss*1000; elseif strcmp(zu, '~m') scale=1000; end rc=get(radius_ed, 'value'); tipfname=[get(fname_ed, 'UserData') get(fname_ed, 'string')]; mode=get(radio_unit(1), 'value'); mode=mode - (mode~=1); type=get(mtt, 'value'); if type==1 %%%%%%%% PARABOLIC TIP %%%%%%%% % calculate the Parabolik matrix % dt is half-1 of tip matrix dimension. dt=ceil(sqrt((vmax-vmin)*2*rc)*(di/ss)); T=zeros(2*dt+1); for x=-dt:dt for y=-dt:dt T(x+dt+1,y+dt+1)=((x*ss/di)^2 + (y*ss/di)^2) / (2*rc); end end %start the tip reconstruction loop if mode==1 setimage(mexrecon(I*scale, T*mode, 1)/scale); elseif mode==-1 setimage(mexconvol(I*scale, T*mode, 1)/scale); end elseif type==2 %%%%%%%%% ELLIPTIC TIP %%%%%%%%% message('Function not defined for this tip shape.'); elseif type==3 %%%%%%%%% CIRCULAR TIP %%%%%%%%% message('Function not defined for this tip shape.'); elseif type==4 %%%%%%%%% TIP FROM FILE %%%%%%% %load the tip profile coordinates eval(['load ' tipfname]); if exist('T')==0 & exist('Tip_profile')==0 alexerror(['Tip file must contain a square matrix|named Tip,',... ' rapresenting the tip image,|or a vector named Tip_profile|',... 'rapresenting the tip profile.']); watchoff(f); return; end if exist('Tip_profile')==1 Tip_profile=Tip_profile-min(Tip_profile); ind=find(Tip_profile < ceil(min(Tip_profile)+(vmax-vmin))); T=maketip(Tip_profile(ind), Tip_profile(ind)); end if mode==1 setimage(mexrecon(I*scale, T*mode, 1)/scale); elseif mode==-1 setimage(mexconvol(I*scale, T*mode, 1)/scale); end end watchoff(f); end %RECON return