View License

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

» Watch video

Highlights from

4.7 | 10 ratings Rate this file 51 Downloads (last 30 days) File Size: 2.2 KB File ID: #7347 Version: 1.0
image thumbnail



Brett Shoelson (view profile)


01 Apr 2005 (Updated )

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

| Watch this File

File Information

[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);

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

MATLAB release MATLAB 7.0.1 (R14SP1)
Other requirements Tested successfully in R12.1 through R14.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (13)
01 Jun 2015 James Mure-Dubois

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

Comment only
01 Jun 2015 James Mure-Dubois

29 Jan 2014 Han

Han (view profile)

08 Apr 2011 Brett Shoelson

Brett Shoelson (view profile)

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

Comment only
06 Apr 2011 AA

AA (view profile)

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

Comment only
20 Oct 2009 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.

11 Sep 2009 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')

31 May 2009 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

03 Apr 2009 Arthur

Arthur (view profile)

useful tool!

26 Jul 2007 Ian Howat

Great, easy to use tool, thanks!

07 Mar 2007 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.

02 Oct 2005 Niv Peled

Very good!

13 Jul 2005 Felix Bollenbeck

very usefull!

06 Apr 2005

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

Contact us