Create draggable, resizable line
imline is not recommended. Use
imline object encapsulates an interactive line over an
You can adjust the size and position of the line by using the mouse. The line also has a context menu that controls aspects of its appearance and behavior. For more information, see Usage.
h = imline
h = imline(hparent)
h = imline(hparent,position)
h = imline(hparent,x,y)
h = imline(___,Name,Value)
h = imline begins interactive placement of a line on the
current axes, and returns an
h = imline( begins
interactive placement of a line on the object specified by
h = imline(___,
specifies name-value pairs that control the behavior of the line.
hparent— Handle to parent object
Handle to parent object, specified as a handle. The parent is
typically an axes object, but can also be any other object that can be
the parent of an
position— Position of line endpoints
Position of line endpoints, specified as a 2-by-2 array of the form
[x1 y1; x2 y2].
x— x-coordinates of line endpoints
x-coordinates of line endpoints, specified as a
2-element vector of the form
x = [x1 x2].
y— y-coordinates of line endpoints
y-coordinates of line endpoints, specified as a
2-element vector of the form
y = [y1 y2].
comma-separated pairs of
the argument name and
Value is the corresponding value.
Name must appear inside quotes. You can specify several name and value
pair arguments in any order as
'PositionConstraintFcn'— Position constraint function
Position constraint function, specified as the comma-separated
pair consisting of
'PositionConstraintFcn' and a
fcn is called whenever the mouse
is dragged. You can use this function to control where the line can
be dragged. See the help for the
setPositionConstraintFcn function for information
about valid function handles.
Deletable— ROI can be deleted
ROI can be deleted, specified as
When you call
imline with an interactive syntax, the pointer
changes to a cross hairs when over the image. Click and drag the mouse to
specify the position and length of the line. The line supports a context menu that you
can use to control aspects of its appearance and behavior.
The table describes the interactive behavior supported by
|Moving the line.||Move the pointer over the line. The pointer changes to a fleur shape . Click and drag the mouse to move the line.|
|Moving the endpoints of the line.||Move the pointer over either end of the line. The pointer changes to the pointing finger, . Click and drag the mouse to resize the line.|
|Changing the color used to display the line.||Move the pointer over the line. Right-click and select Set Color from the context menu.|
|Retrieving the coordinates of the endpoints of the line.||Move the pointer over the line. Right-click and select
Copy Position from the context menu.
|Deleting the line||Move the pointer on top of the line. Right-click and select
Delete from the context menu. To remove
this option from the context menu, set the |
imline object supports a number of methods. Type
methods imline to see a complete list.
|Add new-position callback to ROI object|
|Create mask within image|
|Delete handle object|
|Get color used to draw ROI object|
|Return current position of ROI object|
|Return function handle to current position constraint function|
|Remove new-position callback from ROI object|
|(Not recommended) Resume execution of MATLAB command line|
|Set color used to draw ROI object|
|Set ROI object to new position|
|Move ROI object to new position|
|Set position constraint function of ROI object|
|(Not recommended) Block MATLAB command line until ROI creation is finished|
Use a custom color for displaying the line. Use
addNewPositionCallback method. Move the line, note that the 2-by-2
position vector of the line is displayed in the title above the image. Explore the
context menu of the line by right clicking on the line.
imshow('pout.tif') h = imline(gca,[10 100],[100 100]); setColor(h,[0 1 0]); id = addNewPositionCallback(h,@(pos) title(mat2str(pos,3)));
After observing the callback behavior, remove the callback using the
Interactively place a line by clicking and dragging. Use
wait to block the
MATLAB® command line. Double-click on the line to
execution of the MATLAB command line.
imshow('pout.tif') h = imline; position = wait(h);
If you use
imline with an axes that contains an image
object, and do not specify a position constraint function, users can drag the
line outside the extent of the image and lose the line. When used with an axes
created by the
plot function, the axis limits automatically
expand to accommodate the movement of the line.
imdistline to create an
interactive line with a text box that displays the distance between line