StrataQuest Home › StrataQuest Glossary › Median Filter
BOM Operation

Median Filter

Sets aside extreme pixels, keeps edges sharp

View
Definition
The median filter is a non-linear, rank-order filter: it replaces each pixel with the median of the values in its neighborhood. The output is always a value already present in that neighborhood, never an interpolated average. That is why the filter sets aside isolated outlier pixels and keeps the sharp edges that linear smoothing filters blur.
Non-Linear Filter
Uses rank ordering, not weighted averaging
Edge Preservation
Step edges pass through unchanged
Isolated pixels are outvoted
Sets aside isolated extreme pixels
Not Separable
Heavier than a Gaussian for large kernels

How It Works

For each pixel in the image, the median filter does three things:

  1. Collects all pixel values within the neighborhood (a square or circular window)
  2. Sorts these values in ascending order
  3. Replaces the center pixel with the median, the middle value

The median is the value that minimizes the sum of absolute differences to all other values in the set. That makes it the optimal estimate under impulsive noise.

Two more properties follow:

  • Idempotent for binary images: applying the median filter twice to a binary image gives the same result as applying it once
  • Corner rounding: sharp corners (structures smaller than the kernel) get rounded, much as in morphological opening
Simplified

The median filter lines up the pixel values in a neighborhood and picks the middle one. It is like taking a vote, and an extreme pixel is always outvoted by the typical pixels around it. The extreme pixels disappear and the edges stay sharp, because the median of the values on one side of an edge is that side's own value.

Image Processing Foundation

What Non-Linearity Changes

A linear filter such as the Gaussian computes a weighted sum, so every pixel in the neighborhood contributes in proportion. A single extreme outlier pulls the average toward itself and leaves a blurred artifact. The median is a rank-order statistic: an outlier's magnitude does not matter at all, only its place in the sorted order.

Median vs. Mean

The mean filter gives every pixel equal weight, which is why Solomon & Breckon call it "not robust to outliers." For Gaussian-distributed noise, the mean filter is optimal. For impulsive noise, the median filter performs much better.

Limitations

  • Clusters of extreme pixels larger than (n²−1)/2 pixels, for an n×n kernel, survive, because they become the majority in the sorted list
  • Fine structures smaller than the kernel are removed, much as in morphological opening
  • Repeated application tends toward a piecewise-constant image (a staircase effect)
Simplified

A single extreme pixel, such as a hot pixel from the sensor, can pull a Gaussian average a long way. It can't affect the median at all: it lands at one end of the sorted list and is ignored. That is why the median filter is the standard tool for the salt-and-pepper speckle common in microscopy images.

Parameters & Settings

ParameterTypeDescription
ImageGrayscale imageThe image to filter.
Kernel radius (px)Integer, default 1Radius of the neighborhood for the median, not its width: radius 2 gives a 5×5 window. Larger radii set aside larger clusters of extreme pixels and also remove more fine detail.
Kernel shapeSelection, default DiskThe shape of the neighborhood.
Simplified

The main setting is Kernel radius. Use radius 1 to remove single-pixel outliers, and radius 2 (a 5×5 window) or more for heavier speckle, knowing that details smaller than the kernel will be lost.

Connected Terms

Share This Term
Term Connections