-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRLE.py
More file actions
41 lines (31 loc) · 881 Bytes
/
RLE.py
File metadata and controls
41 lines (31 loc) · 881 Bytes
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
import numpy as np
def encode(oldArrayFlattened):
newArrayStr = []
f = 0
s = 0
while f < len(oldArrayFlattened):
count = 0
while (f < len(oldArrayFlattened) and oldArrayFlattened[f] == oldArrayFlattened[s]):
count += 1
f += 1
tmp = []
newArrayStr.append(count)
newArrayStr.append(oldArrayFlattened[s])
s = f
newImgArray = np.asarray(newArrayStr)
output = newImgArray.astype(np.uint16)
return output
def decode(encodedArray):
output = []
times = 0
i = 0
value = 0
while i < len(encodedArray):
times = encodedArray[i]
value = encodedArray[i+1]
while times > 0:
output.append(value)
times-=1
i+=2
outputArray = np.asarray(output)
return outputArray