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

📄 snake_demo.m

📁 Tracking a moving object through several frames, provided changes from frame to frame are on the ord
💻 M
📖 第 1 页 / 共 2 页
字号:
%    spacing=0.02;    %====================================    % The CONSOLE frame    frmBorder=0.02;    yPos=0.05-frmBorder;    frmPos=[left-frmBorder bottom btnWid+2*frmBorder top-bottom];    h=uicontrol( ...        'Style','frame', ...        'Units','normalized', ...        'Position',frmPos, ...                'BackgroundColor',[0.50 0.50 0.50]);        bottom = bottom + btnSpread;    %====================================    % The Iterate button    labelStr='Iterate';    infoHndl=uicontrol( ...        'Style','pushbutton', ...        'Units','normalized', ...        'Position',[left bottom btnWid 2*btnSize], ...        'String',labelStr, ...        'Callback','snake_demo(''iterate'')');    %====================================    % The Clear button    labelStr='Clear Points';    clearHndl=uicontrol( ...        'Style','pushbutton', ...        'Units','normalized', ...        'Position',[left    bottom+2*space + space   btnWid 2*btnSize/2], ...        'String',labelStr, ...        'Callback','snake_demo(''clear'')');%%%% Added by me%%    %====================================    % Load New Image button    labelStr = 'Load New Image';    loadHndl=uicontrol( ...        'Style','pushbutton', ...        'Units','normalized', ...        'Position',[left bottom+2*space btnWid 2*btnSize/2], ...        'String',labelStr, ...        'Callback','snake_demo(''loadImage'')');%%%%%%    %====================================    % The Display Gradient Checkbox    displayHndl=uicontrol( ...        'Style','checkbox', ...        'Units','normalized', ...        'Position',[left bottom+4*space btnWid 1*btnSize], ...        'String','Display Gradient', ...        'Callback','snake_demo(''redraw'')');    %====================================    % The Compute Gradient Checkbox    useGradHndl=uicontrol( ...        'Style','checkbox', ...        'Units','normalized', ...        'Position',[left bottom+5*space btnWid 1*btnSize], ...        'String','Fit to Gradient', 'Value', 0,...        'Callback', 'snake_demo(''redraw'')');    %====================================    % The Sigma EditBox    sigmaHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+6*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','1.5');    %====================================    % The Sigma Label    sigmaLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+6*space labelSpace 1*btnSize], ...        'String', 'Gaussian Sigma');    %====================================    % The Beta EditBox    betaHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+7*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','0.1');    %====================================    % The Beta Label    betaLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+7*space labelSpace 1*btnSize], ...        'String', 'Beta');    %====================================    % The Y-Delta EditBox    YdeltaHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+8*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','1');    %====================================    % The Y-Delta Label    YdeltaLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+8*space labelSpace 1*btnSize], ...        'String', 'Y Range');    %====================================    % The Y-Resolution EditBox    YresolutionHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+9*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','1');    %====================================    % The Y-Resolution Label    YresolutionLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+9*space labelSpace 1*btnSize], ...        'String', 'Y Resolution');    %====================================    % The X-Delta EditBox    XdeltaHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+10*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','1');    %====================================    % The X-Delta Label    XdeltaLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+10*space labelSpace 1*btnSize], ...        'String', 'X Range');    %====================================    % The X-Resolution EditBox    XresolutionHndl=uicontrol( ...        'Style','edit', ...        'Units','normalized', ...        'Position',[left+labelSpace bottom+11*space ...                    btnWid-labelSpace 1*btnSize], ...        'String','1');    %====================================    % The X-Resolution Label    resolutionLabelHndl=uicontrol( ...        'Style','text', ...        'Units','normalized', ...        'Position',[left bottom+11*space labelSpace 1*btnSize], ...        'String', 'X Resolution');    %====================================    % The HELP parameters button    HelpHndl=uicontrol( ...        'Style','pushbutton', ...        'Units','normalized', ...        'Position',[left bottom+12*space btnWid 1*btnSize], ...        'String','Parameter Help',...        'Callback','snake_demo(''helpparm'')');    %====================================    % The HELP button    HelpHndl=uicontrol( ...        'Style','pushbutton', ...        'Units','normalized', ...        'Position',[left bottom+13*space btnWid 1*btnSize], ...        'String','Help',...        'Callback','snake_demo(''help'')');%%        eval(saveGlobals);           snake_demo('computegrad');        eval(loadGlobals);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The iterate command - Perform one iteration of the snake search%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(action,'iterate')        if size(snakePoints,1) < 1                disp('Need to specify control points first.');                eval(saveGlobals); return;        end        beta = str2num(get(betaHndl,'String'));        if beta <= 0                beta = 0.02;                set(betaHndl,sprintf('%g',beta));        end        alpha = 0.1*ones(1,size(snakePoints,1));        beta  = beta*ones(1,size(snakePoints,1));        gamma = 0.5*ones(1,size(snakePoints,1));        XmaxDelta = str2num(get(XdeltaHndl,'String'));        if XmaxDelta <= 0                XmaxDelta = 0;                set(XdeltaHndl, 'String', sprintf('%g',XmaxDelta));        end        Xresolv = str2num(get(XresolutionHndl,'String'));        if Xresolv <= 1                Xresolv = 1;                set(XresolutionHndl, 'String', sprintf('%g',Xresolv));        end        YmaxDelta = str2num(get(YdeltaHndl,'String'));        if YmaxDelta < 0                YmaxDelta = 0;                set(YdeltaHndl, 'String', sprintf('%g',YmaxDelta));        end        Yresolv = str2num(get(YresolutionHndl,'String'));        if Yresolv < 1                Yresolv = 1;                set(YresolutionHndl, 'String', sprintf('%g',Yresolv));        end        if get(useGradHndl, 'Value')                eval(saveGlobals);snake_demo('computegrad');eval(loadGlobals);                [snakePoints e]= snake(snakePoints, alpha, beta, gamma, ...                                       XmaxDelta,Xresolv, ...                                       YmaxDelta, Yresolv,...                                       snakeImage,...                                       snakeGradient);        else                [snakePoints e]= snake(snakePoints, alpha, beta, gamma, ...                                       XmaxDelta,Xresolv, ...                                       YmaxDelta, Yresolv,...                                       snakeImage,...                                       snakeGradient);        end        eval(saveGlobals); snake_demo('redraw'); eval(loadGlobals);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The movePoint command - Move a point in the path%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(action, 'movePoint')        currPt = get(gca,'CurrentPoint');    x = currPt(1,1);        y = currPt(1,2);        if ~(movingPoint > 0)                dist = (snakePoints(:,1)-x).^2 + (snakePoints(:,2)-y).^2;                [error movingPoint] = min(dist);                line(snakePoints(movingPoint,1), ...                                snakePoints(movingPoint,2), ...                                'LineStyle','.', ...                                'Color','g', ...                                'MarkerSize', 25, ...                                'EraseMode','none');        end        snakePoints(movingPoint,:) = [x y];        eval(saveGlobals); snake_demo('redraw'); eval(loadGlobals);%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The redraw command - Draw the image and the current path%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(action, 'redraw')        if get(displayHndl, 'Value')                eval(saveGlobals);snake_demo('computegrad');eval(loadGlobals);                imagesc(snakeGradient);        else                imagesc(snakeImage);        end        axis('equal')        axis('off')%%%        colormap(1-gray);        colormap( theColorMap );%%%        numPts = size(snakePoints,1);        if numPts > 0                currPt = snakePoints(1,:);                line(currPt(1),currPt(2), ...                        'LineStyle','.', ...                        'Color','r', ...                        'MarkerSize', 25, ...                        'EraseMode','none');        end        for i=2:numPts                currPt = snakePoints(i,:);                line(currPt(1),currPt(2), ...                        'LineStyle','.', ...                        'Color','r', ...                        'MarkerSize', 25, ...                        'EraseMode','none');                line(snakePoints([i-1 i],1),snakePoints([i-1 i],2), ...                'Color','b', ...                'EraseMode','none');        end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% The up command - Mouse button is up, stop changing the path%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%elseif strcmp(action, 'up')        set(gcf,'WindowButtonMotionFcn','');        set(gcf,'WindowButtonUpFcn','');        movingPoint = 0;elseif strcmp(action, 'loadImage')     clear newImageName;     newImageName = input( 'Type a (gif) file name enclosed in single quotes: ' );     [pixels, colorMap] = gifread( newImageName );     snakeImage = ind2gray( pixels, colorMap );     [grayPixels, theColorMap] = gray2ind( snakeImage, 256 );     colormap( theColorMap );     eval(saveGlobals);       snake_demo('computegrad');       snake_demo('redraw');     eval(loadGlobals);else        disp('Illegal command');endeval(saveGlobals);

⌨️ 快捷键说明

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