| Image Processing Toolbox™ | ![]() |
J = roifill
J = roifill(I)
J = roifill(I, c, r)
J = roifill(I, BW)
[J,BW] = roifill(...)
J = roifill(x, y, I, xi, yi)
[x, y, J, BW, xi, yi] = roifill(...)
Use roifill to fill in a specified region of interest (ROI) polygon in a grayscale image. roifill smoothly interpolates inward from the pixel values on the boundary of the polygon by solving Laplace's equation. The boundary pixels are not modified. roifill can be used, for example, to erase objects in an image.
J = roifill creates an interactive polygon tool, associated with the image displayed in the current figure, called the target image. You use the mouse to define the ROI – see Interactive Behavior. When you are finished defining the ROI, fill in the area specified by the ROI by double-clicking inside the region or by right-clicking anywhere inside the region and selecting Fill Area from the context menu. roifill returns the image, J, which is the same size as I with the region filled in (see Examples).
Note If you do not specify an output argument, roifill display the filled image is displayed in a new figure. |
J = roifill(I) displays the image I and creates an interactive polygon tool associated with the image.
J = roifill(I, c, r) fills in the polygon specified by c and r, which are equal-length vectors containing the row-column coordinates of the pixels on vertices of the polygon. The kth vertex is the pixel (r(k),c(k)).
J = roifill(I, BW) uses BW (a binary image the same size as I) as a mask. roifill fills in the regions in I corresponding to the nonzero pixels in BW. If there are multiple regions, roifill performs the interpolation on each region independently.
[J,BW] = roifill(...) returns the binary mask used to determine which pixels in I get filled. BW is a binary image the same size as I with 1's for pixels corresponding to the interpolated region of I and 0's elsewhere.
J = roifill(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.
[x, y, J, BW, xi, yi] = roifill(...) returns the XData and YData in x and y, the output image in J, the mask image in BW, and the polygon coordinates in xi and yi. xi and yi are empty if the roifill(I,BW) form is used.
When you call roifill with an interactive
syntax, the pointer changes to a cross hairs shape
when you move it over
the target image. Using the mouse, you specify a region-of-interest
by selecting vertices of a polygon. You can change the size or shape
of the polygon using the mouse. The following figure illustrates a
polygon defined by multiple vertices. For more information about all
the interactive capabilities of roifill, see the
table that follows.

| Interactive Behavior | Description |
|---|---|
| Closing the polygon. (Completing the region-of-interest.) | Use any of the following mechanisms:
|
| Deleting the polygon | Press Backspace, Escape or Delete, or right-click inside the region and select Cancel from the context menu. Note: If you delete the ROI, the function returns empty values. |
| Moving the polygon | Move the pointer inside the region. The pointer changes to
a fleur
|
| Changing the color of the polygon | Move the pointer inside the region. Right-click and select Set color from the context menu. |
| 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 region-of-interest.) | Move the pointer over a vertex. The pointer changes to a circle
|
| Deleting a vertex. | Move the pointer over a vertex. The pointer changes to a circle
|
| Retrieving the coordinates of the vertices | Move the pointer inside the region. Right-click and select Copy position from the context menu to copy the current position to the Clipboard. Position is an n-by-2 array containing the x- and y-coordinates of each vertex, where n is the number of vertices you selected. |
The input image I can of class uint8, uint16, int16, single, or double. The input binary mask BW can be any numeric class or logical. The output binary mask BW is always logical. The output image J is of the same class as I. All other inputs and outputs are of class double.
This example uses roifill to fill a region in the input image, I. For more examples, especially of the interactive syntaxes, see Filling an ROI.
I = imread('eight.tif');
c = [222 272 300 270 221 194];
r = [21 21 75 121 121 75];
J = roifill(I,c,r);
imshow(I)
figure, imshow(J)

For more information about ROIs, see ROI-Based Processing.
![]() | roicolor | roifilt2 | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |