-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRLEBitPlane.py
More file actions
48 lines (40 loc) · 1.28 KB
/
RLEBitPlane.py
File metadata and controls
48 lines (40 loc) · 1.28 KB
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
import numpy as np
import RLE
def encode(oldArrayFlattened):
# result will lead with 0 bit plane
result = []
binaryOldArray = []
# convert original numbers to 8 bit binary
for i in range(len(oldArrayFlattened)):
binaryOldArray.append(format(oldArrayFlattened[i], '08b'))
bitPlane = []
for i in range(8):
for j in range(len(binaryOldArray)):
bitPlane.append(binaryOldArray[j][i])
result.append(bitPlane)
bitPlane=[]
result = np.asarray(result, dtype=int)
resultEncoded = []
for i in range(8):
tmp = result[i]
tmpEncoded = RLE.encode(tmp)
resultEncoded.append(list(tmpEncoded))
return resultEncoded
def decode(encodedList):
result = []
for i in range(8):
tmp = list(RLE.decode(np.asarray(encodedList[i], dtype=int)))
result.append(tmp)
resultDecoded = []
tmp = []
for i in range(len(result[0])):
for j in range(8):
tmp.append(result[j][i])
resultDecoded.append(tmp)
tmp = []
resultFinished = []
for i in range(len(resultDecoded)):
tmp = resultDecoded[i]
num = ''.join(map(str, tmp))
resultFinished.append(int(num, 2))
return resultFinished