Lulumoy Studio

Math guide

Median blur

Replaces each pixel by the median of its window. It is non-linear: it removes impulse ("salt and pepper") noise while preserving edges better than an average.

I′(x,y)=med{I(x+i,y+j):|i|,|j|≤r}
The median is the middle value after sorting the k² values. In colour images it is computed per channel.

Parameters

ParameterMeaning
Kernel size (odd)k, odd and at least 3. OpenCV only allows k > 5 on 8-bit images.

References

  1. OpenCV 4.x documentation — Image Filtering (GaussianBlur, blur, medianBlur, bilateralFilter, morphologyEx). docs.opencv.org/4.x/d4/d86/group__imgproc__filter.html
  2. T. S. Huang, G. J. Yang, G. Y. Tang. "A fast two-dimensional median filtering algorithm." IEEE Transactions on Acoustics, Speech, and Signal Processing, 27(1):13–18, 1979.
  3. S. Perreault, P. Hébert. "Median filtering in constant time." IEEE Transactions on Image Processing, 16(9):2389–2394, 2007.