Bwlabel function (element tags in binary images)

Source: Internet
Author: User

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.

  1. 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:

  1. [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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.