-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCT_script.m
77 lines (56 loc) · 1.61 KB
/
DCT_script.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
%% DCT Compress all
step = 1000;
N_ks = 30;
errors = zeros(1, N_ks);
for i= 1:N_ks
% Coefficients
k = i*step;
% Compress and decompress
I_comp_all = im_compress(I, k, 'all');
I_rec_all = im_uncompress(I_comp_all);
% Save image
fname = strcat(img_name, '_', 'DCT_compress_all', '_', int2str(k));
imwrite(uint8(I_rec_all), filename(image_dir, fname, 'tiff'), 'tiff');
% Save relative L2 error
errors(i) = rel_error(I, I_rec_all);
end
%% Plot the results
h = figure;
plot(1:step:N_ks*step, errors);
% Save figure
fname = strcat(img_name, '_', 'DCT_compress_all');
print(h, '-depsc2', '-tiff', filename(figures_dir, fname, 'eps'));
% Plot to combined plot
h = figure(1);
hold all;
plot(1:step:N_ks*step, errors);
hold off;
labels = strvcat(labels, 'DCT All');
%% DCT Compress Blocks
N_ks = 30;
errors = zeros(1, N_ks);
for i= 1:N_ks
% Coefficients
k = i;
% Compress and decompress
I_comp_all = im_compress(I, k, 'block');
I_rec_all = im_uncompress(I_comp_all);
% Save Image
% Save image
fname = strcat(img_name, '_', 'DCT_compress_block', '_', int2str(k));
imwrite(uint8(I_rec_all), filename(image_dir, fname, 'tiff'), 'tiff');
% Save relative L2 error
errors(i) = rel_error(I, I_rec_all);
end
%% Plot the results
h = figure;
plot(1:N_ks, errors);
% Save figure
fname = strcat(img_name, '_', 'DCT_compress_blocks');
print(h, '-depsc2', '-tiff', filename(figures_dir, fname, 'eps'))
% Plot to combined plot
% h = figure(1);
% hold on;
% plot(1:step:N_ks*step, errors);
% hold off;
% labels = strvcat(labels, 'DCT Block');