Main Content

roifill

(Not recommended) Fill in specified region of interest (ROI) polygon in grayscale image

roifill is not recommended. Use regionfill instead. If you want to define the polygon interactively with regionfill, then use regionfill either with roipoly or with drawpolygon followed by createMask.

Description

Use the roifill function 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 selection tool associated with the image displayed in the current figure. With this syntax and the other interactive syntaxes, the polygon selection tool blocks the MATLAB® command line until you complete the operation. roifill fills the selected polygon and returns the filled image, J.

For more information about using the polygon selection tool to define and fill ROIs, see Interactive Behavior.

J = roifill(I) displays the image I in a figure window and creates an interactive polygon tool associated with the image.

J = roifill(I,mask) fills regions in I corresponding to the nonzero pixels in the mask. If there are multiple regions, then roifill performs the interpolation on each region independently.

J = roifill(I,xi,yi) fills in the polygon with vertices defined by X-Y coordinates xi and yi in the default spatial coordinate system.

example

J = roifill(x,y,I,xi,yi) defines a nondefault spatial coordinate system using the vectors x and y. The polygon vertices have coordinates xi and yi in this coordinate system.

[J,BW] = roifill(___) returns the binary image BW with 1s for pixels corresponding to the interpolated region of I and 0s elsewhere.

[x2,y2,J,BW,xi2,yi2] = roifill(___) also returns the image XData and YData in x2 and y2 and the polygon coordinates in xi2 and yi2.

roifill(___) without an output argument displays the filled image in a new figure window.

Examples

collapse all

Read and display a grayscale image.

I = imread('eight.tif');
imshow(I)

Figure contains an axes object. The hidden axes object contains an object of type image.

Specify the x- and y-coordinates of a polygon that completely surrounds one of the coins in the image.

x = [222 272 300 270 221 194];
y = [21 21 75 121 121 75];

Fill the polygon by using the regionfill function.

J = regionfill(I,x,y);

Display the filled image.

imshow(J)
title('Filled Image with One Fewer Coin')

Figure contains an axes object. The hidden axes object with title Filled Image with One Fewer Coin contains an object of type image.

Input Arguments

collapse all

Grayscale image, specified as a numeric matrix.

Data Types: single | double | int16 | uint8 | uint16

Mask, specified as a numeric or logical matrix of the same size as the input image, I.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

x- or y-coordinate of polygon vertices, specified as numeric vectors of equal length. If you specify a nondefault coordinate system using the x and y arguments, then xi and yi specify coordinates in this coordinate system. Otherwise, xi and yi specify coordinates in the default coordinate system.

Image extent in world X-Y coordinates, specified as a 2-element numeric vector of the form [min max]. The two elements of x give the x-coordinates (horizontal) of the first and last columns of image I, respectively. The two elements of y give the y-coordinates (vertical) of the first and last rows of I.

Output Arguments

collapse all

Filled image, returned as a numeric matrix.

Data Types: single | double | int16 | uint8 | uint16

Binary image, returned as a logical matrix of the same size as the input image, I.

Data Types: logical

x- or y-coordinate of polygon vertices, specified as numeric vectors. xi and yi are empty if you specify the polygon ROI using the mask argument.

Image extent in world X-Y coordinates,, returned as 2-element numeric vectors of the form [min max]. If you specify image limits x and y, then x2 and y2 are equal to these values. Otherwise, x2 and y2 are equal to the original image XData and YData.

More About

collapse all

Version History

Introduced before R2006a