Documentation Center

  • Trial Software
  • Product Updates

impoint

Create draggable point

Syntax

h = impoint
h = impoint(hparent)
h = impoint(hparent,position)
h = impoint(hparent,x, y)
h = impoint(..., param,val)

Description

h = impoint begins interactive placement of a draggable point on the current axes. The function returns h, a handle to an impoint object. The point has a context menu associated with it that controls aspects of its appearance and behavior—see Interactive Behavior. Right-click on the point to access this context menu.

h = impoint(hparent) begins interactive placement of a point on the object specified by hparent. hparent specifies the HG parent of the point graphics, which is typically an axes but can also be any other object that can be the parent of an hggroup.

h = impoint(hparent,position) creates a draggable point on the object specified by hparent. position is a 1-by-2 array of the form [x y] that specifies the initial position of the point.

h = impoint(hparent,x, y) creates a draggable point on the object specified by hparent. x and y are both scalars that together specify the initial position of the point.

h = impoint(..., param,val) creates a draggable point , specifying parameters and corresponding values that control the behavior of the point. The following table lists the parameter available. Parameter names can be abbreviated, and case does not matter.

ParameterDescription

'PositionConstraintFcn'

Function handle fcn that is called whenever the point is dragged using the mouse. You can use this function to control where the point can be dragged. See the help for the setPositionConstraintFcn method for information about valid function handles.

Interactive Behavior

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, such as . The following table describes the interactive behavior of the point, including the right-click context menu options.

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

Methods

The following lists the methods supported by the impoint object. Type methods impoint to see a complete list of all the methods.

addNewPositionCallback — Add new-position callback to ROI object

See imroi for information.

delete — Delete ROI object

See imroi for information.

getColor — Get color used to draw ROI object

See imroi for information.

getPosition — Return current position of point

pos = getPosition(h) returns the current position of the point h. The returned position, pos, is a two-element vector [x y].

getPositionConstraintFcn — Return function handle to current position constraint function

See imroi for information.

removeNewPositionCallback — Remove new-position callback from ROI object.

See imroi for information.

resume — Resume execution of MATLAB command line

See imroi for information.

setColor — Set color used to draw ROI object

See imroi for information.

setConstrainedPosition — Set ROI object to new position

See imroi for information.

setPosition — Set point to new position

setPosition(h,pos) sets the pointh to a new position. The new position, pos, has the form, [x y].

setPosition(h,new_x,new_y) sets the point h to a new position. new_x and new_y are both scalars that together specify the position of the point.

setPositionConstraintFcn — Set position constraint function of ROI object.

See imroi for information.

setString — Set text label for point

setString(h,s) sets a text label for the point h. The string, s, is placed to the lower right of the point.

wait — Block MATLAB command line until ROI creation is finished

See imroi for information.

Examples

Example 1

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

figure, imshow rice.png
h = impoint(gca,100,200);
% Update position in title using newPositionCallback
addNewPositionCallback(h,@(h) title(sprintf('(%1.0f,%1.0f)',h(1),h(2))));
% Construct boundary constraint function
fcn = makeConstrainToRectFcn('impoint',get(gca,'XLim'),get(gca,'YLim'));
% Enforce boundary constraint function using setPositionConstraintFcn
setPositionConstraintFcn(h,fcn);
setColor(h,'r');
setString(h,'Point label');

Example 2

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.

figure, imshow('pout.tif');
h = impoint(gca,[]);
position = wait(h);

More About

expand all

Tips

If you use impoint with an axes that contains an image object, and do not specify a drag constraint function, 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.

See Also

| | | | | |

Was this topic helpful?