-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharithmetic_coding_separation.py
127 lines (78 loc) · 2.31 KB
/
arithmetic_coding_separation.py
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import numpy as np
import os
import struct
import h5py
import encoder_init as encoder
import decoder_init as decoder
import time
# In[2]:
def write_hdf5(x,filename):
with h5py.File(filename, 'w') as h:
h.create_dataset('data', data=x, shape=x.shape)
# In[3]:
def show_data(x_in, pre_in):
mean = np.mean(x_in)
std = np.std(x_in)
Max = np.max(x_in)
Min = np.min(x_in)
dtype = x_in.dtype
print(pre_in + ' shape: ' + str(x_in.shape) + ' , type: ' + str(dtype) + ' , mean = ' + str(mean)
+ ' , std = ' + str(std) + ' , Max = ' + str(Max) + ' , Min = ' + str(Min))
# In[4]:
fname = '../H5_tmp/comp_3chan_10bit_floor.h5'
ftmp=h5py.File(fname,'r')
dt=ftmp['data'][:]
dt=dt.astype(np.int64)
show_data(dt, 'dt')
# In[5]:
for i in range(3):
print('\nchannel %d'%(i))
a = dt[:,:,i].flatten()
show_data(a, 'a')
start = time.clock()
encoder.encode_data(a,'./TMP_files/encode_data.txt')
end = time.clock()
print('encode_run_time : ' + str(end-start))
fsize = os.path.getsize('./TMP_files/encode_data.txt')
print('fsize= ' + str(fsize))
start = time.clock()
ee = decoder.decode_data('./TMP_files/encode_data.txt','./TMP_files/decode_data.txt')
end = time.clock()
print('decode_run_time : ' + str(end-start))
rec = np.array(ee)
show_data(rec,'rec')
mse = np.mean(np.square(rec-a))
print('mse= ' + str(mse))
ratio = float(fsize)/float(len(a))
print('ratio= ' + str(ratio))
# ## Together
# In[6]:
# fname = '../H5_tmp/comp_3chan_10bit_floor.h5'
# ftmp=h5py.File(fname,'r')
# dt=ftmp['data'][:]
# dt=dt.astype(np.int64)
# show_data(dt, 'dt')
a = dt.flatten()
show_data(a, 'a')
# In[7]:
start = time.clock()
encoder.encode_data(a,'./TMP_files/encode_data.txt')
end = time.clock()
print('encode_run_time : ' + str(end-start))
fsize = os.path.getsize('./TMP_files/encode_data.txt')
print('fsize= ' + str(fsize))
# In[8]:
start = time.clock()
ee = decoder.decode_data('./TMP_files/encode_data.txt','./TMP_files/decode_data.txt')
end = time.clock()
print('decode_run_time : ' + str(end-start))
rec = np.array(ee)
show_data(rec,'rec')
mse = np.mean(np.square(rec-a))
print('mse= ' + str(mse))
ratio = float(fsize)/float(len(a))
print('ratio= ' + str(ratio))
# In[ ]: