从RGB图像MATLAB中去除噪声

时间:2019-01-08 10:05:09

标签: image matlab image-processing rgb

我正在尝试消除已经嘈杂的RGB图像中的噪点。我已经看到了一些示例,其中将盐和胡椒噪声添加到干净的图像中,然后作为示例再次删除,但是如果可以的话,我正在读取已经嘈杂的图像。由于某些原因,此代码未对原始图像进行任何更改。完全没有消除噪音。任何帮助将不胜感激。

train.jpg

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);

1 个答案:

答案 0 :(得分:3)

Ander Biguri commented一样,有许多方法可以减少图像中的噪点。在此处枚举所有这些超出了堆栈溢出的范围。但我建议一种方法:中值滤波。我建议这样做是因为您已经在做!

您正在将medfilt2应用于输入图像的每个通道。只需跳过后面的所有内容,仅保留最后一行:将通道重新合并为RGB图像。

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]);

rgbFixed = cat(3, redMF, greenMF, blueMF)

figure, imshow(rgbFixed);

由于图像非常嘈杂,您可能需要增加滤镜的尺寸。但是您会在噪点和模糊之间妥协。