Image Processing Toolbox | ![]() ![]() |
Fill background regions in a binary image
Note
This function is obsolete and may be removed in future versions. Use imfill instead.
|
Syntax
BW2 = bwfill(BW1,c,r,n) BW2 = bwfill(BW1,n) [BW2,idx] = bwfill(...) BW2 = bwfill(x,y,BW1,xi,yi,n) [x,y,BW2,idx,xi,yi] = bwfill(...) BW2 = bwfill(BW1,'holes',n) [BW2,idx] = bwfill(BW1,'holes',n)
Description
BW2 = bwfill(BW1,c,r,n)
performs a flood-fill operation on the input binary image BW1
, starting from the pixel (r
,c
). If r
and c
are equal-length vectors, the fill is performed in parallel from the starting pixels (r(k)
,c(k)
). n
can have a value of either 4 or 8 (the default), where 4 specifies 4-connected foreground and 8 specifies 8-connected foreground. The foreground of BW1
comprises the on
pixels (i.e., having value of 1).
BW2 = bwfill(BW1,n)
displays the image BW1
on the screen and lets you select the starting points using the mouse. If you omit BW1
, bwfill
operates on the image in the current axes. Use normal button clicks 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; pressing Return finishes the selection without adding a point.
[BW2,idx] = bwfill(...)
returns the linear indices of all pixels filled by bwfill
.
BW2 = bwfill(x,y,BW1,xi,yi,n)
uses the vectors x
and y
to establish a nondefault spatial coordinate system for BW1
. xi
and yi
are scalars or equal-length vectors that specify locations in this coordinate system.
[x,y,BW2,idx,xi,yi] = bwfill(...)
returns the XData
and YData
in x
and y
; the output image in BW2
; linear indices of all filled pixels in idx
; and the fill starting points in xi
and yi
.
BW2 = bwfill(BW1,'holes',n)
fills the holes in the binary image BW1
. bwfill
automatically determines which pixels are in object holes, and then changes the value of those pixels from 0 to 1. n
defaults to 8 if you omit the argument.
[BW2,idx] = bwfill(BW1,'holes',n)
returns the linear indices of all pixels filled in by bwfill
.
If bwfill
is used with no output arguments, the resulting image is displayed in a new figure.
Remarks
bwfill
differs from many other binary image operations in that it operates on background pixels, rather than foreground pixels. If the foreground is 8-connected, the background is 4-connected, and vice versa. Note, however, that you specify the connectedness of the foreground when you call bwfill
.
Class Support
The input image, BW1
, must be a numeric or logical matrix. The output image, BW2
, is logical.
Example
BW1 = [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 = bwfill(BW1,3,3,8) BW2 = 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 0 1 0 1 1 1 1 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 I = imread('blood1.tif'); BW3 = ~im2bw(I); BW4 = bwfill(BW3,'holes'); imshow(BW3) figure, imshow(BW4)
See Also
![]() | bweuler | bwhitmiss | ![]() |