0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function M = dunzip(Z)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % DUNZIP - decompress DZIP output to recover original data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % USAGE:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % M = dzip(Z)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % VARIABLES:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % Z = compressed variable to decompress
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % M = decompressed output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % NOTES: (1) The input variable Z is created by the DZIP function and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % is a vector of type uint8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % (2) The decompressed output will have the same data type and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % dimensions as the original data provided to DZIP.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % (3) See DZIP for other notes.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % (4) Carefully tested, but no warranty; use at your own risk.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % (5) Michael Kleder, Nov 2005
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 import com.mathworks.mlwidgets.io.InterruptibleStreamCopier
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 a=java.io.ByteArrayInputStream(Z);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 b=java.util.zip.InflaterInputStream(a);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 isc = InterruptibleStreamCopier.getInterruptibleStreamCopier;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 c = java.io.ByteArrayOutputStream;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 isc.copyStream(b,c);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 Q=typecast(c.toByteArray,'uint8');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 cn = double(Q(1)); % class
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 nd = double(Q(2)); % # dims
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 s = typecast(Q(3:8*nd+2),'double')'; % size
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 Q=Q(8*nd+3:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 if cn == 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 M = logical(Q);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 elseif cn == 4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 M = char(Q);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 ct = {'double','single','logical','char','int8','uint8',...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 'int16','uint16','int32','uint32','int64','uint64'};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 M = typecast(Q,ct{cn});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 M=reshape(M,s);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 return
|