Clear Filters
Clear Filters

How to apply Median FIlter To a color image with out using 'rgb2gray' ? Program please.

2 views (last 30 days)
How to add noise and eliminate it using filters (in this case salt and pepper and Median filters respectively) by using without the conversion to gray scale.?

Accepted Answer

Guillaume
Guillaume on 23 Sep 2017
Just loop over the colour channels:
processedimage = zeros(size(yourimage), 'like', yourimage));
for channel = 1:3
processedimage(:, :, channel) = somefunction(yourimage(:, :, channel));
end

More Answers (1)

Image Analyst
Image Analyst on 23 Sep 2017
See my attached demos for applying salt and pepper noise to color and gray scale images and then removing it. It should do exactly what you want in a fancy demo. Adapt it as needed.
  3 Comments
Image Analyst
Image Analyst on 25 Apr 2020
Well I guess you could - if you were willing to accept more of a color change. The different color channels can have drastically different values. Imagine you were looking at a tomato with values of (200, 40, 20) with salt and pepper noise. Consider if the 3-D 3x3x3 filter window was processing the green channel so it also brings in values of the red and blue channels into the moving window. So if we ignore values of 0 and 255 and take the median value of what's left, you might be left with a value of 200 for the green instead of 40, depending on how much noise was in each channel. Or it might get a value of 20 if the blue channel was the channel with the least noise. So you're assigning colors from a different color channel to it, which would dramatically change the color if the color is not a neutral shade. Doing it one color channel at a time would avoid that. I suppose the red and blue channels might be ok with the 3-D median IF the window shrunk as it got to the edge of the array, meaning you basically ignore values that are off the edge of the image. (I'm not sure how the median filter deals with edge effects - the common ways are to shrink the window or assume values outside the array are zero). But in that case (shrinking window), it's reverted to a 2-D filter window on one color channel alone. So, bottom line, I think doing it channel-by-channel will give more accurate colors.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!