Morphology
Learn how to apply morphology operations to improve the quality of a mask.
We'll cover the following...
An imperfect mask
When we worked on masking, we generated a mask highlighting the green anchor dowels. We noticed that this mask was not perfect. Some pixels that didn’t belong to a green dowel were active, and the surface of some dowels had holes.
We want to clean up our mask by eliminating the spurious pixels and filling the holes in the dowel surfaces. Such is the purpose of the morphology operations. Most morphology operations we need derive from two simple functions: dilation and erosion.
Dilation
The dilation operation replaces the value of a central pixel with the maximum value in the central pixel’s neighborhood. In the case of a binary image, dilation will increase the active area.
In the image above, we see the effect of dilation with a neighborhood of 3x3. The neighborhood definition is called the dilation kernel. The central pixel has a value of 255 in the dilated mask because at least one pixel in its neighborhood has a value of 255. Dilation has the effect of filling holes in a binary image. Let’s apply dilation to our original mask.
Our goal is to fill ...