Median filter
Prerequisites
Before starting this lesson, you should be familiar with:
Learning Objectives
After completing this lesson, learners should be able to:
Understand in detail what happens when applying a median filter to an image
Motivation
The median filter is a rank filter and is one of the most popular filters for reducing noise in microscopy images. While the median filter has indeed many good properties, it should be - like any other filter - used with care and a good understanding of its properties.
Concept map
Figure
Properties of median filter
The median filter is based on ranking the pixels in the neighbourhood
In general, for any neighbourhood filter, if the spatial extend of the neighbourhood is significantly (maybe three-fold) smaller than the smallest spatial length scale that you care about, you are on the safe side.
However, in biology, microscopy images are often containing relevant information down to the level of a single pixel. Thus, you typically have to deal with the fact that filtering may alter your image in a significant way. To judge whether this may affect your scientific conclusions you therefore should study the effect of filters in some detail.
Although a median filter typically is applied to a noisy gray-scale image, understanding its properties is easier when looking at a binary image.
From inspecting the effect of the median filter on above test image, one could say that a median filter
- is edge preserving
- cuts off at convex regions
- fills in at concave regions
- completely removes structures whose shortest axis is smaller than the filter width
Activities
Median filter exploration
Explore the effect of the median filter on various example images. Explore how changing the size (structural element) of the filter affects the result.
Example images:
- xy_8bit_binary__squares_different_size.tif
- Observe how the median filter can remove small objects while preserving edges of larger objects.
- xy_8bit_binary__large_spot.tif
- Observe that the median filter is not edge-preserving for curved edges.
- xy_8bit__two_noisy_squares_different_size.tif
- Observe how the median behaves in the prescence of noise.
- xy_8bit__PCNA.tif
- Observe how the median filter can remove small internal structure from larger objects.
- xy_8bit_binary__test_structures.tif
- Observe how the median filter behaves for binary images.
Show activity for:
ImageJ Macro
skimage napari
Galaxy
- Upload the following images to Galaxy
- Navigate to Galaxy
- Locate the Tools panel on the left, click the
Upload Data
button.- Within the
Uupload data
pop-up wintow, ClickPaste/Fetch data
button.- In the text box, paste the URLs of the following images. Enter each URL on a new line.
- Click the
Start
button to upload the images.- Once the upload is finished, click the
Close
button at the bottom of the upload window- The uploaded images will be available in your Galaxy history on the right panel.
- Apply Median Filter
- In the
Tools
panel, searchFilter 2D image
, and clickFilter 2D image with scikit-image
from the search results- In Galaxy main window,apply the followings
Filter type
:Median
Radius/Sigma
: Explore different values, such as1
,2
or5
Source file
: click the second button to activateMultiple datasets
. Select images from the dropdown list.- Click
Run Tool
- Depending on the number of input images, you will see the corresponding number of outputs in the
History
panel on the right. Wait for them to turn green and download the resulting images.
Assessment
True or false?
- Median filter is just another name for mean filter.
- Small structures can completely disappear from an image when applying a median filter.
Solution
- Median filter is just another name for mean filter. FALSE
- Small structures can completely disappear from an image when applying a median filter. TRUE
Follow-up material
Recommended follow-up modules:
Learn more: