In Bwlabel (bw,n) Matlab, a connected region of white (1) labeled binary image is __matlab

Source: Internet
Author: User

[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

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.