You are here : matlabImage Processingregionfill

regionfill() - Image Processing

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.exampleJ = regionfill(I,x,y) fills
the region in image I corresponding to the polygon
with vertices specified by x and y.


Syntax

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


Example

Fill Region in Grayscale ImageOpen This Example
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')

Fill Regions Using Mask ImageOpen This Example
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')


Output / Return Value


Limitations


Alternatives / See Also


Reference