# 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

## 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

## 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

## Explanations

## 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

## Follow-up material

Recommended follow-up modules:

Learn more: