impoly
(Not recommended) Create draggable, resizable polygon
impoly
is not recommended. Use the new Polygon
object instead. You can also use the new ROI creation convenience function drawpolygon
. Another option is the Polyline
object, which enables you to create an open polygon, or polyline
shape. For more information, see Version History.
Description
An impoly
object encapsulates an interactive polygon over
an image.
You can add vertices and adjust the size and position of the polygon by using the mouse. The polygon also has a context menu that controls aspects of its appearance and behavior. For more information, see Usage.
Creation
Description
h = impoly
begins interactive placement of a polygon on
the current axes, and returns an impoly
object.
h = impoly(
begins
interactive placement of a polygon on the object specified by
hparent
)hparent
.
h = impoly(___,
specifies name-value pairs that control the behavior of the polygon.Name,Value
)
Input Arguments
Properties
Usage
When you call impoly
with an interactive syntax, the pointer
changes to a cross hairs when over the image. Click and drag the mouse to
define the vertices of the polygon and adjust the size, shape, and position of the
polygon. By default, impoly
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 polygon also supports a context menu that you can use to control aspects of its appearance and behavior. The choices in the context menu vary whether you position the pointer on an edge of the polygon (or anywhere inside the region) or on one of the vertices. The figure shows the context menu when the pointer is on the polygon but not on a vertex.
The table lists the interactive behaviors supported by
impoly
.
Interactive Behavior | Description |
---|---|
Closing the polygon. | Use any of the following mechanisms:
|
Adding a new vertex. | Move the pointer over an edge of the polygon. Press and hold the A key. The shape of the pointer changes . Click the left mouse button to create a new vertex at that position on the line. |
Moving a vertex. (Reshaping the polygon.) | Move the pointer over a vertex. The pointer changes to a circle . Click and drag the vertex to its new position. |
Deleting a vertex. | Move the pointer over a vertex. The shape changes to a circle . Right-click and select Delete Vertex from the vertex context menu. This action deletes the vertex and adjusts the shape of the polygon, drawing a new straight line between the two vertices that were neighbors of the deleted vertex. |
Deleting the polygon | Move the pointer inside the polygon or on one of the lines that
define the polygon, not on a vertex. Right-click and select
Delete from the context menu. To remove
this option from the context menu, set the Deletable
property to false: h = impoly(); h.Deletable =
false; |
Moving the polygon. | Move the pointer inside the polygon. The pointer changes to a fleur shape . Click and drag the mouse to move the polygon. |
Changing the color of the polygon | Move the pointer inside the polygon. Right-click and select Set Color from the context menu. |
Retrieving the coordinates of the vertices | Move the pointer inside the polygon. Right-click and select
Copy Position from the context menu.
impoly copies an n-by-2 array
containing the x- and
y-coordinates of each vertex to the clipboard.
n is the number of vertices you specified.
|
Object Functions
Each impoly
object supports a number of methods. Type
methods impoly
to see a complete list.
addNewPositionCallback | Add new-position callback to ROI object |
createMask | (Not recommended) Create mask within image |
delete | Delete handle object |
getColor | Get color used to draw ROI object |
getPosition | Return current position of ROI object |
getPositionConstraintFcn | Return function handle to current position constraint function |
removeNewPositionCallback | Remove new-position callback from ROI object |
resume | (Not recommended) Resume execution of MATLAB command line |
setClosed | Set closure behavior of ROI object |
setColor | (Not recommended) Set color used to draw ROI object |
setConstrainedPosition | Set ROI object to new position |
setPosition | (Not recommended) Move ROI object to new position |
setPositionConstraintFcn | Set position constraint function of ROI object |
setVerticesDraggable | Set vertex behavior of ROI object |
wait | (Not recommended) Block MATLAB command line until ROI creation is finished |
Examples
Tips
If you use impoly
with an axes that contains an image object, and
do not specify a position constraint function, users can drag the polygon outside the
extent of the image and lose the polygon. When used with an axes created by the
plot
function, the axes limits automatically expand when the
polygon is dragged outside the extent of the axes.