| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Image Processing Toolbox |
| Contents | Index |
| Learn more about Image Processing Toolbox |
h = imfreehand
h = imfreehand(hparent)
h = imfreehand(...,param1, val1,...)
h = imfreehand begins interactive placement of a freehand region of interest on the current axes. The function returns h, a handle to an imfreehand object. A freehand region of interest can be dragged interactively using the mouse and supports a context menu that controls aspects of its appearance and behavior. See Interactive Behavior.
h = imfreehand(hparent) begins interactive placement of a freehand region of interest on the object specified by hparent. hparent specifies the HG parent of the freehand region graphics, which is typically an axes, but can also be any other object that can be the parent of an hggroup.
h = imfreehand(...,param1, val1,...) creates a freehand ROI, specifying parameters and corresponding values that control the behavior of the tool. The following table lists the parameters available. Parameter names can be abbreviated, and case does not matter.
| Parameter | Description |
|---|---|
| 'Closed' | Scalar logical that controls whether the freehand region is closed. When set to true (the default), imfreehand draws a straight line to connect the endpoints of the freehand line to create a closed region. If set to false, imfreehand leaves the region open. |
| 'PositionConstraintFcn' | Function handle specifying the function that is called whenever the freehand region is dragged using the mouse. Use this parameter to control where the freehand region can be dragged. See the help for the setPositionConstraintFcn method for information about valid function handles. |
When you call imfreehand with an interactive
syntax, the pointer changes to a cross hairs
when positioned over an
image. Click and drag the mouse to draw the freehand region. By default, imfreehand draws
a straight line connecting the last point you drew with the first
point, but you can control this behavior using the 'Closed' parameter.
The following figure illustrates a freehand region with its context
menu.

The following table lists the interactive features supported by imfreehand.
| Interactive Behavior | Description |
|---|---|
| Moving the region. | Move the pointer inside the freehand region. The pointer changes
to a fleur shape
|
| Changing the color used to draw the region. | Move the pointer inside the freehand region. Right-click and select Set Color from the context menu. |
| Retrieving the current position of the freehand region. | Move the pointer inside the freehand region. Right-click and select Copy Position from the context menu. imfreehand copies an n-by-2 array of coordinates on the boundary of the ROI to the clipboard.. |
The imfreehand object supports the following methods. Type methods imfreehand to see a complete list of all methods.
See imroi for information.
See imroi for information.
See imroi for information.
See imroi for information.
pos = getPosition(h) returns the current position of the freehand region h. The returned position, pos, is an N-by-2 array [X1 Y1;...;XN YN].
See imroi for information.
See imroi for information.
See imroi for information.
setClosed(h,TF) sets the geometry of the freehand region h. TF is a logical scalar. True means that the freehand region is closed. False means that the freehand region is open.
See imroi for information.
See imroi for information.
See imroi for information.
See imroi for information.
If you use imfreehand with an axes that contains an image object, and do not specify a position constraint function, users can drag the freehand region outside the extent of the image and lose the freehand region. When used with an axes created by the plot function, the axes limits automatically expand to accommodate the movement of the freehand region.
Interactively place a closed freehand region of interest by clicking and dragging over an image.
figure, imshow('pout.tif');
h = imfreehand(gca);
Interactively place a freehand region by clicking and dragging. Use the wait method to block the MATLAB command line. Double-click on the freehand region to resume execution of the MATLAB command line.
figure, imshow('pout.tif');
h = imfreehand;
position = wait(h);
imellipse, imline, impoint, impoly, imrect, iptgetapi, makeConstrainToRectFcn
![]() | imfilter | imgca | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |