countmolecules.m
来自「matlab处理图像的一些基本方法。其中有一部分mex程序需要安装编译」· M 代码 · 共 224 行
M
224 行
function countmolecules(command)%COUNTMOLECULES Counts the molecules clicked by the user.%% COUNTMOLECULES(COMMAND)%% COMMAND: START Begin the session % COUNT Do the counting% UNDO Clear the last input% CLEAR Clear all the counting% CLOSEIMAGE When the image is going to be closed% DONE close the session%% Claudio May, 22 1995%% Copyright (c) 1995 by Claudio Rivetti and Mark Young% claudio@alice.uoregon.edu, mark@alice.uoregon.edu%global Handlefig Handleimgax B_frame Uibgcolor count_txt hline xd yd zd SelObjglobal lsm olden Undofun CloseImageFun%%%%%%%%%%%%%%% START %%%%%%%%%%%%%%%%%%%%%%%%if strcmp(upper(command), 'START') if ~isimage setviewmode('TOPVIEW'); showimage; end figure(Handlefig); CloseImageFun='countmolecules(''CLOSEIMAGE'');'; obj=SelObj; countmolecules('LINE'); SelObj=hline; setclipboard(1); % Position variables--------------------------------------------------- pos=get(B_frame, 'Position'); uiwidth=0.12; uithick=0.035; middle=pos(1)+(pos(3)-uiwidth)/2; %--------------------------------------------------------------------- whendone='countmolecules(''DONE'');'; count_cbk=['countmolecules(''COUNT'');']; undo_cbk =['countmolecules(''UNDO'');']; clear_cbk =['countmolecules(''CLEAR'');']; Undofun=undo_cbk; % Positions of buttons ----------------------------------------------------- f1pos= [middle-0.02 pos(2)+0.47 uiwidth+0.04 0.25]; count_bt_pos=[middle, pos(2)+0.68-uithick, uiwidth, uithick]; counter_txt_pos=[middle, pos(2)+0.55, uiwidth, uithick]; count_txt_pos=[middle, pos(2)+0.55-uithick, uiwidth, uithick]; f2pos= [middle-0.02 pos(2)+0.16 uiwidth+0.04 0.21]; undo_bt_pos=[middle, pos(2)+0.33-uithick, uiwidth, uithick]; clear_bt_pos=[middle, pos(2)+0.23-uithick, uiwidth, uithick]; %--------------------------------------------------------------------------- initbuttons('Molecule Counter', 'Done', whendone); lsm=findobj('label', ' Line Style'); olden=get(lsm, 'Enable'); set(lsm, 'Enable', 'off'); uicontrol(gcf, 'Style', 'frame',... 'Units', 'normalized',... 'Position',f1pos,... 'BackgroundColor', Uibgcolor); count_bt = uicontrol(Handlefig, 'Style', 'push',... 'String', 'Count',... 'Units', 'normalized',... 'Position', count_bt_pos,... 'HorizontalAlignment', 'center',... 'Inter', 'yes',... 'CallBack', count_cbk); uicontrol(Handlefig, 'Style', 'text',... 'String', 'Counter',... 'Units', 'normalized',... 'Position', counter_txt_pos,... 'Backgroundcolor', Uibgcolor,... 'HorizontalAlignment', 'center'); count_txt = uicontrol(Handlefig, 'Style', 'text',... 'String', int2str(length(xd)),... 'Value', length(xd),... 'Units', 'normalized',... 'Position', count_txt_pos,... 'Backgroundcolor', 'w',... 'HorizontalAlignment', 'center'); uicontrol(gcf, 'Style', 'frame',... 'Units', 'normalized',... 'Position',f2pos,... 'BackgroundColor', Uibgcolor); undo_bt = uicontrol(Handlefig, 'Style', 'push',... 'String', 'Undo',... 'Units', 'normalized',... 'Position', undo_bt_pos,... 'HorizontalAlignment', 'center',... 'CallBack', undo_cbk); clear_bt = uicontrol(Handlefig, 'Style', 'push',... 'String', 'Clear',... 'Units', 'normalized',... 'Position', clear_bt_pos,... 'HorizontalAlignment', 'center',... 'CallBack', clear_cbk);end % STARTif strcmp(upper(command), 'COUNT') ax=Handleimgax; if any(get(ax,'view')~=[0 90]), error('Works only on 2-D plots'); end btndown = get(gcf,'windowbuttondownfcn'); btnup = get(gcf,'windowbuttonupfcn'); btnmotion = get(gcf,'windowbuttonmotionfcn'); set(gcf,'windowbuttondownfcn','','windowbuttonupfcn','', ... 'windowbuttonmotionfcn','') ax=axis; while 1 [x,y,b]=ginput(1); if b==3, break; end if (x>=ax(1) & x<=ax(2)) & (y>=ax(3) & y<=ax(4)) xd=[xd x]; yd=[yd y]; zd=xd*0+1000; c=get(count_txt, 'value'); set(count_txt, 'value', c+1, 'string', int2str(c+1)); countmolecules('LINE'); end end set(gcf,'windowbuttondownfcn',btndown,'windowbuttonupfcn',btnup, ... 'windowbuttonmotionfcn',btnmotion)end % COUNTif strcmp(upper(command), 'LINE') if isempty(findobj('tag', 'counterline')) if isempty(xd) ax=axis; hline = line(ax(1)-10, ax(3)-10, -10,... 'erasemode','background','linestyle','x','Color',getpencolor,... 'linewidth', getlinewidth,'tag','counterline','visible','off'); else hline = line(xd, yd, zd,... 'erasemode','background','linestyle','x','Color',getpencolor,... 'linewidth', getlinewidth,'tag','counterline','visible','on'); end else set(hline,'xdata',xd,'ydata',yd, 'zdata',zd); set(hline, 'visible', 'on'); end drawnow;end % LINEif strcmp(upper(command), 'UNDO') if ~isempty(xd) xd=xd(1:length(xd)-1); yd=yd(1:length(yd)-1); zd=zd(1:length(zd)-1); c=get(count_txt, 'value'); set(count_txt, 'value', c-1, 'string', int2str(c-1)); countmolecules('LINE'); drawnow; endend % UNDOif strcmp(upper(command), 'CLEAR') xd=[]; yd=[]; zd=[]; set(count_txt, 'value', 0, 'string', '0'); countmolecules('LINE'); refresh;end % CLEARif strcmp(upper(command), 'CLOSEIMAGE') xd=[]; yd=[]; zd=[]; set(count_txt, 'value', 0, 'string', '0');end % CLOSEIMAGEif strcmp(upper(command), 'DONE') SelObj=obj; CloseImageFun=''; set(lsm, 'Enable', olden); l=findobj('tag', 'counterline'); if ~isempty(l) delete(l); end refresh;end % DONE
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?