[L,num] = Bwlabel (bw,n)
Matlab binary image, White is 1, black is 0, this function marks the number of white block (1) of the number of connected areas.
Usage:
[L,num] = Bwlabel (bw,n)
Returns an L-matrix with the same BW size, containing the category labels labeled for each connected region of BW, with values of 1, 2, num (number of connected regions). The value of n is 4 or 8, which means that the search area is connected by 4, or 8 is connected, and the default is 8.
Four-or eight-connected is the basic sense of image processing: 8 connectivity, is to say a pixel, if and other pixels in the upper, next, left, right, upper left, lower left, upper right, or lower right, then they are connected; 4 connectivity means that if the pixel is positioned on top, bottom, left, or right adjacent to other pixels, They are connected and connected, and they do not connect in the upper left corner, the lower left corner, the upper right corner or the lower right corner.
For example, if the original BW is
BW =
1 1 1 0 0 0 0 0
1 1 1 0 1 1 0 0
1 1 1 0 1 1 0 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 0 1 0
1 1 1 0 0 1 1 0
1 1 1 0 0 0 0 0
L = Bwlabel (bw,4)
The results are as follows: Num=3
L =
1 1 1 0 0 0 0 0
1 1 1 0 2 2 0 0
1 1 1 0 2 2 0 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 0 3 0
1 1 1 0 0 3 3 0
1 1 1 0 0 0 0 0
and 8 connected markers, they are connected:
[L, num] = Bwlabel (bw,8)
The result: num=2
L =
1 1 1 0 0 0 0 0
1 1 1 0 2 2 0 0
1 1 1 0 2 2 0 0
1 1 1 0 0 0 2 0
1 1 1 0 0 0 2 0
1 1 1 0 0 0 2 0
1 1 1 0 0 2 2 0
1 1 1 0 0 0 0 0