参考资料:
陷波滤波器—matlab实现
http://blog.sina.com.cn/s/blog_ebd29d830102wdzw.html
图像复原之约束最小二乘方滤波
https://blog.csdn.net/yi_tech_blog/article/details/54605146
图像去模糊(约束最小二乘方滤波)
https://blog.csdn.net/bluecol/article/details/47359421
约束最小二乘方滤波去模糊
https://blog.csdn.net/yuyangyg/article/details/78681007
图像去模糊(维纳滤波)
https://blog.csdn.net/bluecol/article/details/46242355
%% 仿真逆滤波、维纳滤波,约束最小二乘滤波
close all;
clear all;
clc;
% Display the original image.
I = imread('Lena512.png');
[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 = fft2(blurred);
Pf = psf2otf(PSF,[hei,wid]);
deblurred = ifft2(If./Pf);
subplot(3,3,7), imshow(deblurred); title('逆滤波 对 仅运动')
%自写 逆滤波 对已经添加噪声图像
If2 = fft2(blurred_noisy);
deblurred2 = ifft2(If2./Pf);
subplot(3,3,8), imshow(deblurred2); title('逆滤波 对 运动+噪声')
% Try restoration using Home Made Constrained Least Squares Filtering.
% 自写约束最小二乘滤波
p = [0 -1 0;-1 4 -1;0 -1 0];
P = psf2otf(p,[hei,wid]);
gama = 0.001;
If = fft2(blurred_noisy);
numerator = conj(Pf);
denominator = Pf.^2 + gama*(P.^2);
deblurred2 = ifft2( numerator.*If./ denominator );
subplot(3,3,9), imshow(deblurred2)
title('约束最小二乘滤波');