Corrosion, expansion, open and closed operations in morphological operations.
1. corrosion is a process of eliminating boundary points and shrinking the boundary to the interior. It can be used to eliminate small and meaningless objects.
Corrosion algorithm:
Scan each pixel of an image with a 3x3 structure element
Perform the "and" operation with the structure element and the binary image covered by it
If both are 1, the pixel of the result image is 1. Otherwise, it is 0.
Result: The second-value image is reduced by one lap.
2. Expansion refers to the process of merging all background points in contact with the object into the object to make the boundary expand externally. It can be used to fill holes in objects.
Expansion algorithm:
Scan each pixel of an image with a 3x3 structure element
Perform the "and" operation with the structure element and the binary image covered by it
If both are 0, the pixel of the result image is 0. Otherwise, the value is 1.
Result: The binary image is enlarged.
3. The process of first corrosion and then expansion is called an open operation. It is used to remove small objects, separate objects at slender points, and smooth the boundary of large objects without significantly changing the area.
4. The process of first expansion and then corrosion is called closed operation. It is used to fill the body with small holes, connect adjacent objects, and smooth its boundary without significantly changing its area.
// Example code of Corrosion
// Use structural elements in the horizontal direction for corrosion
For (j = 0; j <lheight; j ++)
{
For (I = 1; I <lWidth-1; I ++)
{
...
// The current vertex in the target image is first black.
* Lpdst = (unsigned char) 0;
// If the current or left vertices in the source image are not black,
// The current vertex in the target image is white.
For (n = 0; n <3; n ++)
{
Pixel = * (lpsrc + N-1 );
If (pixel = 255)
{
* Lpdst = (unsigned char) 255;
Break;
}
}
}
}