forked from poisonwine/hw5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Butterworth.txt
123 lines (97 loc) · 2.19 KB
/
Butterworth.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
close all;
clear all;
f = imread('test4 copy.bmp');
f = mat2gray(f,[0 255]);
[M,N] = size(f);
P = 2*M;
Q = 2*N;
fc = zeros(M,N);
for x = 1:1:M
for y = 1:1:N
fc(x,y) = f(x,y) * (-1)^(x+y);
end
end
F = fft2(fc,P,Q);
H_1 = zeros(P,Q);
H_2 = zeros(P,Q);
for x = (-P/2):1:(P/2)-1
for y = (-Q/2):1:(Q/2)-1
D = (x^2 + y^2)^(0.5);
D_0 = 20;
H_1(x+(P/2)+1,y+(Q/2)+1) = 1/(1+(D/D_0)^2);
H_2(x+(P/2)+1,y+(Q/2)+1) = 1/(1+(D/D_0)^6);
end
end
H_3 = 1-H_1;
G_1 = H_1 .* F;
G_2 = H_2 .* F;
G_3 = H_3 .* F;
g_1 = real(ifft2(G_1));
g_1 = g_1(1:1:M,1:1:N);
g_2 = real(ifft2(G_2));
g_2 = g_2(1:1:M,1:1:N);
g_3 = real(ifft2(G_3));
g_3 = g_3(1:1:M,1:1:N);
for x = 1:1:M
for y = 1:1:N
g_1(x,y) = g_1(x,y) * (-1)^(x+y);
g_2(x,y) = g_2(x,y) * (-1)^(x+y);
g_3(x,y) = g_3(x,y) * (-1)^(x+y);
end
end
figure();
subplot(3,3,1);
imshow(f,[0 1]);
xlabel('a).Ôͼ');
subplot(3,3,2);
pw1=abs(F).^2/128;
k=0:length(F)-1;
w=2*pi*k/128;
plot(w/pi/2,pw1);
xlabel('b).Ôͼ¹¦ÂÊÆ×');
subplot(3,3,4);
h = mesh(1:20:P,1:20:Q,H_1(1:20:P,1:20:Q));
set(h,'EdgeColor','k');
axis([0 P 0 Q 0 1]);
xlabel('u');ylabel('v');
zlabel('c)Butterworth Lowpass (D_{0}=100,n=1)');
subplot(3,3,5);
imshow(g_1,[0 1]);
xlabel('d).½á¹û');
subplot(3,3,6);
pw2=abs(G_1).^2/128;
k=0:length(G_1)-1;
w1=2*pi*k/128;
plot(w1/pi/2,pw2);
xlabel('e).¹¦ÂÊÆ×');
subplot(3,3,7);
h = mesh(1:20:P,1:20:Q,H_2(1:20:P,1:20:Q));
set(h,'EdgeColor','k');
axis([0 P 0 Q 0 1]);
xlabel('u');ylabel('v');
zlabel('f).Butterworth Lowpass (D_{0}=100,n=3');
subplot(3,3,8);
imshow(g_2,[0 1]);
xlabel('g).½á¹û');
subplot(3,3,9);
pw3=abs(G_2).^2/128;
k=0:length(G_2)-1;
w2=2*pi*k/128;
plot(w2/pi/2,pw3);
xlabel('h).¹¦ÂÊÆ×');
figure();
subplot(1,3,1);
h = mesh(1:20:P,1:20:Q,H_3(1:20:P,1:20:Q));
set(h,'EdgeColor','k');
axis([0 P 0 Q 0 1]);
xlabel('u');ylabel('v');
zlabel('a)Butterworth Highpass (D_{0}=20,n=1)');
subplot(1,3,2);
imshow(g_3,[0 1]);
xlabel('b).½á¹û');
subplot(1,3,3);
pw4=abs(G_3).^2/128;
k=0:length(G_3)-1;
w3=2*pi*k/128;
plot(w3/pi/2,pw4);
xlabel('c).¹¦ÂÊÆ×');