Morphological filters
Prerequisites
Before starting this lesson, you should be familiar with:
Learning Objectives
After completing this lesson, learners should be able to:
Understand how to design morphological filters using rank filters
Execute morphological filters on binary or label images and understand the output
Motivation
Morphological filters (MFs) are used to clean up segmentation masks and achieve a change in morphology and/or size of the objects. For example, MFs are used to remove wrongly assigned foreground pixels, separate touching objects, or identify objects boundaries.
Concept map
Figure
Rank filters
In the region defined by the structuring element, pixel elements are ranked/sorted according to their values. The pixel in the filtered image is replaced with the corresponding sorted pixel (smallest = min, greatest = max, median ). See also Median filter. Morphological filters corresponds to one or several rank filters applied to an image.
Morphological filters on binary images
A typical application of these filters is to refine segmentation results. A max-filter is called dilation whereas a min-filter is called erosion. Often rank filters are applied in a sequence. We refer to a closing operation as a max-filter followed by a min-filter of the same size. An opening operation is the inverse, a min-filter followed by a max-filter.
Opening operations will:
- Remove small/thin objects which extent is below the size of the structuring element
- Smooth border of an object
Closing operations:
- Fill small holes below the size of the structuring element
- Can connect gaps
Image subtraction using eroded/dilated images allows to identify the boundary of objects and is referred to morphological gradients:
- Internal gradient: original - eroded
- External gradient: dilated - original
- (Symmetric) gradient: dilated - eroded
Fill holes operation is a slightly more complex morphological operation. It is used to identify background pixels surrounded by foreground pixels and change their value to foreground. Algorithmically there are several ways to achieve this.
Morphological filters on label images
Morphological filters work also on label images. If the objects are not touching this will achieve the expected result for each label. However, when objects touch each other, operations such as dilations can lead to unwanted results.
Morphological filters on grey level images
Min and max operations can be applied to grey level images. Applications are for example contrast enhancement, edge detection, feature description, or pre-processing for segmentation.
Activities
Dilation and erosion of a binary image
- Open xy_8bit_binary__three_spots_different_size.tif
- Explore erosion and dilation
- Appreciate how structures grow and shrink or even disappear depending on the size of the structuring element
Show activity for:
ImageJ Macro
skimage napari
Opening and closing of a binary image
- Open xy_8bit_binary__for_open_and_close.tif
- Perform erosion followed by dilation - opening. Explains it effects in removing small structures. If applicable show that opening runs as single command.
- Perform dilation followed by erosion - closing. Explains it effects on filling small holes, connecting gaps. If applicable show that opening runs as single command.
Show activity for:
ImageJ Macro
skimage napari
Morphological internal gradient of a binary image
- Open xy_8bit_binary__h2b.tif
- Perform an erosion
- Subtract eroded image from binary image and discuss the results. This operation is sometime called internal gradient
- If applicable show where the morphological gradient runs as a single command
Show activity for:
ImageJ Macro
skimage napari
Workflow to measure the intensity on a nuclear membrane
In image xyc_16bit__nup__nuclei.tif we would like to measure the intensity along the nuclear membrane (channel 1) using the information from the DNA (channel 2) using following workflow:
- Segmentation of the nuclei using channel 2, the results is a binary mask.
- Cleanup of the binary mask using morphological filters (try opening and closing operations). You should get something like xy_8bit_binary__nuclei.tif.
- Use the improved binary mask to compute a rim mask around the nucleus
- Perform a connected components analysis to obtain a labeled image of the nuclear rim. You should get something like xy_8bit_labels__nuclei.tif.
- Measure the intensities in channel 1 on the nuclear rim
Show activity for:
ImageJ GUI
// TODO adapt to new text
- Open the image xy_8bit_binary__nuclei_noisy.tif
- [Plugins > MorpholibJ > Filtering > Morphological Filters]
- operation : Opening
- element : Square
- radius : 1
- [Plugins > MorpholibJ > Filtering > Morphological Filters]
- operation : Closing
- element : Square
- radius : 16
An alternative to the closing operation is also [Plugins > MorpholibJ > Filtering > Fill Holes (Binary/Gray)]
- Open xy_8bit_labels__nuclei.tif
- [Plugins > MorpholibJ > Filtering > Morphological Filters]
- Operation : Internal Gradient
- Element : Square
- Radius : 3
- [ Image › Rename… ]
- “rim”
- Open xyc_16bit__nup_nuclei
- [Image > Duplicate…]
- Title : Ch1
- Duplicate hyperstack
- Channels (c): 1
- [Plugins > MorpholibJ > Analyze > Intensity Measurements 2D/3D]
- Input : Ch1
- Labels : rim
ImageJ Macro
Create a cytoplasmic ring label mask
- Open the nuclei label mask image xy_8bit_labels__nuclei.
- Create cytoplasmic rings by dilating the labels and subtracting the original (or slightly dilated) input nuclei labels.
- Note that a naive morphological dilation will not work here as close by nuclei will grow into each other.
Show activity for:
skimage napari
Assessment
Fill in the blanks
Using those words fill in the blanks: closing, opening, min, shrinks, decreases, enlarges, max.
- An erosion _____ objects in a binary image.
- An erosion in a binary image _____ the number of foreground pixels.
- A dilation _____ objects in a binary image.
- An erosion of a binary image corresponds to a ___ rank operation.
- An dilation of a binary image corresponds to a ___ rank operation.
- A dilation followed by an erosion is called ___.
- An erosion followed by a dilation is called ___ .
Solution
- shrinks
- decreases
- enlarges
- min
- max
- closing
- opening
True of false?
Discuss with your neighbour!
- Morphological openings on binary images never decrease the number of foreground pixels.
- Morphological closings on binary images never decreases the number of foreground pixels.
- Performing a morphological closing twice in a row does not make sense, because the second closing does not further change the image.
- Performing a morphological closing with radius 2 element is equivalent to two subsequent closing operation with radius 1.
Solution
- False
- True
- True
- False
Follow-up material
Recommended follow-up modules:
Learn more: