📄 snake_demo.mht
字号:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% Information for all buttons
labelColor=3D[0.8 0.8 0.8];
top=3D0.95;
bottom=3D0.05;
labelSpace =3D .19;
btnCnt =3D 10 + 2*2; % 10 singles, 2 =
doubles
btnSpread =3D 0.01; % Border Spread
btnSize =3D (top-bottom-btnSpread)/btnCnt - btnSpread;
space =3D btnSize+btnSpread;
left=3D0.68;
btnWid=3D0.28;
% Spacing between the button and the next command's label
% spacing=3D0.02;
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The CONSOLE frame
frmBorder=3D0.02;
yPos=3D0.05-frmBorder;
frmPos=3D[left-frmBorder bottom btnWid+2*frmBorder top-bottom];
h=3Duicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.50 0.50 0.50]);
bottom =3D bottom + btnSpread;
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Iterate button
labelStr=3D'Iterate';
infoHndl=3Duicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom btnWid 2*btnSize], ...
'String',labelStr, ...
'Callback','snake_demo(''iterate'')');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Clear button
labelStr=3D'Clear Points';
clearHndl=3Duicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+2*space + space btnWid =
2*btnSize/2], ...
'String',labelStr, ...
'Callback','snake_demo(''clear'')');
%%
%% Added by me
%%
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% Load New Image button
labelStr =3D 'Load New Image';
loadHndl=3Duicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+2*space btnWid 2*btnSize/2], ...
'String',labelStr, ...
'Callback','snake_demo(''loadImage'')');
%%
%%
%%
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Display Gradient Checkbox
displayHndl=3Duicontrol( ...
'Style','checkbox', ...
'Units','normalized', ...
'Position',[left bottom+4*space btnWid 1*btnSize], ...
'String','Display Gradient', ...
'Callback','snake_demo(''redraw'')');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Compute Gradient Checkbox
useGradHndl=3Duicontrol( ...
'Style','checkbox', ...
'Units','normalized', ...
'Position',[left bottom+5*space btnWid 1*btnSize], ...
'String','Fit to Gradient', 'Value', 0,...
'Callback', 'snake_demo(''redraw'')');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Sigma EditBox
sigmaHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+6*space ...
btnWid-labelSpace 1*btnSize], ...
'String','1.5');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Sigma Label
sigmaLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+6*space labelSpace 1*btnSize], ...
'String', 'Gaussian Sigma');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Beta EditBox
betaHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+7*space ...
btnWid-labelSpace 1*btnSize], ...
'String','0.1');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Beta Label
betaLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+7*space labelSpace 1*btnSize], ...
'String', 'Beta');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Y-Delta EditBox
YdeltaHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+8*space ...
btnWid-labelSpace 1*btnSize], ...
'String','1');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Y-Delta Label
YdeltaLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+8*space labelSpace 1*btnSize], ...
'String', 'Y Range');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Y-Resolution EditBox
YresolutionHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+9*space ...
btnWid-labelSpace 1*btnSize], ...
'String','1');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The Y-Resolution Label
YresolutionLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+9*space labelSpace 1*btnSize], ...
'String', 'Y Resolution');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The X-Delta EditBox
XdeltaHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+10*space ...
btnWid-labelSpace 1*btnSize], ...
'String','1');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The X-Delta Label
XdeltaLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+10*space labelSpace 1*btnSize], ...
'String', 'X Range');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The X-Resolution EditBox
XresolutionHndl=3Duicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',[left+labelSpace bottom+11*space ...
btnWid-labelSpace 1*btnSize], ...
'String','1');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The X-Resolution Label
resolutionLabelHndl=3Duicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',[left bottom+11*space labelSpace 1*btnSize], ...
'String', 'X Resolution');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The HELP parameters button
HelpHndl=3Duicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left bottom+12*space btnWid 1*btnSize], ...
'String','Parameter Help',...
'Callback','snake_demo(''helpparm'')');
=
%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% The HELP button
HelpHndl=3Duicontrol( ...
'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 =3D str2num(get(betaHndl,'String'));
if beta <=3D 0
beta =3D 0.02;
set(betaHndl,sprintf('%g',beta));
end
alpha =3D 0.1*ones(1,size(snakePoints,1));
beta =3D beta*ones(1,size(snakePoints,1));
gamma =3D 0.5*ones(1,size(snakePoints,1));
XmaxDelta =3D str2num(get(XdeltaHndl,'String'));
if XmaxDelta <=3D 0
XmaxDelta =3D 0;
set(XdeltaHndl, 'String', sprintf('%g',XmaxDelta));
end
Xresolv =3D str2num(get(XresolutionHndl,'String'));
if Xresolv <=3D 1
Xresolv =3D 1;
set(XresolutionHndl, 'String', sprintf('%g',Xresolv));
end
YmaxDelta =3D str2num(get(YdeltaHndl,'String'));
if YmaxDelta < 0
YmaxDelta =3D 0;
set(YdeltaHndl, 'String', sprintf('%g',YmaxDelta));
end
Yresolv =3D str2num(get(YresolutionHndl,'String'));
if Yresolv < 1
Yresolv =3D 1;
set(YresolutionHndl, 'String', sprintf('%g',Yresolv));
end
if get(useGradHndl, 'Value')
=
eval(saveGlobals);snake_demo('computegrad');eval(loadGlobals);
[snakePoints e]=3D snake(snakePoints, alpha, beta, =
gamma, ...
XmaxDelta,Xresolv, ...
YmaxDelta, Yresolv,...
snakeImage,...
snakeGradient);
else
[snakePoints e]=3D 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 =3D get(gca,'CurrentPoint');
x =3D currPt(1,1);
y =3D currPt(1,2);
if ~(movingPoint > 0)
dist =3D (snakePoints(:,1)-x).^2 + =
(snakePoints(:,2)-y).^2;
[error movingPoint] =3D min(dist);
line(snakePoints(movingPoint,1), ...
snakePoints(movingPoint,2), ...
'LineStyle','.', ...
'Color','g', ...
'MarkerSize', 25, ...
'EraseMode','none');
end
snakePoints(movingPoint,:) =3D [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 =3D size(snakePoints,1);
if numPts > 0
currPt =3D snakePoints(1,:);
line(currPt(1),currPt(2), ...
'LineStyle','.', ...
'Color','r', ...
'MarkerSize', 25, ...
'EraseMode','none');
end
for i=3D2:numPts
currPt =3D 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 =3D 0;
elseif strcmp(action, 'loadImage')
clear newImageName;
newImageName =3D input( 'Type a (gif) file name enclosed in single =
quotes: ' );
[pixels, colorMap] =3D gifread( newImageName );
snakeImage =3D ind2gray( pixels, colorMap );
[grayPixels, theColorMap] =3D gray2ind( snakeImage, 256 );
colormap( theColorMap );
eval(saveGlobals);
snake_demo('computegrad');
snake_demo('redraw');
eval(loadGlobals);
else
disp('Illegal command');
end
eval(saveGlobals);
</PRE></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -