How To Make Geodesic Dilation And Erosion In Morphology

Geodesic dilation and erosion are fundamental morphological reconstruction algorithms which yield the same result if left to converge.


Andraz Krzisnik
How To Make Geodesic Dilation And Erosion In...

Geodesic dilation and erosion are fundamental operations in morphological reconstruction branch. Furthermore, these processes have a special spin on basic dilation and erosion. They enable us reconstruction of specific shapes in the image.

However, we’re still dealing with binary images here. In case you’re new here, binary images are images that hold either black or white pixels. In other words, we can divide these images to two sets, one for foreground pixels and other for background pixels.

The special thing about these two processes is that we use two images for each of them instead of one. Similarly to basic versions, we need an image to apply either dilation or erosion on it. Together with this image, we also need a masking image, which will limit the growth or shrinkage of the resulting image.

How does geodesic dilation and erosion work?

With geodesic dilation, we need to acquire the intersection between masking image and dilated image. As we mentioned before, masking image will limit the way successive dilations grow.

geodesic dilation process illustration
Geodesic dilation process illustration

On the other hand, geodesic erosion is a morphological dual to dilation. Therefore, both processes will eventually converge to the same result. However, with erosion, we take away foreground pixels, so what we’re looking for is the union between input and masking image.

Geodesic erosion process illustration
Geodesic erosion process illustration

Both operations converge after a finite number of steps, which yield a resulting image that is identical to the masking image.

One example of geodesic dilation use was in the pruning tutorial post on this blog. We used it to reconstruct a part of handwritten letters, we removed in the thinning process. I recommend you check it out to learn more about the process.

Code

Although I make a demo project for each of the process I describe on this blog, I will only post a segment that applies geodesic dilation on this one. However, it should give you an idea of how to implement the erosion as well.

public static byte[] Dilate(this byte[] buffer, byte[] limiter, int w, int h)
     {
         byte[] result = buffer;

         for (int x = 1; x < w - 1; x++)
         {
             for (int y = 1; y < h - 1; y++)
             {
                 int position = x + y * w;
                 byte val = 15;
                 for (int kx = -1; kx < 2; kx++)
                 {
                     for (int ky = -1; ky < 2; ky++)
                     {
                         int se_pos = position + kx + ky * w;
                         val = Math.Max(val, buffer[se_pos]);
                     }
                 }

                 if (limiter[position] > 0)
                 {
                     result[position] = val;
                 }
             }
         }

         return result;
     }

Conclusion

I hope this post helped you understand how geodesic dilation and erosion in image processing work.

Related Articles

Adaptive Filters

How To Make Adaptive Median Filter For Images With C#

Adaptive median filter is much more effective at removing impulse noise, also known as salt and pepper noise, than traditional median filter.

Posted on by Andraz Krzisnik
C# Tutorial

C# Tutorial: How To Scale Images Without Deforming Them

Let’s Get Started A very basic problem that we face in image processing is how to scale images without making them look deformed when we want to make it of an arbitrary...

Posted on by Andraz Krzisnik