ScientiaLux
strataquest Glossary Median Filter
BOM Operation

Median Filter

Non-linear noise removal that preserves edges

View
Definition
A non-linear rank-order filter that replaces each pixel with the median value of its neighborhood — excelling at removing salt-and-pepper noise and isolated outlier pixels while preserving sharp edges better than any linear smoothing filter.
Non-Linear Filter
Uses rank ordering, not weighted averaging
Edge Preservation
Step edges pass through unchanged
Salt-and-Pepper Specialist
Removes impulsive noise completely
Not Separable
Computationally heavier than Gaussian for large kernels

How It Works

For each pixel in the image, the median filter:

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

Because the output is always an actual pixel value from the neighborhood — never an interpolated average — the filter preserves edges remarkably well. The key insight: the median is the value that minimizes the sum of absolute differences to all other values in the set, making it the optimal estimate under impulsive noise.

Properties:

  • Idempotent for binary images — applying the median filter twice to a binary image gives the same result as applying it once
  • Edge preservation — step edges survive because the majority vote on each side of the edge determines the output
  • Corner rounding — sharp corners (structures smaller than the kernel) get rounded, similar to morphological opening
Simplified

The median filter lines up all the pixel values in a neighborhood and picks the middle one. It's like taking a vote — noise pixels are always outvoted by the surrounding normal pixels. The result: noise disappears but edges stay sharp, because the median of values on one side of an edge is just that side's normal value.

Image Processing Foundation

Solomon & Breckon describe the median filter as "superior to the mean filter in that it is better at preserving sharp high-frequency detail (edges) whilst also eliminating noise, especially isolated noise spikes (salt and pepper noise)."

Why Non-Linearity Matters

Linear filters (like Gaussian) compute weighted sums — every pixel in the neighborhood contributes to the output proportionally. A single extreme outlier pulls the average toward itself, creating a blurred artifact. The median, being a rank-order statistic, is completely unaffected by the magnitude of outliers — only their position in the sorted order matters.

Median vs. Mean

The mean filter gives equal weight to all pixels, making it "not robust to outliers" (Solomon & Breckon). The median "is a pixel value drawn from the neighbourhood itself" — the output is always an observed value, never an artificial intermediate. For Gaussian-distributed noise, the mean filter is optimal. For impulsive noise, the median filter is dramatically better.

Limitations

  • Noise clusters larger than (n²−1)/2 pixels (for an n×n kernel) survive the median — they become the majority in the sorted list
  • Fine structures smaller than the kernel get removed (similar to morphological opening)
  • Repeated application tends toward a piecewise-constant image (staircase effect)
Simplified

The key advantage: a single noise pixel (like a hot pixel from the sensor) can dramatically affect a Gaussian average, but it can't affect the median at all — it just gets ranked at one end of the sorted list and ignored. This is why the median filter is the standard tool for salt-and-pepper noise that plagues microscopy images.

Parameters & Settings

ParameterTypeDescription
InputGrayscale imageThe image to filter.
Kernel SizeOdd integerNeighborhood size for median computation (e.g., 3×3, 5×5). Larger kernels remove larger noise clusters but also remove more fine detail.
Simplified

The main setting is Kernel Size. Use 3×3 for minimal intervention (removes single-pixel noise). Use 5×5 or 7×7 for heavier noise, but be aware that fine details smaller than the kernel will be lost.

Connected Terms

Share This Term
Term Connections