Specify polygonal region of interest (ROI)

creates an interactive
polygon tool associated with the image displayed in the current figure.
`BW`

= roipoly`roipoly`

returns the mask as a binary image, setting
pixels inside the ROI to `1`

and pixels outside the ROI to
`0`

.

With this syntax and the other interactive syntaxes, the polygon selection
tool blocks the MATLAB^{®} command line until you complete the operation. For more
information about using the polygon selection tool, see Interactive Behavior.

`roipoly(___)`

without output arguments
displays the resulting mask image in a new figure window.

`roipoly`

always produces a closed polygon. If you specify input vertex positions of a closed polygon (such that the last pair of coordinates is identical to the first pair), then the length of the output coordinate vectors is equal to the number of points specified. If the points specified do not describe a closed polygon, then`roipoly`

adds a final point having the same coordinates as the first point. In this case the length of the output coordinate vectors is one greater than the number of points specified.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.c = [112 112 79 79]; r = [37 66 66 37]; BW = roipoly(100,200,c,r);

If you specify

`m`

and`n`

with an interactive form of`roipoly`

, an`m`

-by-`n`

black image is displayed. Use the mouse to specify a polygon within this image.

`drawpolygon`

| `poly2mask`

| `regionfill`

| `roicolor`

| `roifilt2`