Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

regionfill

Fill in specified regions in image using inward interpolation

Syntax

J = regionfill(I,mask)
J = regionfill(I,x,y)

Description

example

J = regionfill(I,mask) fills the regions in image I specified by mask. Non-zero pixels in mask designate the pixels of image I to fill. You can use regionfill to remove objects in an image or to replace invalid pixel values using their neighbors.

example

J = regionfill(I,x,y) fills the region in image I corresponding to the polygon with vertices specified by x and y.

Examples

collapse all

Read grayscale image into the workspace.

I = imread('eight.tif');

Specify a polygon that completely surrounds one of the coins in the image. This example uses the x-coordinates and y-coordinates (columns and rows) of the polygon vertices to specify the region.

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

Fill the polygon, using the regionfill function.

J = regionfill(I,x,y);

Display the original image and the filled image side-by-side.

figure
subplot(1,2,1)
imshow(I)
title('Original image')
subplot(1,2,2)
imshow(J)
title('Image with one less coin')

Read grayscale image into the workspace.

I = imread('eight.tif');

Create a mask image that covers all the coins.

mask = I < 200;

Fill holes in the mask image.

mask = imfill(mask,'holes');

Remove noise in the mask image.

mask = imerode(mask,strel('disk',10));
mask = imdilate(mask,strel('disk',20));

Fill the regions in the input image using the mask image.

J = regionfill(I,mask);

Display the original image next to the mask image and the filled image.

figure
subplot(1,3,1)
imshow(I)
title('Original image')
subplot(1,3,2)
imshow(mask)
title('Mask of pixels to fill')
subplot(1,3,3)
imshow(J)
title('Resulting image')

Input Arguments

collapse all

Input grayscale image, specified as a 2-D numeric array, nonsparse and real. I must be greater than or equal to a 3-by-3 array.

Example: I = imread('eight.tif');

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

Mask binary image, specified as a nonsparse logical array the same size as I.

Data Types: logical

X-coordinates of polygon vertices, specified as a numeric vector of class double. Must be the same length as y.

Example: x = [222 272 300 270 221 194];

Data Types: double

Y-coordinates of polygon vertices, specified as a numeric vector of class double. Must be the same length as x.

Example: y = [21 21 75 121 121 75];

Data Types: double

Output Arguments

collapse all

Filled grayscale image, returned as a 2-D numeric array, nonsparse, and real. J has the same size and class as I.

Tips

  • regionfill does not support the interactive syntax that roifill supports to specify a region of interest (ROI). To define an ROI interactively, use roipoly with regionfill.

Algorithms

regionfill smoothly interpolates inward from the pixel values on the outer boundary of the regions. regionfill computes the discrete Laplacian over the regions and solves the Dirichlet boundary value problem.

Introduced in R2015a

Was this topic helpful?