Skip to main content

Median

Replaces each pixel's value with the median value of neighboring pixels, effectively reducing noise and preserving edge details.

🖼️ Image options and parameters of median method

Median filter is a digital image processing technique used to reduce noise in an image by replacing each pixel's value with the median value of neighboring pixels. It's particularly effective at removing "salt and pepper" noise.

placeholderplaceholder
Ran in 0.00μs (Infinity ops/s)

The key advantage of using the median filter, especially for noise reduction, is that it is less sensitive to extreme values or outliers compared to other filters like the mean filter. Since noise often appears as isolated bright or dark pixels that deviate significantly from their neighbors, the median filter effectively ignores these outliers and replaces them with more representative values from the local neighborhood.

However, the median filter also has limitations. It can blur sharp edges and thin lines in the image, as it doesn't consider the spatial relationship between pixels beyond their intensity values. This means that while it's great for removing noise, it might not be suitable for all types of image enhancement tasks.

Kinds of images compatible with algorithm

Image propertyWhat it meansPossible values
bitDepthnumber of bits per channel[8,16]
componentsnumber of componentsany
alphais alpha channel allowedtrue

Parameters and default values

  • options

Options

PropertyRequiredDefault value
cellSizeyes1
borderTypenoreflect101
borderValueno0
Implementation

Here's how median filter is implemented in ImageJS:

Window or Kernel Selection: The first step is to choose a small window or kernel. This window will move over the entire image, pixel by pixel.

Pixel Neighborhood: As the window moves over the image, for each pixel location, the filter collects the pixel values within the window's neighborhood. The neighborhood consists of the pixels that are currently covered by the window/kernel.

Median Calculation: The collected pixel values within the neighborhood are then calculated with internal algorithm.

Median Replacement: After calculating the median value, the filter replaces the original pixel value with this median value. This process is repeated for every pixel in the image, as the window moves over the entire image.