A bright speck in a robot camera image can pull a local arithmetic average away from its surrounding values. A median treats that same window differently: it selects by order rather than dividing the sum. That difference explains both its resistance to some isolated outliers and its ability to erase legitimate narrow detail.

The useful question is not which filter is universally better. It is what each statistic does to the particular arrangement of retained values. An unusual pixel might be interference, or it might be the feature the robot needs to observe.

OpenCV's Smoothing Images tutorial, version 4.12.0, defines median filtering through neighboring pixel values and discusses impulsive salt-and-pepper noise. SciPy's median_filter reference, displayed as v1.18.0 when checked, separately documents the footprint over which values are selected. The following windows are original examples rather than reproduced demonstrations.

Define a five-value rank operation

Use one-dimensional grayscale windows containing five real-valued samples. They are invented intensity values without a specified camera format, physical brightness calibration, or probability distribution.

To find their median, sort the five values and select the third. To find their arithmetic mean, add all five and divide by five. Use exact arithmetic before displaying rounded results.

These examples evaluate a window's output only. They do not require image-boundary padding, and they do not report execution of an image library. Restricting the discussion to an odd number of values also avoids differing software conventions for an even-sized median.

One extreme value affects the mean through its magnitude

Take the window:

78, 79, 80, 81, 240.

Its sorted order is already shown, so its median is 80. Its sum is 558, giving mean 111.6.

For this constructed example, suppose the first four values represent local variation around approximately 80 and the last is an unwanted bright impulse. The median stays within the surrounding cluster. The mean moves substantially upward because the extreme value contributes to the sum.

Replace only the last value with 800, while allowing the invented intensity representation to contain that number. The median remains 80. The mean becomes 1,118/5 = 223.6.

Increasing an already highest-ranked value did not change which sample occupied the middle rank. It did change the mean. This is a specific rank property, not proof that a real image contains the assumed contamination.

The median does not identify the cause

Now consider a window with two high values:

78, 79, 80, 240, 240.

The median is still 80, while the mean is 143.4. Three values in the lower group still determine the middle rank.

With three high values instead:

78, 79, 240, 240, 240.

The median becomes 240. The mean is 175.4.

A majority of these five samples now belongs to the high group. The median cannot infer that the group is unwanted merely because its values differ from the two remaining samples. It is selecting an order statistic from the data supplied.

More generally, when at least three values in a five-value window remain within a specified clean-value interval, the median must lie within that interval, regardless of the other two values. That statement does not guarantee recovery of an exact original value or describe every form of image corruption.

An ideal step can remain sharp

Consider a sharp one-dimensional transition from a level of 20 to a level of 180. A window straddling the transition might be:

20, 20, 20, 180, 180.

Its median is 20 and its mean is 84. Shift the window by one position across the same ideal step:

20, 20, 180, 180, 180.

Its median is 180 and its mean is 116.

For this noiseless step example, the median switches directly between the two levels as their majority changes. The mean introduces intermediate values in the transition region.

This illustrates a limited form of edge preservation. It is not a promise that every curved contour, corner, thin line, or textured boundary survives a median filter unchanged. The arrangement and width of the feature relative to the footprint matter.

A narrow real feature looks like an impulse

Suppose a bright feature occupies only the center of this window:

20, 20, 180, 20, 20.

Its median is 20, removing the center peak from the output. Its mean is 52, reducing and spreading its contribution when the operation slides along a larger signal.

The mathematics is the same whether the 180 represents an unwanted speck or a genuine narrow marking. The filter receives values, not a label explaining which physical interpretation is correct.

Two adjacent bright samples within a five-value dark window also fail to form a majority. A larger footprint can therefore remove features that were retained by a smaller footprint. That is a geometric consequence of rank selection, not automatically an improvement in measurement quality.

A median is not a weighted average

The operation is nonlinear. For another original five-value illustration, let window A be 0, 0, 0, 1, 1 and window B be 0, 1, 1, 0, 0. Each median is zero.

Their elementwise sum is 0, 1, 1, 1, 1, whose median is one. The median of the sum differs from the sum of the medians. A median therefore cannot generally be replaced by one fixed convolution kernel.

For the odd windows used here, the selected median equals one of the supplied values. That does not make it the original center pixel, an independently measured value at the center's physical location, or an unbiased estimate under every noise distribution.

The footprint gives the statistic its spatial meaning

A one-dimensional window, a square image neighborhood, and another shaped footprint can contain different mixtures of the same scene. The relevant “majority” is over the selected samples, not over the entire physical object.

Spatially clustered corruption can occupy most of one neighborhood while remaining rare in the full image. Likewise, a real thin feature can be a minority locally even when it extends across a large scene.

A meaningful robot-image filtering record therefore retains the footprint and intended feature geometry alongside the statistic. The original examples show why median filtering can suppress isolated extremes without being able to distinguish every outlier from a useful detail.

Sources checked October 23, 2026

OpenCV, Smoothing Images, version 4.12.0, median-blurring section:

https://docs.opencv.org/4.12.0/d4/d13/tutorial_py_filtering.html

SciPy, median_filter, documentation displayed as v1.18.0:

https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.median_filter.html

All windows and interpretations are hypothetical. No source arrays, figures, or executed software outputs are reproduced.

Illustration note: An accompanying generic robot vision scene is a concept illustration. It does not show measured image noise, a verified filter result, or validated feature detection.