-
Notifications
You must be signed in to change notification settings - Fork 0
/
dec_huffman_new.m
81 lines (67 loc) · 1.77 KB
/
dec_huffman_new.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
78
79
80
81
%--------------------------------------------------------------
%
%
%
% %%% %%% %%% %%%%%%%%
% %%% %%% %%% %%%%%%%%%
% %%% %%% %%% %%%%
% %%% %%% %%% %%%
% %%% %%% %%% %%%
% %%% %%% %%% %%%
% %%% %%% %%% %%%
% %%% %%%%%% %%%
% %%% %%%%% %%%
% %%% %%%% %%%%%%%%%%%%
% %%% %%% %%%%%%%%% BUILDHUFFMAN.M
%
%
% description: creatre a huffman table from a given distribution
%
% input: bytestream - Encoded bitstream
% BinaryTree - Binary Tree of the Code created by buildHuffma
% nr_symbols - Number of symbols to decode
%
% returnvalue: output - decoded data
%
% Course: Image and Video Compression
% Prof. Eckehard Steinbach
%
%
%-----------------------------------------------------------------------------------
function [output] = dec_huffman_new (bytestream, BinaryTree, nr_symbols)
output = zeros(1,nr_symbols);
ctemp = BinaryTree;
dec = zeros(size(bytestream,1),8);
for i = 8:-1:1
dec(:,i) = rem(bytestream,2);
bytestream = floor(bytestream/2);
end
dec = dec(:,end:-1:1)';
a = dec(:);
i = 1;
p = 1;
while(i <= nr_symbols)&&p<=max(size(a))
while(isa(ctemp,'cell'))
next = a(p)+1;
p = p+1;
ctemp = ctemp{next};
end;
output(i) = ctemp;
ctemp = BinaryTree;
i=i+1;
end;
% ctemp = BinaryTree;
% i = 1;
% p = 1;
% while(i <= nr_symbols)
% while(isa(ctemp,'cell'))
% next = a(p)+1;
% next
% p = p+1;
% ctemp = ctemp{next};
% end;
% output2(i) = ctemp;
% ctemp = BinaryTree;
% i=i+1;
% end
%return