I am trying to remove noise from an already noisy RGB image. I've seen some examples where salt & pepper noise is added to a clean image and then removed again as an example, but I'm reading in an already noisy image if that makes sense. This code isn't making any changes to the original image for some reason. No noise has been removed at all. Any help would be appreciated.
p = imread("train.jpg");
redChannel = p(:, :, 1);
greenChannel = p(:, :, 2);
blueChannel = p(:, :, 3);
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
figure, imshow(rgbFixed);
noiseImage
condition, you may see a larger change. Try setting it to completely true (i.e.redChannel >= 0
), then you'll see the overall effect of themedfilt2
function, and decide where it's even going to be effective. – Wolfie