File Exchange

image thumbnail

freehanddraw

version 1.0 (2.2 KB) by

Draw smooth lines freehand on images or plots; return the handle and xy data of the line object.

22 Downloads

Updated

View License

[LINEOBJ,XS,YS] = FREEHANDDRAW(ax_handle,line_options)

Draw a smooth freehand line object on the current axis (default),or on the axis specified by handle in the first input argument. Left-click once to begin drawing, right-click to terminate, or double-click to close contour and terminate.

INPUT ARGUMENTS: First: axis handle (optional)
Additional: valid line property/value pairs

OUTPUT ARGUMENTS: 1) Handle to line object
2) x-data
3) y-data
(Note that output args 2 & 3 can also be extracted from the first output argument.)

Ex: [myobj,xs,ys] = freehanddraw(gca,'color','r','linewidth',3);
freehanddraw('linestyle','--');

Written by Brett Shoelson, PhD
shoelson@helix.nih.gov
3/29/05. Modified 10/05/06 to allow double-click contour closure.

Comments and Ratings (13)

on R2014b on Ubuntu (12.04 LTS), I had to comment out line 82 :
'doublebuffer',oldvals.DoubleBuffer
since my figure does not have this field, but otherwise this function worked perfectly !

Han

Han (view profile)

Brett Shoelson

Brett Shoelson (view profile)

AA,
IMFREEHAND didn't exist when I wrote FREEHANDDRAW. I'm happy to see that you're using the new Toolbox functionality!

AA

AA (view profile)

how is the following different from what the file outputs?
figure; imshow('pout.tif');
h = imfreehand;data=get(h);
xydata=get(data.Children(4));
x=xydata.XData;
y=xydata.YData;
figure; plot(x,y,'-.')
These statements give the x, y data of an arbitrary freehand drawing on a figure.

Image Analyst

Image Analyst (view profile)

I had been using this with R2008b and discovered that it's still "broken" in R2009b, but thanks to Paul Groot's helpful comment, it's now working again. However, now that the Image Processing Toolbox has imfreehand(), maybe you could use that instead.

Paul Groot

Very nice work!
Noticed a small issue, which may only occur in recent (R2009a) releases: The DoubleBuffer property seems not always present in the oldvals structure at line 82. This could be solved by moving it to a separate line:

if isfield(oldvals, 'DoubleBuffer')
set(gcf,'doublebuffer',oldvals.DoubleBuffer);
end

De

De (view profile)

Very good work works very nicely !!!
Has anyone managed to merge the line object to the actual image one is drawing upon.... i.e change the value of the actual image pixels .. Thanks

Arthur

Arthur (view profile)

useful tool!

Ian Howat

Great, easy to use tool, thanks!

Jared Goor

Works great. This saved me a ton of coding. I turned it into an eraser by making a mask of the points, dilating them, and applying the mask to the image. The only drawback with my application of this program is that the tool drops points if you move it too fast so you don't get perfectly continuous lines. Regardless, great program. Don't forget to input the axes you are working with, NOT the image. Easy mistake for NBs like me.

Niv Peled

Very good!

Felix Bollenbeck

very usefull!

Updates

Mistakenly cited ability to draw in 3D. Function returns xy- data, NOT xyz data.

MATLAB Release
MATLAB 7.0.1 (R14SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video