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