Image Processing Toolbox User's Guide Previous page   Next Page
roipoly

Select a polygonal region of interest

Syntax

Description

Use roipoly to select a polygonal region of interest within an image. roipoly returns a binary image that you can use as a mask for masked filtering.

BW = roipoly(I,c,r) returns the region of interest selected by the polygon described by vectors c and r. BW is a binary image the same size as I with 0's outside the region of interest and 1's inside.

BW = roipoly(I) displays the image I on the screen and lets you specify the polygon using the mouse. If you omit I, roipoly operates on the image in the current axes. Use normal button clicks to add vertices to the polygon. Pressing Backspace or Delete removes the previously selected vertex. A shift-click, right-click, or double-click adds a final vertex to the selection and then starts the fill; pressing Return finishes the selection without adding a vertex.

BW = roipoly(x,y,I,xi,yi) uses the vectors x and y to establish a nondefault spatial coordinate system. xi and yi are equal-length vectors that specify polygon vertices as locations in this coordinate system.

[BW,xi,yi] = roipoly(...) returns the polygon coordinates in xi and yi. Note that roipoly always produces a closed polygon. If the points specified describe a closed polygon (i.e., if the last pair of coordinates is identical to the first pair), the length of xi and yi is equal to the number of points specified. If the points specified do not describe a closed polygon, roipoly adds a final point having the same coordinates as the first point. (In this case the length of xi and yi is one greater than the number of points specified.)

[x,y,BW,xi,yi] = roipoly(...) returns the XData and YData in x and y, the mask image in BW, and the polygon coordinates in xi and yi.

If roipoly is called with no output arguments, the resulting image is displayed in a new figure.

Class Support

The input image I can be of class uint8, uint16, int16, single, or double. The output image BW is of class logical. All other inputs and outputs are of class double.

Remarks

For any of the roipoly syntaxes, you can replace the input image I with two arguments, m and n, that specify the row and column dimensions of an arbitrary image. For example, these commands create a 100-by-200 binary mask.

If you specify m and n with an interactive form of roipoly, an m-by-n black image is displayed, and you use the mouse to specify a polygon within this image.

Example

See Also

roifilt2, roicolor, roifill, poly2mask


Previous page  roifilt2 std2 Next page

© 1994-2005 The MathWorks, Inc.