| Image Processing Toolbox™ | ![]() |
h = impoly
h = impoly(hparent)
h = impoly(hparent, position)
h = impoly(..., param1, val1, ...)
h = impoly begins interactive placement of a polygon on the current axes. The function returns h, a handle to an impoly object. The polygon has a context menu associated with it that controls aspects of its appearance and behavior—see Interactive Behavior. Right-click on the polygon to access this context menu.
h = impoly(hparent) begins interactive placement of a polygon on the object specified by hparent. hparent specifies the HG parent of the polygon graphics, which is typically an axes but can also be any other object that can be the parent of an hggroup.
h = impoly(hparent, position) creates a draggable, resizable polygon on the object specified by hparent. position is an n-by-2 array that specifies the initial position of the vertices of the polygon. position has the form [X1,Y1;...;XN,YN].
h = impoly(..., param1, val1, ...) creates a draggable, resizable polygon, specifying parameters and corresponding values that control the behavior of the polygon. The following table lists available parameters. Parameter names can be abbreviated, and case does not matter.
| Parameter | Description |
|---|---|
'Closed' | Scalar logical that controls whether the polygon is closed. When set to true (the default), impoly creates a closed polygon, that is, it draws a straight line between the last vertex specified and the first vertex specified to create a closed region. When Closed is false, impoly does not connect the last vertex with the first vertex, creating an open polygon (or polyline). |
'PositionConstraintFcn' | Function handle fcn that is called whenever the object is dragged using the mouse. You can use this function to control where the line can be dragged. See the help for the setPositionConstraintFcn method for information about valid function handles. |
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. 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 following figure shows a polygon being
created.

The following 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 and press the A key. The shape of the pointer changes
|
| Moving a vertex. (Reshaping the polygon.) | Move the pointer over a vertex. The pointer changes to a circle
|
| Deleting a vertex. | Move the pointer over a vertex. The shape changes to a circle
|
| Moving the polygon. | Move the pointer inside the polygon. The pointer changes to
a fleur shape
|
| 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. |
Each impoly object supports a number of methods, listed below. Methods inherited from the base class are links to that class.
See imroi for information.
See imroi for information.
pos = getPosition(h) returns the current position of the polygon h. The returned position, pos, is an N-by-2 array [X1 Y1;...;XN YN].
See imroi for information.
See imroi for information.
See imroi for information.
setClosed(TF) sets the geometry of the polygon. TF is a logical scalar. true means that the polygon is closed. false means that the polygon is an open polyline.
See imroi for information.
See imroi for information.
setPosition(h,pos) sets the polygon h to a new position. The new position, pos, is an n-by-2 array, [x1 y1; ..; xn yn] where each row specifies the position of a vertex of the polygon.
See imroi for information.
setVerticesDraggable(h,TF) sets the interactive behavior of the vertices of the polygon h. TF is a logical scalar. True means that the vertices of the polygon are draggable. False means that the vertices of the polygon are not draggable.
See imroi for information.
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.
Display updated position in the title. Specify a position constraint function using makeConstainToRectFcn to keep the polygon inside the original xlim and ylim ranges.
figure, imshow('gantrycrane.png');
h = impoly(gca, [188,30; 189,142; 93,141; 13,41; 14,29]);
setColor(h,'yellow');
addNewPositionCallback(h,@(p) title(mat2str(p,3)));
fcn = makeConstrainToRectFcn('impoly',get(gca,'XLim'),get(gca,'YLim'));
setPositionConstraintFcn(h,fcn);Interactively place a polygon by clicking to specify vertex locations. Double-click or right-click to finish positioning the polygon. Use wait to block the MATLAB command line. Double-click on the polygon to resume execution of the MATLAB command line.
figure, imshow('pout.tif');
h = impoly;
position = wait(h);imellipse, imfreehand, imline, impoint, imrect, imroi, makeConstrainToRectFcn
![]() | impoint | impositionrect | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |