matlab给图像添加多种噪声
时间: 2023-10-20 13:17:17 浏览: 31
1. 加高斯噪声:
```matlab
I = imread('lena.png');
J = imnoise(I,'gaussian',0,0.01);
imshow(J);
```
其中,`0.01`是噪声方差,可以根据需要自行调整。
2. 加椒盐噪声:
```matlab
I = imread('lena.png');
J = imnoise(I,'salt & pepper',0.05);
imshow(J);
```
其中,`0.05`是噪声密度,可以根据需要自行调整。
3. 加泊松噪声:
```matlab
I = imread('lena.png');
J = imnoise(I,'poisson');
imshow(J);
```
4. 加乘性噪声:
```matlab
I = imread('lena.png');
J = imnoise(I,'speckle',0.04);
imshow(J);
```
其中,`0.04`是噪声方差,可以根据需要自行调整。
相关问题
基于matlab的彩色图像添加噪声实验
好的,我可以帮你讲解一下基于 Matlab 的彩色图像添加噪声实验步骤。具体实现如下:
1. 读入彩色图像:使用 `imread` 函数读入需要添加噪声的彩色图像,例如:
```
img = imread('color_image.bmp');
```
2. 分离通道:将彩色图像的三个通道(红、绿、蓝)分离出来,分别处理。例如:
```
red_channel = img(:,:,1);
green_channel = img(:,:,2);
blue_channel = img(:,:,3);
```
3. 添加噪声:使用 `imnoise` 函数为每个通道添加噪声。这个函数可以添加多种类型的噪声,包括高斯噪声、椒盐噪声、泊松噪声等。例如:
```
noisy_red_channel = imnoise(red_channel, 'gaussian', 0, 0.01);
noisy_green_channel = imnoise(green_channel, 'salt & pepper', 0.05);
noisy_blue_channel = imnoise(blue_channel, 'poisson');
```
这里分别为红、绿、蓝三个通道添加了高斯噪声、椒盐噪声和泊松噪声。
4. 合并通道:将处理后的三个通道合并成一张图像。例如:
```
noisy_img = cat(3, noisy_red_channel, noisy_green_channel, noisy_blue_channel);
```
5. 显示图像:使用 `imshow` 函数显示原始图像和添加噪声后的图像。例如:
```
subplot(1, 2, 1);
imshow(img);
title('Original Image');
subplot(1, 2, 2);
imshow(noisy_img);
title('Noisy Image');
```
这里使用了 `subplot` 函数将两张图像显示在同一个窗口中。
这样,你就可以在 Matlab 中实现彩色图像添加噪声的实验了。希望对你有所帮助!
在matlab中给图像加椒盐噪声
可以使用 `imnoise` 函数在 MATLAB 中给图像添加椒盐噪声。这个函数可以添加多种类型的噪声,包括高斯噪声、椒盐噪声等。下面是一个简单的例子,演示如何在 MATLAB 中添加椒盐噪声:
```matlab
% 读入图像
img = imread('lena.png');
% 添加椒盐噪声
noisy_img = imnoise(img, 'salt & pepper', 0.05);
% 显示原图和添加噪声后的图像
figure;
subplot(1,2,1); imshow(img); title('原图');
subplot(1,2,2); imshow(noisy_img); title('添加椒盐噪声后的图像');
```
在上面的代码中,`imnoise` 函数的第二个参数指定添加的噪声类型为椒盐噪声,第三个参数指定噪声比例为 0.05,即在图像中添加 5% 的椒盐噪声。添加噪声后的图像存储在 `noisy_img` 变量中,可以使用 `imshow` 函数显示原图和添加噪声后的图像。