Function Code
function aOut = WienerFilter(aIn,k,a,b,T)%这仅仅是一个维纳滤波器%k(默认为0.001)--->加到Huv2所有项上的一个规定常数,根据情况选择大小%a(默认为0.1)--->x方向最大移动量(运动模糊图片)%b(默认为0.1)--->y方向最大移动量(运动模糊图片)%T(默认为1)--->移动到最大所需的时间%aOut--->输出图像%输入参数接收及预定义if nargin == 1k = 0.005;a = 0.1;b = 0.1;T = 1;elseif nargin == 2a = 0.1;b = 0.1;T = 1;elseif nargin == 3b = 0.1;T = 1;elseif nargin == 4T = 1;end%读入退化图像并进行图像预处理a1 = double(aIn);% figure,imshow(a1,[])%-------------图像---------------%生成退化图像频谱图Guv(禁止填充)[ra,ca] = size(a1);[X,Y] = meshgrid(0:ca-1,0:ra-1);Guv = fft2(a1.*(-1).^(X+Y));% figure,imshow(log(abs(Guv)+1),[])%-------------图像---------------%生成退化传递函数HuvuaPvb = (Y-floor(ra/2)).*a+(X-floor(ca/2)).*b+eps;Huv = T.*sin(pi.*uaPvb).*exp(-1j.*pi.*uaPvb)./(pi.*uaPvb);Huv2 = abs(Huv).*abs(Huv);%估计函数公式Fuv = (Huv2./(Huv2+k)./Huv).*Guv;%将得到的估计函数进行逆傅里叶变换FxyShift = ifft2(Fuv);Fxy = real(FxyShift).*(-1).^(X+Y);% figure,imshow(Fxy,[])%-------------图像---------------aOut = Fxy;end
Demo Code
clearclose allaIn3 = imread("paper3.jpg");aIn2 = imread("paper2.jpg");aIn1 = imread("paper1.jpg");a3 = double(aIn3);a2 = double(aIn2);a1 = double(aIn1);k3 = 0.001;k2 = 0.0001;k1 = 0.00001;a = 0.1;b = 0.1;T = 1;aOut3 = WienerFilter(a3,k3,a,b,T);aOut2 = WienerFilter(a2,k2,a,b,T);aOut1 = WienerFilter(a1,k1,a,b,T);figuresubplot(231),imshow(a3,[]),title("严重噪声")subplot(232),imshow(a2,[]),title("中度噪声")subplot(233),imshow(a1,[]),title("轻微噪声")subplot(234),imshow(aOut3,[]),title("k = "+string(k3))subplot(235),imshow(aOut2,[]),title("k = "+string(k2))subplot(236),imshow(aOut1,[]),title("k = "+string(k1))
Figure
说明:由于屏幕大小限制,噪声图像缩小后更加模糊
1、k3 = 0.05;k2 = 0.005;k1 = 0.001;
2、k3 = 0.01;k2 = 0.01;k1 = 0.008;
3、k3 = 0.1;k2 = 0.1;k1 = 0.1;
4、k3 = 0.001;k2 = 0.0001;k1 = 0.00001;
Conclusion
k值的过于增大,噪声明显被抑制,但是图像会变得更加模糊!
k值过于减小,会加强噪声,使噪声放大!
需要多次实验才能找到适合的k值!