-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflow-guided-sample.py
51 lines (41 loc) · 1.26 KB
/
flow-guided-sample.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
from sys import argv
import os
import numpy as np
import skimage
import skimage.io
import pyflow.pyflow as pyflow
import progressbar
if len(argv) < 2:
print ('Usage: {} [filelist]'.format(argv[0]))
exit(1)
filelist = argv[1]
with open(filelist, 'r') as fd:
filenames = [f.rstrip() for f in fd.readlines()]
data = [(name, float(flowmag))
for f in filenames
for [name, flowmag] in (f.split(), )
]
def inRange(a, lb, rb):
return lb <= a and a < rb
bin1 = list(filter(lambda a: a[1] < 1, data))
bin1 = list(filter(lambda a: a[1] >= 0.1, bin1))
bin2 = list(filter(lambda a: inRange(a[1], 1, 2), data))
bin3 = list(filter(lambda a: inRange(a[1], 2, 3), data))
bin4 = list(filter(lambda a: inRange(a[1], 3, 4), data))
bin5 = list(filter(lambda a: inRange(a[1], 4, 5), data))
res = list(filter(lambda a: a[1] >= 5, data))
clipN = len(list(filter(lambda a: inRange(a[1], 5, 6), data)))
np.random.shuffle(bin1)
np.random.shuffle(bin2)
np.random.shuffle(bin3)
np.random.shuffle(bin4)
np.random.shuffle(bin5)
bin1 = bin1[:clipN]
bin2 = bin2[:clipN]
bin3 = bin3[:clipN]
bin4 = bin4[:clipN]
bin5 = bin5[:clipN]
newdata = bin1 + bin2 + bin3 + bin4 + bin5 + res
newdata.sort(key=lambda a: a[1])
for name, flow in newdata:
print ('{} {}'.format(name, flow))