Image Processing Toolbox User's Guide |
Syntax
BW2 = imfill(BW,locations) BW2 = imfill(BW,'holes') I2 = imfill(I) BW2 = imfill(BW) [BW2 locations] = imfill(BW) BW2 = imfill(BW,locations,CONN) BW2 = imfill(BW,CONN,'holes') I2 = imfill(I,CONN)
Description
BW2 = imfill(BW,locations)
performs a flood-fill operation on background pixels of the binary image BW
, starting from the points specified in locations
. If locations
is a P-by-1 vector, it contains the linear indices of the starting locations. If locations
is a P
-by-ndims(BW)
matrix, each row contains the array indices of one of the starting locations.
BW2 = imfill(BW,'holes')
fills holes in the binary image BW
. A hole is a set of background pixels that cannot be reached by filling in the background from the edge of the image.
I2 = imfill(I)
fills holes in the intensity image I
. In this case, a hole is an area of dark pixels surrounded by lighter pixels.
Interactive Use
BW2 = imfill(BW)
displays the binary image BW
on the screen and lets you select the starting locations using the mouse. Click the mouse button to add points. Press Backspace or Delete to remove the previously selected point. A shift-click, right-click, or double-click selects a final point and then starts the fill operation; pressing Return finishes the selection without adding a point.
[BW2,locations] = imfill(BW)
lets you select the starting points selected using the mouse, returning the locations of points in locations
. locations
is a vector of linear indices into the input image.
Specifying Connectivity
By default, imfill
uses 4-connected background neighbors for 2-D inputs and 6-connected background neighbors for 3-D inputs. For higher dimensions the default background connectivity is determined by using conndef(NUM_DIMS,'minimal')
. You can override the default connectivity with these syntaxes:
To override the default connectivity and interactively specify the starting locations, use this syntax:
CONN
can have any of the following scalar values.
Connectivity can be defined in a more general way for any dimension by using for CONN
a 3-by-3-by- ... -by-3 matrix of 0
's and 1
's. The 1
-valued elements define neighborhood locations relative to the center element of CONN
. Note that CONN
must be symmetric about its center element.
Class Support
The input image can be numeric or logical, and it must be real and nonsparse. It can have any dimension. The output image has the same class as the input image.
Examples
Fill in the background of a binary image from a specified starting location.
BW1 = logical([1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0 1 1 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 1 1 0]); BW2 = imfill(BW1,[3 3],8)
Fill in the holes of a binary image.
Fill in the holes of an intensity image.
Algorithm
imfill
uses an algorithm based on morphological reconstruction [1].
See Also
bwselect
, imreconstruct
, roifill
Reference
[1] Soille, P., Morphological Image Analysis: Principles and Applications, Springer-Verlag, 1999, pp. 173-174.
imextendedmin | imfilter |
© 1994-2005 The MathWorks, Inc.