Go to: http://hi.baidu.com/zhudlike/item/69b6ca8fbb58dacdb171544e
Image processing function description-bwlabel function: Mark connected objects. bwlabel is used to mark the separated parts of a two-dimensional binary image (bwlabeln is used for multiple dimensions in a similar way ).
Usage: L = bwlabel (BW, n)
[L, num] = bwlabel (BW, n)
L = bwlabel (BW, n) indicates to return the array L of the same size as BW. L contains the connectivity object annotation. The N parameter is 4 or 8, which corresponds to the 4-and 8-neighborhoods respectively. The default value is 8.
[L, num] = bwlabel (BW, n) returns the number of connected num. Bwlabel usage:
L = bwlabel (BW, n)
Returns an L matrix of the same size as BW. It contains the class labels marked for each connected area in BW. The values of these labels are 1, 2, and num (number of connected areas ). The value of N is 4 or 8, indicating whether to search for a region by 4 or 8 connections. The default value is 8.
The four-or eight-connection is the basic concept in image processing. The eight-connection is a pixel, if they are connected to other pixels in the upper, lower, left, right, upper left, lower left, upper right, or lower right corner, they are considered to be connected, if the pixels are located on the top, bottom, left, or right of other adjacent pixels, they are considered to be connected, connected, and connected in the upper left, lower left, upper right, or lower right corner, they are not considered to be connected.
[L, num] = bwlabel (BW, n)
Here num returns the number of connected regions in BW.
Supplement: I have heard of 16 connections. This should be a concept in 3D space.
Example:
BW =
1 1 1 0 0 0 0 0
1 1 1 0 1 0 0
1 1 1 0 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 0
1 1 1 0 0 0 0 0
In 4-connected computing, the square area and the flipped L-shaped area are useful for diagonal connections and are not connected. Therefore, they are marked separately and the number of connected areas is 3.
- L = bwlabel (BW, 4)
The result is as follows:
L =
1 1 1 0 0 0 0 0
1 1 1 0 2 0 0
1 1 1 0 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 0
1 1 1 0 0 0 0 0
While the eight connectivity labels are connected:
- [L, num] = bwlabel (BW, 8)
L =
1 1 1 0 0 0 0 0
1 1 1 0 2 0 0
1 1 1 0 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 0
1 1 1 0 0 0 0 0
Here
Num =
2