(Not recommended) Create draggable point
impoint object encapsulates an interactive point over an
You can adjust the position of the point by using the mouse. The point also has a context menu that controls aspects of its appearance and behavior. For more information, see Usage.
h = impoint begins interactive placement of a point on
the current axes, and returns an
h = impoint( begins
interactive placement of a point on the object specified by
h = impoint(___,"PositionConstraintFcn",
also specifies where the point can be dragged using a position constraint
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 point
Position of point, specified as a 2-element vector of the form
x — x-coordinate of point
x-coordinate of the point, specified as a numeric scalar.
y — y-coordinate of point
y-coordinate of the point, specified as a numeric scalar.
fcn — Position constraint function
Position constraint function, specified as a function handle.
fcn is called whenever the mouse is dragged.
You can use this function to control where the ellipse can be dragged.
See the help for the
setPositionConstraintFcn function for information about
valid function handles.
Deletable — ROI can be deleted
true (default) |
ROI can be deleted, specified as
When you call
impoint with an interactive syntax, the pointer
changes to a cross hairs when over the image. Click and drag the mouse to
specify the position of the point. The point 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 point.||Move the mouse pointer over the point. The mouse pointer changes to a fleur shape . Click and drag the mouse to move the point.|
|Changing the color used to display the point.||Move the mouse pointer over the point. Right-click and select Set Color from the context menu and specify the color you want to use.|
|Retrieving the coordinates of the point.||Move the mouse pointer over the point. Right-click and select
Copy Position from the context menu to
copy a 1-by-2 array to the clipboard specifying the coordinates of the
|Deleting the point||Move the pointer on top of the point. Right-click and select
Delete from the context menu. To remove
this option from the context menu, set the |
impoint object supports a number of functions. Type
methods impoint to see a complete list.
|Add new-position callback to ROI object|
|(Not recommended) 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|
|(Not recommended) Set color used to draw ROI object|
|Set ROI object to new position|
|(Not recommended) Move ROI object to new position|
|Set position constraint function of ROI object|
|Set text label for point ROI object|
|(Not recommended) Block MATLAB command line until ROI creation is finished|
Enforce Boundary Constraint when Point Moves
impoint functions to set custom color, set a label,
enforce a boundary constraint, and update position in title as point
imshow("rice.png") h = impoint(gca,100,200);
Update the title with the new position by using
Construct a boundary constraint function by using
fcn = makeConstrainToRectFcn("impoint",get(gca,"XLim"),get(gca,"YLim"));
Enforce the boundary constraint function using
setPositionConstraintFcn(h,fcn); setColor(h,"r"); setString(h,"Point label");
Click and Drag to Move Point
Interactively place a point. Use
block the MATLAB® command line. Double-click on the point to
resume execution of the MATLAB command line
imshow("pout.tif") h = impoint(gca,); position = wait(h);
If you use
impoint with an axes that contains an image object, and
do not specify a drag constraint function, then users can drag the point outside the
extent of the image and lose the point. When used with an axes created by the
plot function, the axes limits automatically expand to
accommodate the movement of the point.
Version HistoryIntroduced before R2006a
impoint is not recommended
Starting in R2018b, a new set of ROI objects replaces the existing set of ROI objects. The new objects provide more functional capabilities, such as face color transparency. The new classes also support events that you can use to respond to changes in your ROI such as moving or being clicked. Although there are no plans to remove the old ROI objects at this time, switch to the new ROIs to take advantage of the additional capabilities and flexibility. For more information on creating ROIs using the new ROI functions, see Create ROI Shapes.
Update all instances of
|Discouraged Usage||Recommended Replacement|
This example creates a point ROI.
imshow("cameraman.tif"); h = impoint(gca,[25 50]);
Here is equivalent code, replacing the old ROI object with the new ROI object. This example uses the ROI creation convenience function. Note that you must specify the size and position information as a name-value argument.
imshow("cameraman.tif"); h = drawpoint(gca,"Position",[25 50]);
Update code that uses any of the object functions of the
impoint ROI object. In many cases, you can replace the
call to an
impoint object function by simply accessing or
setting the value of a
Point ROI object property. For
example, replace calls to
setColor with use of the
property. In some cases, you must replace the
function with an object function of the new
Point ROI. Each
of the individual
impoint ROI object functions include
information about migrating to the new
Point ROI object. For
a migration overview, see ROI Migration.