This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

impoint

Create draggable point

impoint is not recommended. Use drawpoint instead.

Description

An impoint object encapsulates an interactive point over an image.

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.

Creation

Syntax

h = impoint
h = impoint(hparent)
h = impoint(hparent,position)
h = impoint(hparent,x,y)
h = impoint(___,Name,Value)

Description

h = impoint begins interactive placement of a point on the current axes, and returns an impoint object.

h = impoint(hparent) begins interactive placement of a point on the object specified by hparent.

h = impoint(hparent,position) creates a draggable point with coordinates defined by position.

example

h = impoint(hparent,x,y) creates a draggable point with x- and y-coordinates of the point defined by x and y.

h = impoint(___,Name,Value) specifies name-value pairs that control the behavior of the point.

Input Arguments

expand all

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 hggroup object.

Position of point, specified as a 2-element vector of the form [x y].

x- or y-coordinate of the point, specified as a numeric scalar.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is 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 Name1,Value1,...,NameN,ValueN.

Position constraint function, specified as the comma-separated pair consisting of 'PositionConstraintFcn' and a function handle. fcn is called whenever the mouse is dragged. You can use this function to control where the point can be dragged. See the help for the setPositionConstraintFcn function for information about valid function handles.

Properties

expand all

ROI can be deleted, specified as true or false.

Data Types: logical

Usage

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 impoint.

Interactive BehaviorDescription
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 point [X Y].
Deleting the pointMove 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 Deletable property to false: h = impoint(); h.Deletable = false;

Object Functions

Each impoint object supports a number of methods. Type methods impoint to see a complete list.

addNewPositionCallbackAdd new-position callback to ROI object
createMaskCreate mask within image
deleteDelete handle object
getColorGet color used to draw ROI object
getPositionReturn current position of ROI object
getPositionConstraintFcnReturn function handle to current position constraint function
removeNewPositionCallbackRemove new-position callback from ROI object
resumeResume execution of MATLAB command line
setColorSet color used to draw ROI object
setConstrainedPositionSet ROI object to new position
setPositionMove ROI object to new position
setPositionConstraintFcnSet position constraint function of ROI object
setStringSet text label for point ROI object
waitBlock MATLAB command line until ROI creation is finished

Examples

Enforce Boundary Constraint when Point Moves

Use impoint methods to set custom color, set a label, enforce a boundary constraint, and update position in title as point moves.

imshow('rice.png')
h = impoint(gca,100,200);

Update the title with the new position by using addNewPositionCallback.

addNewPositionCallback(h,@(h) title(sprintf('(%1.0f,%1.0f)',h(1),h(2))));

Construct a boundary constraint function by using makeConstrainToRectFcn.

fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));

Enforce the boundary constraint function using setPositionConstraintFcn.

setPositionConstraintFcn(h,fcn);
setColor(h,'r');
setString(h,'Point label');

Click and Drag to Move Point

Interactively place a point. Use wait to 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);

Tips

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.

Introduced before R2006a