The median filter is also a neighborhood filter resembling the averaging filter, but instead of calculating the average value of the neighborhood it processes, it finds their median value and assigns it to the central pixel. This difference causes the process of median filtering to be less sensitive to outliers. Since the salt & pepper noise is essentially a collection of randomly placed outlier (black or white) pixels, the median filter should work better on this type of noise. Let's see if this is true, using the function medfit2
.