Connected area marker-stroke scanning algorithm

Source: Internet
Author: User

1. Connected domains

For an image, its basic components are pixels, and each pixel corresponds to a grayscale value.

The Unicom area tag is for a two-value image, and the binary image is the name of its grayscale value only two values---0 or 255 of the image, a connected area refers to the image of those locations adjacent to the same grayscale value of the same pixel collection of the region.

The neighborhood relationship between pixels and pixels has 4 neighbors and 8 neighbors, and 4 neighbors refers to the pixels at the top and bottom of the current pixel, and the 8 neighborhood refers to the pixels at the top and bottom left and right of the diagonal position.

As shown in the image on the right, corresponding to the 4 neighborhood of the pixel and the 8 neighborhood location relationship

(x,y-1)
(x-1,y) (x, Y) (x+1,y)
(x,y+1)

4 Adjacent domains

(x-1,y-1) (x,y-1) (x+1,y-1)
(x-1,y) (x, Y) (x+1,y)
(x-1,y+1) (x,y+1) (x+1,y+1)

8 Adjacent domains

2. Connected Area Labeling Method

1) Stroke-based marking

A. Scan the image row by line, make a sequence of contiguous white pixels in a row, and note its start and end points, along with its line number.

B. For a regiment in all rows except the first line, if it has no overlapping areas with all the groups in the previous line, it marks a new label; if it overlaps only one of the previous lines, assign the label of the previous row to it, or if it overlaps with more than two groups on the previous line, Assigns the smallest label in several groups to it, and writes the labels to the equivalent pair, indicating that they belong to the same region.

C. The equivalence pair is converted to an equivalent sequence, and each sequence needs to be given the same label because they are all equivalent. Starting from 1, each equivalence sequence is given a label.

D. Iterate through the markers of the starting group, find the equivalent sequence, and give them a new label.

E. Fill in the image with the tags of each group

F. End

Using the above image to explain the stroke scanning algorithm

In the first line, we get two groups [2,6] and [10,13], while they are labeled 1 and 2.

In the second line, we get two groups [6,7] and [9,10], and they overlap with the two groups on the previous line, so they are labeled 1 and 2 with the group number on the previous line.

In the third line, two groups [2,4] and [7,8],[2,4] and the previous line do not overlap, so give it a new label 3,[7,8] and two groups in the previous row have overlapping, so give it two the smaller of the number of the group, that is 1, at the same time, will ["] write equivalent pairs.

After all the images have been traversed, we get the starting coordinates of many groups, the end coordinates and the rows and labels they are in. At the same time, we also get a list of equivalence pairs.

Connected area marker-stroke scanning algorithm

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.