-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf_filter.asv
114 lines (93 loc) · 2.6 KB
/
sf_filter.asv
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
% spatial frequency (SF) filtering by SF-bandpass filter
% the SF filter is unselective to orientation (doughnut-shaped in the SF
% domain).
% parameters for SF filtering
ctrSF = 1/(40*2); % center SF
s = ctrSF/0.5; % sigma of Gaussian function
ctrSF = 0;
show_log_amp = false; % flag to show log SF spectrum instead of SF spectrum
min_amp_to_show = 10 ^ -10; % small positive value to replace 0 for log SF spectrum
filtered_magnified = zeros(size(filtered));
img1 = filtered(1, 1, :);
img1 = reshape(img1, imgDim);
% calculate the number of points for FFT (power of 2)
FFT_pts = 2 .^ ceil(log2(size(img1)));
if 1
for i = 1:%size(filtered, 1)
for index = 1:1
img = filtered(5, index, :);
img = reshape(img, imgDim);
%img(abs(img) > 0.2) = 0;
%img = blurDn(img, 1);
%img = imresize(img, imgDim);
[img_spektrum fx fy mfx mfy] = Myff2(img, FFT_pts(1), FFT_pts(2));
SF = sqrt(mfx .^ 2 + mfy .^ 2);
% SF-bandpass and orientation-unselective filter
filt = exp(-(SF - ctrSF) .^ 2 / (2 * s ^ 2));
img_spektrum_filtered = filt .* img_spektrum; % SF filtering
img_filtered = real(ifft2(ifftshift(img_spektrum_filtered))); % IFFT
img_filtered = img_filtered(1: size(img, 1), 1: size(img, 2));
filtered_magnified(i, index, :) = img_filtered(:);
end
end
end
if 0
img = filtered(5, 1, :);
img = reshape(img, imgDim);
%imagesc(img1)
caxis([-0.3 0.3]);
img(abs(img) > 0.2) = 0;
img = blurDn(img, 1);
img = imresize(img, imgDim);
end
[img_spektrum fx fy mfx mfy] = Myff2(img, FFT_pts(1), FFT_pts(2));
%return;
figure(1);
clf reset;
colormap gray;
% luminance image
subplot(2, 2, 1);
imagesc(img);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('original image');
xlabel('x');
ylabel('y');
img_spektrum = abs(img_spektrum);
if show_log_amp
img_spektrum(find(img_spektrum < min_amp_to_show)) = min_amp_to_show; % avoid taking log 0
img_spektrum = log10(img_spektrum);
end
% spectral amplitude
subplot(2, 2, 2);
imagesc(fx, fy, img_spektrum);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('amplitude spectrum');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
% filter in the SF domain
subplot(2, 2, 3);
imagesc(fx, fy, filt);
axis xy;
axis square;
set(gca, 'TickDir', 'out');
title('filter in the SF domain');
xlabel('fx (cyc/pix)');
ylabel('fy (cyc/pix)');
% filtered image
subplot(2, 2, 4);
imagesc(img_filtered);
colorbar;
axis square;
set(gca, 'TickDir', 'out');
title('filtered image');
xlabel('x');
ylabel('y');
return
cx=65;cy=65;ix=128;iy=128;r=5;
[x,y]=meshgrid(-(cx-1):(ix-cx),-(cy-1):(iy-cy));
c_mask=((x.^2+y.^2)<=r^2);
imagesc(c_mask)