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 threefold) 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 grayscale 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
Use example images that are relevant to your science and explore in detail what happens when applying a median filter. On purpose, increase the neighbourhood to an extend where your structures of interest become clearly compromised. Do some of all of these activities.

Open image xy_8bit_binary__squares_different_size.tif discuss effect of median filter on removing small objects, preserving edge and changing edges for large radii.

Open image xy_8bit_binary__large_spot.tif discuss effect of median filter on edge changes. Use a ROI and apply filter only on the ROI. Compare also to mean filter.
 Open image xy_8bit__two_noisy_squares_different_size.tif and discuss effect of median and mean filter of different size with respect to noise and preservation of structure.

Open image xy_8bit__PCNA.tif and discuss effect of filters with respect to preservation of structure.
 (Optional) Open image xy_8bit_binary__test_structures.tif and discuss what happens to the structures. This is a more detail inspection of what does a median filter do.
Show activity for:
ImageJ GUI & Macro median
ImageJ GUI & Macro mean
Exercises
Show exercise/solution for:ImageJ GUI
Exercise 1
 Open xy_16bit__microtubules.tif
 Apply median filter with radius 1 and 3, respectively
 Estimate the width of microtubules for nonfiltered and filtered images using a line profile ([Analyze > Plot Profile])
 What happens for a median filter with a radius above 10?
 What happens to the microtubule width if you mean filter with radius 3?
Solution
 [Image > Duplicate] Title = small_median
 [Image > Duplicate] Title = large_median
 on small_median [Process > Filters > Median] radius = 1
 on large_median [Process > Filters > Median] radius = 3
 Draw a line with a line tool orthogonal to the MTs
 Measure line width using [Analyze > Plot Profile] or [CtrlK]
 Estimate width or in profile window [Data» > Add fit…] and [Fit function > Gaussian] the parameter d
is a proxy for the width (d = sigma). For radii larger than 10 the microtubules disappear
 A mean filter with radius 3 will increase the apparent width (blur) the microtubules
Exercise 2
 Open xy_8bit__nuclei_noisy_different_intensity.tif
 Estimate radius of nuclei
 Apply median filter smaller than nucleus radius
 Apply median filter larger than nucleus radius
 Which radius can be used to
 suppress noise
 remove dark spot in one of the nuclei
 remove both nuclei
 Compare median filter to mean filter of same radii
 What are the advantages of a median filter?
 What are the advantages of a mean filter?
Solution
 [File > Open …] xy_8bit__nuclei_noisy_different_intensity.tif
 Draw a line with a line along one of the nuclei and measure radius. About 7 px
 Apply median filter smaller than nucleus radius: noise is suppressed
 Apply median filter larger than nucleus radius: nuclei are shrinking
 Which radius can be used to
 suppress noise: 2
 remove dark spot in one of the nuclei: 1
 remove both nuclei: 20
 Compare median filter to mean filter of same radii
 What are the advantages of a median filter? edge preserving
 What are the advantages of a mean filter? small structure preserving
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
Followup material
Recommended followup modules:
Learn more: