I wrote a median filter hw7_b.m that handles the boundary pixels using Neumann boundary conditions. First, I applied it to the original gray image cameraman.tif.
Original image |
3x3 Median Filter |
5x5 Median Filter |
9x9 Median Filter |
I was surprised that the 9x9 median filter blurred the image so much. To check my filter, I ran the built-in MATALB function medfilt2 (ONLY AS A CHECK!!). The MATLAB 9x9 median filter also blurs the original image to the same extent. Apparently, MATLAB handles the corners differently. The MATLAB version of the 9x9 median filter is shown below.

Next, I ran my median filter on the image with salt and pepper noise. I loaded the image in
matrix A and added noise to the
image using the command:
imnoise(A, 'salt & pepper', 0.03)
The 3x3 filter cleans up the noise well with little blurring. But the 5x5 and 9x9 filters
result in severe blurring.
Salt & Pepper Noise Added |
3x3 Median Filter |
5x5 Median Filter |
9x9 Median Filter |
Finally, I created an image with Gaussian noise of mean 0 and variance 0.01 by running:
imnoise(A,'gaussian',0,0.01)
Again, the median filter cleans up the noise, but it appears the filter had a harder time
with Gaussian noise than it did with the salt & pepper noise. In particular, we can see that
the sky is clouded up.
Again, the larger the window
size, the more blurring we see.
Gaussian Noise Added |
3x3 Median Filter |
5x5 Median Filter |
9x9 Median Filter |