Skip to content
All projects
EEL 5820 Image Processing2025

A switching median filter for salt and pepper noise

Written from scratch in MATLAB. A standard median filter blurs everything it touches; a switching one only intervenes where a pixel is actually corrupted.

MATLABNonlinear filteringImpulse noiseSNR

The question

Salt and pepper noise replaces isolated pixels with extreme values. A plain median filter removes them, but it also rewrites every uncorrupted pixel in the image, so you trade noise for a loss of detail everywhere.

Approach

A switching median filter that first detects whether a pixel is an impulse and only replaces it if so, leaving clean pixels untouched. Tested across noise densities from 10 to 40 percent on multiple images, and at 40 percent I applied the filter recursively for ten iterations to see how SNR evolves.

SNR against iteration when the switching filter is applied recursively at 40 percent noise. The gain saturates after four to five passes, so more iterations stop buying anything.
Original, corrupted and restored at 10 percent impulse noise.

Outcome

The switching filter preserves detail that the standard median destroys, and the gap widens as noise density rises. Recursive application at high density keeps improving SNR for several iterations before it plateaus.

What it taught me

Detect first, then act. A filter that treats every pixel identically is throwing away the information that some of them were fine, and that principle turns up again in every weighted objective I have written since.

More output

At 30 percent noise: corrupted input, standard median, switching median.
SNR against iteration when the switching filter is applied recursively at 40 percent noise.
SNR comparison across noise densities.