-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.py
44 lines (34 loc) · 1.23 KB
/
utils.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
import numpy as np
def readcfl(name):
# get dims from .hdr
with open(name + ".hdr", "rt") as h:
h.readline() # skip
l = h.readline()
dims = [int(i) for i in l.split()]
# remove singleton dimensions from the end
n = np.prod(dims)
dims_prod = np.cumprod(dims)
dims = dims[:np.searchsorted(dims_prod, n)+1]
# load data and reshape into dims
with open(name + ".cfl", "rb") as d:
a = np.fromfile(d, dtype=np.complex64, count=n);
return a.reshape(dims, order='F') # column-major
def float2cplx(float_in):
return np.array(float_in[...,0]+1.0j*float_in[...,1], dtype='complex64')
def cplx2float(cplx_in):
return np.array(np.stack((cplx_in.real, cplx_in.imag), axis=-1), dtype='float32')
# read cfl file and plot it as image
import matplotlib.pyplot as plt
import sys
def main(cfl, img_path):
input_tensor = readcfl(cfl).squeeze()
plt.imshow(abs(input_tensor), cmap="gray")
plt.savefig(img_path)
if __name__ == "__main__":
# parse command line arguments
if len(sys.argv) != 3:
print("Usage: python utils.py <cfl> <save_img_path>")
sys.exit(1)
cfl = sys.argv[1]
img_path = sys.argv[2]
main(sys.argv[1], sys.argv[2])