Median filtering is another filtering technique similar to convolution in that we define a small window ( an nxn square smaller than our image) to move across it, and based on the pixels that fall within that window, we define a new pixel value in the filtered image. For example, here we have a window of size 3X3 that we will move across our image:
In median filtering, it’s a super simple algorithm. We set the new image pixel to be the median value of the pixels that fall within our yellow window. What does this mean for what the filter does? It means that if we have outlier pixels (extremely high or low values that will make the image look speckled, often called salt and pepper noise), we get rid of those nicely. For example. here is a before and after shot of an image with salt and pepper noise that has been median filtered:
This is a huge improvement! Hooray for simple algorithms that work well.