Median Filter
A Median filter is a non-linear filter. It sorts the pixels covered by the window and sorts them in ascending order then returns the median of them.
For Median filter in the 2D image. We use medfit(). It takes 2 parameters. First is the noisy image, second is the window size used. By default window size is [3 3].
Syntax:
medfilt2( noisy_image, window_size);
To display the 2 images side by side together we use imshowpair().imshowpair( ) is an overloaded function, it has many signatures in Matlab. The montage keyword says that 2 images have to be displayed side by side.
Syntax:
imshowpair(img1, img2, ‘montage’);
Example:
Matlab
% MATLaB code for Median filter % read the image. k=imread( "einstein_colored.png" ); % Convert into grayscale image. k=rgb2gray(k); % Create the image corrupted with gaussian noise. gaussian_noise=imnoise(k, 'gaussian' ,0,0.01); % Create the image corrupted with poisson noise. poisson_noise=imnoise(k, 'poisson' ); % Create the image corrupted with salt % & pepper noise. salt_noise=imnoise(k, 'salt & pepper' , 0.05); % Create the image corrupted % with speckle noise. speckle_noise=imnoise(k, 'speckle' , 0.05); % Get the denoised image from noised % image of: gaussian_noise gaussian_denoised=medfilt2(gaussian_noise, [5 5]); % Get the denoised image from % noised image of:poisson_noise poisson_denoised=medfilt2(poisson_noise, [5 5]); % Get the denoised image from noised % image of: salt_noise salt_denoised=medfilt2(salt_noise, [5 5]); % Get the denoised image from noised % image of: speckle_noise speckle_denoised=medfilt2(speckle_noise, [5 5]); % Display the noised and denoised image % side by side for Gaussian noise. imshowpair(gaussian_noise, gaussian_denoised, 'montage' ); % Display the noised and denoised image %side by side for poisson_noise. imshowpair(poisson_noise, poisson_denoised, 'montage' ); % Display the noised and denoised % image side by side for salt_noise. imshowpair(salt_noise, salt_denoised, 'montage' ); % Display the noised and denoised image % side by side for speckle_noise. imshowpair(speckle_noise, speckle_denoised, 'montage' ); |
Output:
The median filter removes the salt and pepper noise completely but introduces blurriness to the image. It does not perform well with other noises.
What are different types of denoising filters in MATLAB?
Digital images are prone to various types of noise that make the quality of the images worst. Image noise is a random variation of brightness or color information in the captured image. Noise is basically the degradation in image signal caused by external sources such as cameras. Images containing multiplicative noise have the characteristic that the brighter the area the noisier it. We shall discuss various denoising filters in order to remove these noises from the digital images.
Types of filters discussed in this article are listed as:
- Mean filter
- Median filter
- Gaussian filter
- Wiener filter
Contact Us