-
Notifications
You must be signed in to change notification settings - Fork 3
/
flow_IO.py
31 lines (20 loc) · 927 Bytes
/
flow_IO.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
from PIL import Image
import h5py
def writeFlo5File(flow, filename):
with h5py.File(filename, "w") as f:
f.create_dataset("flow", data=flow, compression="gzip", compression_opts=5)
def readFlo5Flow(filename):
with h5py.File(filename, "r") as f:
if "flow" not in f.keys():
raise IOError(f"File {filename} does not have a 'flow' key. Is this a valid flo5 file?")
return f["flow"][()]
def writeDsp5File(disp, filename):
with h5py.File(filename, "w") as f:
f.create_dataset("disparity", data=disp, compression="gzip", compression_opts=5)
def readDsp5Disp(filename):
with h5py.File(filename, "r") as f:
if "disparity" not in f.keys():
raise IOError(f"File {filename} does not have a 'disparity' key. Is this a valid dsp5 file?")
return f["disparity"][()]
def writePngMapFile(map_, filename):
Image.fromarray(map_).save(filename)