webapps / hmc /reference /scripts /conform_facts.py
gdevenyi's picture
hmc: NiFreeze 3bcfb00 and QSIPrep 26.1.1 SHORELine reference runs on ds005577 sub-107 (part 9)
a4ba047 verified
Raw History Blame Contribute Delete
829 Bytes
"""Compare the raw DWI grid with QSIPrep's conformed (LPS) grid. Usage: python -I conform_facts.py RAW CONFORMED."""
import sys
import nibabel as nb
import numpy as np
raw = nb.load(sys.argv[1])
con = nb.load(sys.argv[2])
print("raw", raw.shape, raw.get_data_dtype(), nb.aff2axcodes(raw.affine))
print(np.array2string(raw.affine, precision=6))
print("conformed", con.shape, con.get_data_dtype(), nb.aff2axcodes(con.affine))
print(np.array2string(con.affine, precision=6))
print("scl", con.header["scl_slope"], con.header["scl_inter"])
ornt = nb.orientations.ornt_transform(
nb.io_orientation(raw.affine), nb.io_orientation(con.affine)
)
r = nb.orientations.apply_orientation(np.asanyarray(raw.dataobj), ornt)
c = np.asanyarray(con.dataobj)
print("max abs diff after reorientation", np.abs(r.astype(np.float64) - c).max())