Bob’s Imaging Fundamentals #11: Morphology Part 2
Last time we saw one of the two building blocks of Binary Morphology: Erosion. Today we are going to have a look at the other: dilation.
As some of you may remember, the purpose of morphological erosion is to nibble away at the objects in a binary image in order to get rid of unwanted noise. The downside of this operation is that we also nibble away some of the good parts. Luckily for us though, the dilation operator does the opposite of the erosion operator, it actually increases the size of the objects. But wait a minute!?! Won’t that bring all the noise back? Only if there is noise left in the image after you’ve applied the erosion operator. In other words, if you’ve used a big enough erosion structuring element or, you’ve applied it often enough– you can erode your image more than once – you shouldn’t have too much noise left to enhance. But, I’m getting ahead of myself…
Erosion affects a reduction because it uses the logical AND operation to evaluate the results of the application of the structure element. The reason this causes a reduction is that, by its very nature, the AND operation results in a ‘0’ in 3 out of 4 binary combinations (see below). Conversely, the dilation operation which uses the logical OR operation on the outcome of the structuring element, will result in an increase in the size of objects since the logical ‘OR’ results in a ‘1’ for 3 out of 4 binary combinations:
The cool thing about dilation is that it is much easier to understand than erosion. Basically it boils down to this: If at least one member of your structuring element set is overlapping your target set, you get a result. But, just to be sure we are all riding the same bus, let’s have a ‘leetle’ example OK?
Well, I’m sure the result comes as no surprise to any of you. However, just to make sure we’ve all mastered dilation, here are the results obtained with a couple of different B’s:
It must be clear at this point that if we apply dilation after erosion, the objects in the image regain some of their lost dimension. However, if the object becomes too eroded, there is no longer much object left to increase. Let’s take our original ‘A’ and ‘B’ and apply each operator in turn:
As you can see, dilation can’t restore an object once it has been eroded down to a few pixels. However, this is a good thing because, in a real application, the only thing that gets eroded away to that point is noise so, we don’t want it to come back! By the way, the operation we just performed (erosion followed by dilation) is called a “Morphological Opening.” And, where there’s an opening, there’s usually a huge pile of resumes, which, eventually leads to a closing!
That’s right, closing consists of applying erosion followed by dilation. But why do they call these operations opening and closing? The reason becomes apparent when you start to apply them to real images. In the case of opening, we notice that narrow gaps open up and thin protrusions disappear. Whereas with closing, narrow gaps close up (i.e. objects fuse together) and small holes disappear. Obviously there are all kinds of cool uses for our basic morphological operators, such as: boundary extraction, region filling and thinning to name but a few. But be careful when evaluating these different approaches, because although many morphological techniques are very effective, they can have a downside. The problem is many morphological techniques tend to be recursive in nature; in other words, the operation is repeated several times in order to achieve the desired result. On the other hand, you can lessen the impact on processing time by applying your algorithms to a region of interest instead of the whole image.
Anyway, remember the result I got last time when I applied a 5 x 5 Erosion operator to those letters?
Although most of the noise disappeared, the resulting image was a little too eroded in some places. So let’s see what happens when we apply our new dilation operator to the eroded image!
We get most of our letters back but none of the noise! Sure, some of the gaps in the letters were too wide so they could not be bridged, but that was my fault for not taking a good image to begin with. The bottom line is binary morphology is a powerful approach to noise reduction and feature extraction, so make sure you have it in your machine vision toolbox, just in case.
About this article: Bob’s Imaging Fundamentals is an article series based on the work of Bob Howison. Originally titled Bob’s Brain Snacks, these articles were intended to help employees and partners get up to speed with the fundamental concepts of image processing. They became such a popular reference that we’ve decided to bring them to the Possibility Hub. As technology goes further, faster, and new industries discover the power of digital imaging, it’s important to remember the basics.
Bob’s Brain Snacks are recommended for anyone interested in learning about imaging technology. Sharpen your mind and try one!