forked from zhaihongjia/hw6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TASK3.txt
73 lines (67 loc) · 1.55 KB
/
TASK3.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
close all
clear
clc
I=imread('lena.bmp');
figure(1);
subplot(1,3,1)
imshow(I);
title('lena.bmp原始图像');
H=fspecial( 'motion' ,50,45);
I1=imfilter(I,H, 'circular' , 'conv' );
subplot(1,3,2)
imshow(I1);
title( ' 运动模糊后的 lena.bmp( 角度为 45 度)' );
imwrite(I1, 'lena 运动模糊(调用 matlab 中的函数) .bmp' );
I2=imnoise(I1, 'gaussian' ,0,0.01);
subplot(1,3,3)
imshow(I2);
title( ' 加噪并模糊的 lena.bmp' );
imwrite(I2, 'lena 运动模糊 +高斯噪声(调用 matlab 中的函数 0.bmp' );
figure(2)
f1=wnlb(I2,0.01);
subplot(2,2,1)
imshow(f1);
title('维纳滤波k=0.01');
f2=wnlb(I2,0.05);
subplot(2,2,2)
imshow(f2);
title('维纳滤波k=0.05');
f3=wnlb(I2,0.1);
subplot(2,2,3)
imshow(f3);
title('维纳滤波k=0.1');
f4=wnlb(I2,0.5);
subplot(2,2,4)
imshow(f4);
title('维纳滤波k=0.5');
%%约束最小二乘:
h=fspecial('motion',50,45);
I1=imfilter(I,h,'circular','conv');
I2=imnoise(I1,'gaussian',0,0.01);
figure(3);
subplot(1,2,1)
imshow(I2);
title('lena运动模糊+高斯噪声');
V=0.0001;
NoisePower=V*prod(size(I));
[g,LAGRA]=deconvreg(I1,h,NoisePower);
subplot(1,2,2)
imshow(g);
title('约束最小二乘滤波');
function f=wnlb(I,K)
g=double(I);
G=fft2(g);
G=fftshift(G);
[M,N]=size(G);
a=0.1;b=0.1;T=1;
for u=1:M
for v=1:N
H(u,v)=(T/(pi*(u*a+v*b)))*sin(pi*(u*a+v*b))*exp(-sqrt(-1)*pi*(u*a+v*b));
F(u,v)=1/H(u,v)*(abs(H(u,v)))^2/((abs(H(u,v)))^2+K)*G(u,v);
end
end
F=ifftshift(F);
f=ifft2(F);
f=256.*f./max(max(f));
f=uint8(real(f));
end