用matlab做给定图像对其加噪声模糊化,通过逆滤波对图像进行复原。
时间: 2023-10-03 16:08:10 浏览: 126
好的,具体步骤如下:
1. 加噪声和模糊化
首先,我们需要给原始图像加上噪声和模糊化。这里我们以高斯噪声和高斯模糊为例,代码如下:
```
I = imread('lena.png'); % 读取原始图像
h = fspecial('gaussian', [5 5], 2); % 生成高斯模糊核
Inoise = imnoise(I, 'gaussian', 0, 0.01); % 添加高斯噪声
Iblur = imfilter(Inoise, h, 'conv', 'same'); % 进行高斯模糊
```
2. 逆滤波复原
接下来,我们可以使用matlab中的`deconvwnr`函数进行逆滤波复原。这里我们选择最小二乘逆滤波方法,代码如下:
```
J = deconvwnr(Iblur, h, 0.01); % 进行最小二乘逆滤波
```
其中,`Iblur`为模糊图像,`h`为模糊核,`0.01`为正则化参数,可以根据实际情况进行调整。
3. 结果展示
最后,我们可以将原始图像、加噪声模糊图像和复原图像进行对比展示,代码如下:
```
subplot(1,3,1); imshow(I); title('原始图像');
subplot(1,3,2); imshow(Iblur); title('加噪声模糊图像');
subplot(1,3,3); imshow(J); title('复原图像');
```
运行后,就可以得到三张图像的对比展示了。
完整代码如下:
```
I = imread('lena.png'); % 读取原始图像
h = fspecial('gaussian', [5 5], 2); % 生成高斯模糊核
Inoise = imnoise(I, 'gaussian', 0, 0.01); % 添加高斯噪声
Iblur = imfilter(Inoise, h, 'conv', 'same'); % 进行高斯模糊
J = deconvwnr(Iblur, h, 0.01); % 进行最小二乘逆滤波
subplot(1,3,1); imshow(I); title('原始图像');
subplot(1,3,2); imshow(Iblur); title('加噪声模糊图像');
subplot(1,3,3); imshow(J); title('复原图像');
```
阅读全文
相关推荐















