主要内容

Bwlabeln

在二进制图像中连接的标签组件

Description

example

L= bwlabeln(BW)returns a label matrix,L,包含连接组件的标签BW

L= bwlabeln(BW,conn)返回标签矩阵,其中conn指定连接性。

[L,n] = bwlabeln(___)also returnsn, the number of connected objects found inBW

Examples

collapse all

创建简单的样本3-D二进制图像。

bw = cat(3,[1 1 0; 0 0 0; 1 0 0],,。。。[0 1 0; 0 0 0; 0 1 0],。。。[0 1 1;0 0 0;0 0 1]))
BW = BW(:,:,1) = 1 1 0 0 0 0 1 0 0 BW(:,:,2) = 0 1 0 0 0 0 0 1 0 BW(:,:,3) = 0 1 1 0 0 0 0 0 1

Label connected components in the image.

Bwlabeln(BW)
ans = ans(::,:,1)= 1 1 0 0 0 0 0 2 0 0 0 ans(::, :,:,2)= 0 1 0 0 0 0 0 0 0 0 0 0 2 0 ans(:, :, :, :,3)= 0 1 1 1 1 1 1 1 1 1 10 0 0 0 0 2

Input Arguments

collapse all

二进制图像,指定为任何维度的数字或逻辑阵列。对于数字输入,任何非零像素都被认为是

Example:BW = imread('text.png');

Data Types:single|double|int8|INT16|int32|int64|uint8|uint16|uint32|uint64|logical

像素连接,指定为该表中的值之一。默认连接是8对于二维图像,以及26for 3-D images.

价值

Meaning

二维连接

4

Pixels are connected if their edges touch. Two adjoining pixels are part of the same object if they are both on and are connected along the horizontal or vertical direction.

Center pixel connected to four pixels

Current pixel is shown in gray.

8

如果它们的边缘或角触摸,则连接像素。如果两个相邻的像素是同一对象的一部分,则它们都沿水平,垂直或对角线方向连接并连接。

Center pixel connected to eight pixels

Current pixel is shown in gray.

Three-Dimensional Connectivities

6

如果他们的脸触摸,则连接像素。如果两个相邻的像素是同一对象的一部分,则它们均为并连接为:

  • One of these directions: in, out, left, right, up, and down

中心像素连接到6像素的面孔

Current pixel is center of cube.

18

Pixels are connected if their faces or edges touch. Two adjoining pixels are part of the same object if they are both on and are connected in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

中心像素连接到6像素的面孔和the edges of 12 pixels

Current pixel is center of cube.

26

如果像素的脸,边缘或角触摸,则连接像素。如果两个相邻的像素是同一对象的一部分,则它们均为并连接为:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

  • A combination of three directions, such as in-right-up or in-left-down

中心像素连接到6像素的面孔, the edges of 12 pixels, and the corners of 8 pixels

Current pixel is center of cube.

For higher dimensions,Bwlabelnuses the default valueConndef(ndims(bw),“最大”)

连接性can also be defined in a more general way for any dimension by specifying a 3-by-3-by- ... -by-3 matrix of0s and1s. The1-valued elements define neighborhood locations relative to the center element ofconn。注意connmust be symmetric about its center element. See指定自定义连接for more information.

Data Types:double|logical

Output Arguments

collapse all

Label matrix, returned as an array of nonnegative integers with the same size asBW。The pixels labeled0are the background. The pixels labeled1组成一个对象;标记的像素2组成第二个对象;等等。

Data Types:double

Number of connected objects inBW, returned as a nonnegative integer.

Data Types:double

Tips

  • The functionsbwlabel,Bwlabeln, 和bwconncompall compute connected components for binary images.bwconncompreplaces the use ofbwlabelBwlabeln。It uses significantly less memory and is sometimes faster than the other functions.

    功能 Input Dimension Output Form Memory Use 连接性
    bwlabel 2-D Label matrix with double-precision 高的 4 or 8
    Bwlabeln N-D 双精度标签矩阵 高的 任何
    bwconncomp N-D CCstruct Low 任何
  • 使用二进制图像提取功能regionpropswith default connectivity, just passBWdirectly intoregionprops使用命令regionprops(BW)

Algorithms

Bwlabelnuses the following general procedure:

  1. Scan all image pixels, assigning preliminary labels to nonzero pixels and recording label equivalences in a union-find table.

  2. Resolve the equivalence classes using the union-find algorithm[1]

  3. 根据已解决的等效类别重新标记像素。

参考

[1]Sedgewick, Robert,Algorithms in C,第三版,Addison-Wesley,1998年,第11-20页。

Version History

在R2006a之前引入