The first recipe of this chapter introduced the concept of linear filters. Nonlinear filters also exist and can be used advantageously in image processing. One such filter is the median filter that we present in this recipe.
Since median filters are particularly useful in order to combat salt-and-pepper noise (or salt-only noise, in our case), we will use the image we created in the first recipe of Chapter 2, Manipulating the Pixels, and that is reproduced here:
Let's get started with the steps.