一、实验目的:
1.掌握退化模型的建立方法。
2.掌握图像恢复的基本原理。
二、实验原理(略)
三、实验步骤(包括分析、代码和波形)
首先来看看这个实验的内容。实验主要内容如下:
(1)选择一幅清晰的灰度图像,对该图像进行模糊化处理并加入高斯噪声,然后分别采用逆滤波、维纳滤波和约束最小二乘方滤波对退化图像进行复原,比较各种图像的复原方法的复原效果。
(2)选择一幅清晰的灰度图像,对该图像进行仿射变换,如然后分别采用连接点选择、空间变换和灰度插值法对几何失真的图像进行复原,比较各种图像复原方法的复原效果。
下面是第(1)小题的代码。
代码一:
%% 仿真逆滤波、维纳滤波,约束最小二乘滤波
close all;
clear all;
clc;
% Display the original image.
I = imread('flower.jpg');
[d1,d2,d3] = size(I);
if(d3 > 1)
I = rgb2gray(I);
end
I = im2double(I);
[hei,wid,~] = size(I);
subplot(3,3,1),imshow(I);
title('Original Image ');
% Simulate a motion blur.
LEN = 50;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
subplot(3,3,2), imshow(blurred); title('Blurred Image');
% Simulate additive noise.
noise_mean = 0;
% noise_var = 0.00001;
noise_var = 0.0001;
blurred_noisy = imnoise(blurred, 'gaussian', ...
noise_mean, noise_var);
subplot(3,3,3), imshow(blurred_noisy)
title('Simulate Blur and Noise')
%% 使用自带的 deconvwnr 进行维纳滤波。 deconvreg进行约束最小二乘滤波
% deconvwnr 维纳滤波,如果没有参数NSPR,则为逆滤波
%自带 逆滤波 对已添加噪声图像 deconvwnr
deblurred4 = deconvwnr(blurred_noisy,PSF);
subplot(3,3,4), imshow(deblurred4); title('deconvwnr逆滤波 对 运动+噪声')
%自带 维纳滤波 对已添加噪声图像 deconvwnr
deblurred4 = deconvwnr(blurred_noisy,PSF,0.005); %0.005为噪声信号比
subplot(3,3,5), imshow(deblurred4); title('deconvwnr维纳滤波 对 运动+噪声')
%自带的 deconvreg 进行约束最小二乘滤波
subplot(3,3,6);
imshow(deconvreg(blurred_noisy, PSF,20)); %20 为噪声功率
title('deconvreg最小二乘滤波 对 运动+噪声');
%% 自写 逆滤波,约束最小二乘滤波
%自写 逆滤波 对未添加噪声图像
If =