-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_test.m
49 lines (40 loc) · 1010 Bytes
/
run_test.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
function run_test()
% Parameters
FILE = 'res/lena.tif';
RESOLUTIONS = 3;
TOGRAYSCALE = true;
UNBIASED = true;
% Read file
raw = imread(FILE);
if TOGRAYSCALE
raw = rgb2gray(raw);
end
% Transform
if ~UNBIASED
raw = raw-128;
end
wav = zeros(size(raw));
for i = 1:size(raw,3)
wav(:,:,i) = dwt2_exe(raw(:,:,i), RESOLUTIONS);
end
% Compare
imshowpair(raw, uint8(wav+128*(~UNBIASED)), 'montage');
% Cleanup
system('del input.bin');
system('del output.bin');
end
function output = dwt2_exe(input, res)
wbin_32('input.bin',input);
system(sprintf('dwt %i input.bin output.bin', res), '-echo');
output = rbin_32('output.bin', size(input));
end
function data = rbin_32(filename, n)
fid = fopen(filename, 'r');
data = fread(fid, n, 'int32');
fclose(fid);
end
function wbin_32(filename, data)
fid = fopen(filename, 'w');
fwrite(fid, data, 'int32');
fclose(fid);
end