Why can a median filter remove a single salt pixel?

MedianFilter orders the values in a window and uses the middle value as output.

Pixel experiment and interpretation

Eight cells at 20 outweigh one at 250 in a nine-cell window. A genuine narrow bright feature can disappear for the same reason.

from PIL import Image, ImageFilter

im=Image.new('L',(3,3),20)
im.putpixel((1,1),250)
im.filter(ImageFilter.MedianFilter(3)).getpixel((1,1))

Result 20

中文

中值滤波为什么适合清除孤立盐点?

MedianFilter 对窗口内像素排序,选中间位置的值作为输出。

像素实验与适用边界

九格里八格为 20,一格为 250,中位数仍是 20。很细的真实亮线也可能被它抹去。

from PIL import Image, ImageFilter

im=Image.new('L',(3,3),20)
im.putpixel((1,1),250)
im.filter(ImageFilter.MedianFilter(3)).getpixel((1,1))

结果 20

References / 参考来源

Keep reading / 继续阅读