matlab去除高斯噪声代码
时间: 2023-07-09 15:29:44 浏览: 66
下面是一份Matlab代码,可以用来去除高斯噪声:
```matlab
% 读入图像
img = imread('noisy_image.png');
% 添加高斯噪声
noisy_img = imnoise(img, 'gaussian', 0, 0.01);
% 使用高斯滤波器去除噪声
filtered_img = imgaussfilt(noisy_img, 1);
% 显示原始图像、加噪图像和去噪图像
figure;
subplot(1,3,1); imshow(img); title('原始图像');
subplot(1,3,2); imshow(noisy_img); title('加噪图像');
subplot(1,3,3); imshow(filtered_img); title('去噪图像');
```
在这个例子中,我们首先读入一张图像,然后使用`imnoise`函数添加高斯噪声。接下来,我们使用`imgaussfilt`函数应用高斯滤波器去除噪声。最后,我们将原始图像、加噪图像和去噪图像显示在一个图像窗口中。
相关问题
matlab去除高斯噪声
可以使用matlab中的wiener2函数去除高斯噪声。wiener2函数是一种自适应滤波器,可以根据图像的局部特征自动调整滤波器的参数,从而更好地去除噪声。以下是一个简单的示例代码:
```matlab
% 读入图像并添加高斯噪声
I = imread('lena.png');
J = imnoise(I, 'gaussian', 0, 0.01);
% 使用wiener2函数去除噪声
K = wiener2(J, [5 5]);
% 显示结果
subplot(1,3,1), imshow(I), title('原始图像');
subplot(1,3,2), imshow(J), title('添加高斯噪声后的图像');
subplot(1,3,3), imshow(K), title('去除噪声后的图像');
```
matlab去除语音高斯噪声代码
下面是一份Matlab代码,可以用来去除语音高斯噪声:
```matlab
% 读入语音文件
[s, fs] = audioread('noisy_audio.wav');
% 添加高斯噪声
noisy_s = awgn(s, 10, 'measured');
% 使用Wiener滤波器去除噪声
filtered_s = wiener(noisy_s, [3 3]);
% 播放原始语音、加噪语音和去噪语音
sound(s, fs);
pause(length(s)/fs);
sound(noisy_s, fs);
pause(length(noisy_s)/fs);
sound(filtered_s, fs);
% 绘制原始语音、加噪语音和去噪语音的波形图
figure;
subplot(3,1,1); plot(s); title('原始语音');
subplot(3,1,2); plot(noisy_s); title('加噪语音');
subplot(3,1,3); plot(filtered_s); title('去噪语音');
```
在这个例子中,我们首先读入一个语音文件,然后使用`awgn`函数添加高斯噪声。接下来,我们使用`wiener`函数应用Wiener滤波器去除噪声。最后,我们播放原始语音、加噪语音和去噪语音,并绘制它们的波形图。注意,这里的`10`是信噪比,可以根据实际情况适当调整。