不添加噪声,使用维纳滤波器对运动模糊的图像进行恢复MATLAB 代码
时间: 2023-05-28 21:08:04 浏览: 64
% 读取运动模糊图像
img = im2double(imread('motion_blur_image.jpg'));
% 定义运动方向和长度
theta = 45; % 运动方向
len = 15; % 运动长度
% 生成点扩散函数(PSF)
psf = fspecial('motion', len, theta);
% 对图像进行卷积
blurred = imfilter(img, psf, 'conv', 'circular');
% 恢复图像
restored = deconvwnr(blurred, psf);
% 显示图像
figure;
subplot(1,2,1); imshow(blurred); title('运动模糊图像');
subplot(1,2,2); imshow(restored); title('恢复图像');
% 评估恢复质量
psnr_val = psnr(restored, img);
fprintf('PSNR值为: %.2f dB\n', psnr_val);
相关问题
已知含有噪声,使用维纳滤波器对运动模糊的图像进行恢复MATLAB 代码
以下是使用维纳滤波器对运动模糊图像进行恢复的MATLAB代码:
```matlab
% 读入运动模糊图像
img = imread('motion_blur_image.png');
% 添加高斯噪声
noisy_img = imnoise(img, 'gaussian', 0, 0.01);
% 设置运动模糊参数
len = 21; % 运动模糊核长度
theta = 11; % 运动模糊核角度
motion_psf = fspecial('motion', len, theta); % 生成运动模糊核
% 对图像进行运动模糊
blurred_img = imfilter(noisy_img, motion_psf, 'conv', 'circular');
% 使用维纳滤波器进行图像恢复
estimated_nsr = 0.001; % 估计噪声方差
wnr_img = deconvwnr(blurred_img, motion_psf, estimated_nsr);
% 显示原图像、含噪声图像和恢复图像
subplot(1,3,1); imshow(img); title('Original Image');
subplot(1,3,2); imshow(noisy_img); title('Noisy Image');
subplot(1,3,3); imshow(wnr_img); title('Restored Image');
```
在上述代码中,我们首先读入运动模糊图像,并添加高斯噪声。然后,我们设置运动模糊参数并在图像上应用运动模糊。接下来,我们使用`deconvwnr`函数对模糊图像进行维纳滤波器恢复,并估计噪声方差。最后,我们使用`subplot`函数显示原始图像、含噪声图像和恢复图像。
给出用维纳滤波法实现对运动模糊图像复原的matlab代码
好的,以下是使用维纳滤波法实现对运动模糊图像复原的 MATLAB 代码:
```matlab
% 读入运动模糊图像
img = imread('blurry_image.png');
% 定义运动方向和长度
theta = 30; % 运动的方向,单位:度
len = 15; % 运动的长度
% 生成点扩散函数
PSF = fspecial('motion', len, theta);
% 对图像进行运动模糊处理
blurred = imfilter(img, PSF, 'conv', 'circular');
% 计算频率响应函数
[H, W] = freqspace(size(PSF));
[U, V] = meshgrid(W, H);
D = len * sqrt(U.^2 + V.^2);
F = exp(-pi * D.^2);
% 计算维纳滤波器
K = F ./ (F + 1 / SNR);
% 对模糊图像进行维纳滤波
restored = deconvwnr(blurred, PSF, K);
% 显示原始图像、模糊图像和复原图像
figure;
subplot(1, 3, 1); imshow(img); title('原始图像');
subplot(1, 3, 2); imshow(blurred); title('模糊图像');
subplot(1, 3, 3); imshow(restored); title('复原图像');
```
其中,`SNR` 变量表示信噪比,越大表示信号越强,噪声越小。你可以根据实际情况调整这个值。
希望这个代码能够帮到你!