用MATLAB实现对图像加椒盐噪声、高斯噪声以及加噪后的均值滤波、高斯滤波、中值滤波处理的代码
时间: 2023-07-10 11:20:56 浏览: 224
以下是一个示例代码,其中包括了对图像加椒盐噪声、高斯噪声以及加噪后的均值滤波、高斯滤波、中值滤波处理。代码中使用了Matlab自带的一些函数。
```matlab
% 读取原图像
img = imread('lena.png');
% 显示原图像
subplot(2, 3, 1);
imshow(img);
title('Original Image');
% 加椒盐噪声
img_salt_and_pepper = imnoise(img, 'salt & pepper', 0.02);
% 显示加噪后的图像
subplot(2, 3, 2);
imshow(img_salt_and_pepper);
title('Salt & Pepper Noise');
% 加高斯噪声
img_gaussian = imnoise(img, 'gaussian', 0, 0.01);
% 显示加噪后的图像
subplot(2, 3, 3);
imshow(img_gaussian);
title('Gaussian Noise');
% 均值滤波
img_mean = imfilter(img_salt_and_pepper, fspecial('average', [3 3]));
% 显示均值滤波后的图像
subplot(2, 3, 4);
imshow(img_mean);
title('Mean Filter');
% 高斯滤波
img_gauss = imgaussfilt(img_salt_and_pepper, 1.5);
% 显示高斯滤波后的图像
subplot(2, 3, 5);
imshow(img_gauss);
title('Gaussian Filter');
% 中值滤波
img_median = medfilt2(img_salt_and_pepper, [3 3]);
% 显示中值滤波后的图像
subplot(2, 3, 6);
imshow(img_median);
title('Median Filter');
```
其中,imread函数用于读取原图像,imnoise函数用于加噪,imfilter、imgaussfilt、medfilt2分别用于均值滤波、高斯滤波、中值滤波。在使用时可以根据需要调整参数。
阅读全文
相关推荐
















