MATLAB: Connected Component Labeling without Using bwlabel or bwconncomp Functions
A connected component or object in a binary image is a set of adjacent pixels. Determining which pixels are adjacent depends on how pixel connectivity is defined. There are two standard classification connections for 2D images.
- Connected-4 – Pixels are connected when the edges touch. Two adjacent pixels are part of the same object if they are both on and connected along the horizontal or vertical direction.
- Connected-8 – Pixels are connected when their edges or corners touch. Two adjacent pixels are part of the same object if they are both on and connected along a horizontal, vertical, or diagonal direction.
So in this article we will understand the Connected Component labeling without using bwlabel or bwconncomp functions, before performing the labeling we have to understand the basic required terms-
labeling means is to identify and placing labels on each program of an object project in the image. in Binary image, it’s classified as 4-connected and 8-connected. for performing the labeling in MATLAB we use the Built-in function bwlabel() used to label the object in the binary image.
MATLAB has a function called bwlabel for labeling connected components. Connected components are extracted based on the iterative formula:
Xk = ( Xk-1 ⊕ B ) ∩ A where k = 1,2,3 …..
To perform Connected Component labeling without using bwlabel or bwconncomp functions:
If we use the built-in function bwlabel or bwconncomp to perform the labeling it is easier than without using these functions, but here the MATLAB code may be a little bit longer.
Here we use the given GeeksforGeeks logo to perform the labeling without using the built-in function. So firstly we have to plot the image and convert it into a binary image, then define the structure of the image to initialize the Label matrix with zero.
In the above code first read the image using the function and convert it into the binary image as you can see in the output. after then define the structuring element (B) and initialize the label matrix with zeros. then next find a nonzero element position in the input matrix A.
Perform the intersecting point with the matrix A. Y= A&imdilate(X, B), and so on. Connected components can be extracted using labels.
Differentiate Each Component with RGB Colors
To label each component in the image we will use the specific RGB colors using the following line of code.
Please Login to comment...