Main Content

Fill Region of Interest in an Image

This example shows how to use regionfill to fill a region of interest (ROI) in an image. The example uses the roipoly function to define the region of interest interactively with the mouse. regionfill smoothly interpolates inward into the region from the pixel values on the boundary of the polygon. You can use this function for image editing, including removal of extraneous details or artifacts. The filling process replaces values in the region with values that blend with the background.

Read an image into the MATLAB® workspace and display it.

I = imread('eight.tif');

Create a mask image to specify the region of interest (ROI) you want to fill. Use the roipoly function to specify the region interactively. Call roipoly and move the pointer over the image. The pointer shape changes to cross hairs . Define the ROI by clicking the mouse to specify the vertices of a polygon. You can use the mouse to adjust the size and position of the ROI.

mask = roipoly(I);

Double-click to finish defining the region. roipoly creates a binary image with the region filled with 1-valued pixels.

Display the mask image.


Fill the region, using regionfill, specifying the image to be filled and the mask image as inputs. Display the result. Note the image contains one less coin.

J = regionfill(I,mask);

See Also

| | |