webapps / hmc /reference /scripts /pivot_norm.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
455 Bytes
"""Print the QSIPrep-formula pivot A[:3,:3] @ c and its norm for two centre definitions."""
import sys
import nibabel as nb
import numpy as np
img = nb.load(sys.argv[1])
a = img.affine
s = np.array(img.shape[:3])
for name, c in (("(shape-1)/2", (s - 1) / 2), ("shape/2", s / 2)):
p = a[:3, :3] @ c
print(name, p.round(3), round(float(np.linalg.norm(p)), 3))
print("origin", a[:3, 3].round(3), "norm", round(float(np.linalg.norm(a[:3, 3])), 3))