-
Notifications
You must be signed in to change notification settings - Fork 0
/
one_3_grayscale.m
54 lines (43 loc) · 1.81 KB
/
one_3_grayscale.m
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
function one_3_grayscale() %ίδια σχόλια με την one_3_rgb.m, παρακαλώ δείτε εκεί
files = dir('*.png');
for i = 1:numel(files)
figure();
filename = files(i).name;
ft = find_spectrum(filename);
reconstruct(ft, 4, 8);
end
end
function fourier_image = find_spectrum(im)
image = imread(im);
image = rgb2gray(image);
show_image(image, "Grayscale image", 1, false);
fourier_image = fftshift(fft2(image));
log_trans = log(1 + abs(fourier_image));
show_image(log_trans, "Spectrum", 1, true);
end
function reconstruct(ft, k, j)
N = size(ft, 1);
M = size(ft, 2);
new_fm = zeros(N, M);
new_fm(round(N/2 - N/(2*k)):round(N/2 + N/(2*k)), round(M/2 - M/(2*k)): round(M/2 + M/(2*k))) = ft(round(N/2 - N/(2*k)):round(N/2 + N/(2*k)), round(M/2 - M/(2*k)):round(M/2 + M/(2*k)));
show_image(log(1 + abs(new_fm)), "Logarithmic (N/" + k + ") transform of the image", 2, true);
new_fm2 = zeros(N, M);
new_fm2(round(N/2 - N/(2*j)):round(N/2 + N/(2*j)), round(M/2 - M/(2*j)): round(M/2 + M/(2*j))) = ft(round(N/2 - N/(2*j)):round(N/2 + N/(2*j)), round(M/2 - M/(2*j)):round(M/2 + M/(2*j)));
show_image(log(1 + abs(new_fm2)), "Logarithmic (N/" + j + ") transform of the image", 3, true);
recon = abs(ifft2(new_fm));
recon2 = abs(ifft2(new_fm2));
show_image(recon, "Reconstructed image after the N/" + k + " FT", 2, false);
show_image(recon2, "Reconstructed image after the N/" + j + " FT", 3, false);
end
function show_image(im, tl, r, isFourier)
if isFourier == false
subplot(2,3,r);
imshow(im, []);
title(tl);
else
subplot(2,3,3+r);
imshow(im, []);
title(tl);
colorbar
end
end