Function File: bw2 = imfill (bw, "holes")
Function File: bw2 = imfill (bw, conn, "holes")
Function File: bw2 = imfill (bw, locations)
Function File: bw2 = imfill (bw, locations, conn)
Function File: I2 = imfill (I)
Function File: I2 = imfill (I, "holes")
Function File: I2 = imfill (I, conn)
Function File: I2 = imfill (I, conn, "holes")

Fill image holes or regions.

The image to be filled can be binary bw or grayscale I. Regions are a series of connected elements whose values are lower than at least one of its neighbor elements.

The option "holes", default for grayscale images, can be used to fill all holes, i.e., regions without border elements.

Alternatively, the argument locations are coordinates for elements in the regions to be filled. It can be a a n-by-1 vector of linear indices or a n-by-d matrix of subscript indices where n is the number of points and d is the number of dimensions in the image.

The argument conn specifies the connectivity used for filling the region and defaults to conndef (ndims (img, "minimal") which is 4 for the case of 2 dimensional images.

im = [0  1  0
      1  0  1
      0  1  0];

imfill (im, "holes")
ans =

 0  1  0
 1  1  1
 0  1  0

See also: bwfill, bwselect, imreconstruct.

Package: image