1.
hFH = imfreehand(); %Choose ROI using freehand tool
画出的是连续的图形.曲线自动闭合且只能画一次.
2.
类似点画线,任意图形.
S.fh = figure('units','pixels',...
'position',[300 300 400 400],...
'menubar','none',...
'name','GUI_39',...
'numbertitle','off',...
'resize','off');
S.ax = axes('units','pixels',...
'position',[20 20 360 350],...
'Xlim',[0 1],...
'YLim',[0 1],...
'drawmode','fast');
S.cm = uicontextmenu;
% Set the uicontextmenu to point to the axes.
set(S.ax, 'buttondownfcn',@ax_bdfcn,'uicontextmenu',S.cm)
hold on, box on % So that we don't overwrite with each new point drawn.
set(S.fh,'windowbuttonupfcn', @fh_wbufcn);
function [] = ax_bdfcn(varargin)
% ButtonDownFcn for the axes.
% We only want to do something if left clicking.
if strcmp(get(S.fh,'selectiontype'),'normal')
% We want to plot dots as long as user holds down mouse button.
set(S.fh, 'windowbuttonmotionfcn', @fh_wbmfcn)
end
end
function [] = fh_wbmfcn(varargin)
% The windowbuttonmotionfcn for figure, while button is held only.
pt = get(S.ax, 'currentpoint');
plot(pt(1),pt(3),'.','buttondownfcn',@ax_bdfcn,'color',S.COL);
end
function [] = fh_wbufcn(varargin)
% WindowButtonUpFcn for the figure.
% We want to stop drawing dots when user lets mouse button up.
set(S.fh, 'windowbuttonmotionfcn', '');
end