MATLAB Answers

To apply a median filter on a coloured image, why do I have to use 'medfilt2' on each channel separately rather than use 'medfilt3'?

5 views (last 30 days)
Salad Box
Salad Box on 30 Oct 2019
Edited: Salad Box on 30 Oct 2019
Hi,
I have a color image and would like to use a 9 x 9 median filter.
Method A - using 'medfilt2' on each channel separately with 'padopt' = 'symmetric'.
fn = 'exuberant.png';
[I,map] = imread(fn);
I = ind2rgb(I, map);
I = I * 255;
figure
subplot(1,2,1)
imshow(uint8(I))
R = I(:,:,1);
G = I(:,:,2);
B = I(:,:,3);
a = 9;
medfilimg(:,:,1) = medfilt2(R,[a,a],'symmetric');
medfilimg(:,:,2) = medfilt2(G,[a,a],'symmetric');
medfilimg(:,:,3) = medfilt2(B,[a,a],'symmetric');
subplot(1,2,2)
imshow(uint8(medfilimg))
I get the below, with left image the 'original image' and right image the 'median filter' image. The colors look fine comparing the right image to the left image.
Method B - using 'medfilt3' on the whole image.
fn = 'exuberant.png';
[I,map] = imread(fn);
I = ind2rgb(I, map);
I = I * 255;
figure
subplot(1,2,1)
imshow(uint8(I))
K = medfilt3(I);
subplot(1,2,2)
imshow(uint8(K))
I get the below, where left is still the original image, and the right is the median filter image using medfilt3. Noticed that the texts in the image changed from red to yellow/orange. The bird's feet changed from red to orange which doesn't appear right at all. WHY?

  0 Comments

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by