簡體   English   中英

從RGB圖像MATLAB中去除噪聲

[英]Noise removal from rgb image MATLAB

我正在嘗試從已經嘈雜的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);

正如Ander Biguri所評論的那樣 ,有很多方法可以減少圖像中的噪點。 在此處枚舉所有這些超出了堆棧溢出的范圍。 但我建議一種方法:中值濾波。 我建議這樣做,因為您已經在做!

您正在將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);

由於圖像非常嘈雜,因此您可能需要增加濾鏡的大小。 但是您會在噪點和模糊之間妥協。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM