12. Morphology

Note

This unit and two following units relate to finding objects from images, which of course is a very important machine vision application. When we can find and determine the location of objects (Homography) from an image, we can perform visual guided movement of machine and robotic parts. This unit relates to cleaning up logical images to remove unwanted objects and filling in missing areas from desired objects. In Segmentation, we will revisit forming logical images by tresholding and learn how to identify contiguous regions (blobs). Finally, in Image Features, we will learn about properties from the shape of blobs, called features, and how to identify shapes.

Reading Assignment

Please read section from 12.6 of [RVC] and chapter 13 of [PIVP].

Video Resources

It is VERY important that you watch this video on morphology because it has some animations that explain the morphology operations very clearly.

A very important task in machine vision applications is to recognise or find shapes contained in logical images. So we may have previously selected portions of an image based on criteria such as color or intensity. The output of these operations is likely to be a logical image.

When there are holes in the shapes (blobs) or there are other logically true sections of the image that are not what we are looking for, we can use Mathematical Morphology to clean up the image before attempting to extract features from the shapes.

Both the MVTB and IPT have functions for performing morphology. Here we will just define some terms for reference purposes. Make sure to watch Dr. Corke’s video (link above) because the animations will help you to understand it.

blob

A set of connected true pixels in a logical image. Connectivity is based on either a 4-neighborhood or 8-neighborhood (usually 4). The shape, size, and other features of blobs contribute to object recognition.

structuring element

A logical pattern of a specified shape and size used as a pattern to match blobs. It should match the shape desired, be smaller than objects searched for, but larger than non-objects. In the examples below, a 3x3 square (ones(3)) is used as the structuring element.

The MVTB has a kcircle function to create a circular structuring element. The IPT function strel can return several different structuring elements.

compatible structure

Where a structuring element overlaid on a blob aligns with true blob pixels, then at that point the blob is compatible with the structuring element.

erosion

A morphology operation where target pixels are only retained where the true blob are compatible with all of the structuring element. After erosion, blobs that are not partially compatible with the structuring element are removed and the compatible blobs are smaller.

MVTB: out = ierode(im, ones(3));

IPT: out = imerode(im, ones(3));

dilation

A morphology operation where target pixels are true where any part of the original blob is compatible with the structuring element. After dilation, blobs are larger, take on some of the shape of the structuring element, and holes in blobs are either partially of fully filled.

MVTB: out = idilate(im, ones(3));

IPT: out = imdilate(im, ones(3));

The basic morphology operations of erosion and dilation do a nice job of removing unwanted blobs and filling holes respectively, but they change the size of wanted blobs. When the two operation are done in sequence, the resulting wanted blobs are close to their original size.

opening

A morphology sequence that removes unwanted blobs leaving only compatible blobs. Erosion removes the unwanted blobs and then dilation restores the size of the compatible blobs.

MVTB: out = iopen(im, ones(3));

IPT: out = imopen(im, ones(3));

closing

A morphology sequence that fills holes in blobs. First, dilation fills the holes and then erosion restores the size of the blobs.

MVTB: out = iclose(im, ones(3));

IPT: out = imclose(im, ones(3));

To achieve both goals, experiment with the order to see which works best. If the holes in blobs are fairly large, then first performing opening and then closing might work well. If the holes are more like small noise, then first performing a closing following by an opening might be better. In the later case, the opening can remove chunks from the target which can not be restored.

The hardest part of morphology is usually to set a suitable size for the structuring element.