Sitemap
TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.

Image Processing Class #6 — Morphological Filter

5 min readDec 26, 2018

--

This article is for sum up the lesson that I have learned in medical image processing class (EGBE443).

This article is about basic image processing. If you are new in this field, you can read my first post by clicking on the link below. :)

In the previous chapter, I’ve talked about a method to remove noise using median filter. Median filter makes image structure change a lot. A figure below shows the result of applying median filter to a binary image. The small structures, single line, and dot, are removed and small size holes are filled.

Press enter or click to view image in full size

So in this chapter, I will introduce an idea which overcomes this problem. It is called “Morphological Filter”.

Press enter or click to view image in full size
Shrink and grow process

Morphological Filter

The idea of the morphological filter are shrink and let grow process. The word “shrink” means using median filter to round off the large structures and to remove the small structures and in grow process, remaining structures are grow back by the same amount.

The morphological operation of the binary image is described first and will talk in the following outline.

Outlines

  • The structuring element of a binary filter
  • Dilation and Erosion
  • Composite Operation

The structuring element

In morphological filter, each element in the matrix is called “structuring element” instead of coefficient matrix in the linear filter. The structuring elements contain only value 0 and 1. And the hot spot of the filter is the dark shade element.

Press enter or click to view image in full size

The binary image is described as sets of two-dimensional coordinate point. This is called “Point Set” Q and point set consist of the coordinate pair p = (u,v) of all foreground pixels. Some operations of point set are similar to the operation in others image. For inverting binary image is complement operation and combining two binary image use union operator. Shifting binary image I by some coordinate vector d by adding vector d to point p. Or reflection of binary image I by multiply -1 to point p.

Dilation and Erosion

  • Dilation is a morphological operator which works for the grow process as I mentioned before. The equation of this operator is defined as
Press enter or click to view image in full size
  • Erosion is a morphological operator which works for the shrink process as I mentioned before as well and the equation is defined as
Press enter or click to view image in full size

Properties of dilation and erosion

  • Commutative: only in dilation
  • Associative: only in dilation

Note that: in erosion is in contrast to dilation, not have commutative property.

Get Pitchaya Thipkham’s stories in your inbox

Join Medium for free to get updates from this writer.

In addition, erosion and dilation are duels, for a dilation of the foreground can be accomplished by an erosion of background and subsequent of the result in two different properties but work similarity

Press enter or click to view image in full size

Composite Operation

In morphological process, dilation and erosion work together in composite operation. There are common way to represent the order of these two operations, opening and closing. Opening denotes an erosion followed by dilation and closing work in opposite way.

Press enter or click to view image in full size
Opening and Closing process respectively

The opening and closing also are dual in sense that opening the foreground is equal to closing the background.

Press enter or click to view image in full size

Morphological Filter can also apply to gray-scale image, but in the different definition. It is a generalization with MIN and MAX operators. I will describe in following outline.

Outlines

  • Structuring Elements
  • Dilation and Erosion
  • Opening and Closing

Structuring Element

In gray-scale morphology, structuring elements are defined as real-value 2D functions instead of point sets

Press enter or click to view image in full size

The value in H can be negative or zero value. But it contrast to linear convolution, zero elements are used to compute the result. And if you do not want to use the elements in some location, you can put no element in that location.

Press enter or click to view image in full size

Dilation and Erosion

The result of dilation and erosion in gray-scale morphology is contributed from maximum and minimum operation.

For dilation, the result is the maximum value of the value in H add to the current sub-image.

Press enter or click to view image in full size

For erosion, the result is the minimum value of the difference.

Press enter or click to view image in full size

These operations can cause the negative value, so we need to clamping the result after calculation.

Press enter or click to view image in full size
Example of dilation in gray-scale morphology

Opening and Closing

Opening and closing in gray-scale morphology work in the same way as in binary morphology. The difference is just the operator in dilation and erosion.

For implementation in Python 3 using OpenCV module, you can use the function cv2.erode(input,size) and cv2.dilate(input,size)

This is the result of the program, erosion and dilation, opening and closing.

Press enter or click to view image in full size
The result of erosion and dilation of the program.
Press enter or click to view image in full size
The result of opening and closing from the program.

This is my last article on image processing. Thanks for reading and following my post. Keep enjoying image processing! I’ll be back soon, Good luck. :)

--

TDS Archive
TDS Archive

Published in TDS Archive

An archive of data science, data analytics, data engineering, machine learning, and artificial intelligence writing from the former Towards Data Science Medium publication.