For each pixel in the image, the median filter does three things:
- Collects all pixel values within the neighborhood (a square or circular window)
- Sorts these values in ascending order
- Replaces the center pixel with the median, the middle value
The median is the value that minimizes the sum of absolute differences to all other values in the set. That makes it the optimal estimate under impulsive noise.
Two more properties follow:
- Idempotent for binary images: applying the median filter twice to a binary image gives the same result as applying it once
- Corner rounding: sharp corners (structures smaller than the kernel) get rounded, much as in morphological opening