Skip to content
CoreSource checked

Median Filter

Replaces each sample or pixel with the median of a local neighborhood.

Quick Facts

Compact metadata for implementation and discovery.

Category
Signal Processing
Difficulty
Beginner
Family
Nonlinear Filter
Tier
Core
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
2
Code example
Not ready
Visualization
Ready

Overview

A median filter slides a window over a signal or image and outputs the median value in that window. It reduces impulse noise while preserving sharper edges better than simple averaging.

Core Concepts

signal samplesranked neighborhoodfilter kernelnoise smoothingnonlinear filtersample windowsignal transformnoise handling

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(n)

Average

O(n k log k)

Worst

O(n k log k)

Space

O(k)

When to Use

  • Use when outlier samples should be suppressed without averaging across edges too much.
  • Use when the window size can be chosen relative to feature size.

When Not to Use

  • Avoid when Gaussian-like noise is better handled by linear filters.
  • Avoid with windows so large that real features are erased.

What It Does

  • Collects values in a local window
  • Sorts or selects the median value
  • Outputs the median as the filtered sample

Use Cases

  • Removing salt-and-pepper noise
  • Robust smoothing for images or signals
  • Preprocessing before thresholding or edge detection

Inputs

  • Signal or image
  • Window size

Outputs

  • Filtered signal or image

Key Formulas (1)

Median replacement

output[i] = median(values in local window around i)
output[i] = median(values in local window around i)

Replaces each sample with the middle-ranked value from its neighborhood.

Pseudocode

  1. 1.Choose a local window size and boundary policy
  2. 2.For each output position
  3. 3.Collect neighboring samples inside the window
  4. 4.Select the median value
  5. 5.Write the median to the output

Canonical Example

Input
window [2, 100, 3]
Output
3
Explanation
The outlier 100 is ignored because the median is the middle sorted value.

Implementation Notes

  • Use odd window sizes unless an even-window policy is explicitly needed.
  • Test impulse-noise examples and edge-preservation examples.
  • For images with small integer ranges, histogram-based median updates can be faster.

Common Pitfalls

  • Even-sized windows need a defined median convention.
  • Boundary padding choices change output near edges.
  • Large naive windows can be expensive without incremental histograms or selection structures.

Interactive Mechanism Walkthrough

Iterative Convergence & State Trajectory

Show an outlier removed by choosing the middle value in a window.

Median Filter mechanism walkthrough step 1 of 5x₀x₁x₂x*
Step 1 of 5: Choose a local window size and boundary policy
median-window

Notes

Median filtering is nonlinear; it does not have the same frequency response interpretation as linear filters.

Sources (1)

What each reference supports for this entry.

Digital Image Processing

Book

Image-processing reference for nonlinear filters such as median filtering and practical neighborhood operations.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toGaussian Blur

Median filters suppress impulse noise, while Gaussian blur averages local neighborhoods.

Conceptual neighborMorphological Dilation

Both are local-window image operations but use different order statistics.

Tags

Signal ProcessingMedian FilterFilteringSmoothing