Main Content

使用预训练的神经网络去除彩色图像中的噪声

此示例说明如何使用去噪卷积神经网络从 RGB 图像中去除高斯噪声。

将一个彩色图像读入工作区中,并将数据转换为数据类型 double。显示原始彩色图像。

pristineRGB = imread("lighthouse.png");
pristineRGB = im2double(pristineRGB);
imshow(pristineRGB)
title("Pristine Image")

将方差为 0.01 的零均值高斯白噪声添加到图像中。imnoise 函数独立地向每个颜色通道添加噪声。显示含噪彩色图像。

noisyRGB = imnoise(pristineRGB,"gaussian",0,0.01);
imshow(noisyRGB)
title("Noisy Image")

预训练去噪卷积神经网络 DnCNN 对单通道图像进行运算。将含噪 RGB 图像分成三个单独的颜色通道。

[noisyR,noisyG,noisyB] = imsplit(noisyRGB);

加载预训练的 DnCNN 网络。

net = denoisingNetwork("dncnn");

使用 DnCNN 网络去除每个颜色通道的噪声。

denoisedR = denoiseImage(noisyR,net);
denoisedG = denoiseImage(noisyG,net);
denoisedB = denoiseImage(noisyB,net);

合并去噪的颜色通道以形成去噪后的 RGB 图像。显示去噪后的彩色图像。

denoisedRGB = cat(3,denoisedR,denoisedG,denoisedB);
imshow(denoisedRGB)
title("Denoised Image")

计算含噪图像和去噪图像的峰值信噪比 (PSNR)。PSNR 越大,噪声相对信号越小,说明图像质量越高。

noisyPSNR = psnr(noisyRGB,pristineRGB);
fprintf("\n The PSNR value of the noisy image is %0.4f.",noisyPSNR);
 The PSNR value of the noisy image is 20.6395.
denoisedPSNR = psnr(denoisedRGB,pristineRGB);
fprintf("\n The PSNR value of the denoised image is %0.4f.",denoisedPSNR);
 The PSNR value of the denoised image is 29.6857.

计算含噪图像和去噪图像的结构相似性 (SSIM) 指数。SSIM 指数接近 1 表示与参考图像相当一致,图像质量更高。

noisySSIM = ssim(noisyRGB,pristineRGB);
fprintf("\n The SSIM value of the noisy image is %0.4f.",noisySSIM);
 The SSIM value of the noisy image is 0.7393.
denoisedSSIM = ssim(denoisedRGB,pristineRGB);
fprintf("\n The SSIM value of the denoised image is %0.4f.",denoisedSSIM);
 The SSIM value of the denoised image is 0.9507.

实际上,图像颜色通道经常具有相关噪声。为了去除相关的图像噪声,首先将 RGB 图像转换为具有亮度通道的颜色空间,例如 L*a*b* 颜色空间。仅去除亮度通道上的噪声,然后将去噪图像转换回 RGB 颜色空间。

另请参阅

| | | | | |

相关主题