Skip to content

Commit 90642bb

Browse files
committed
BF: Only use the cross product (possibly negated) for the slice normal.
If the CSA slice normal is in the opposite direction then negate the cross product. Fixes issue #137.
1 parent 1e171a3 commit 90642bb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

nibabel/nicom/dicomwrappers.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,22 @@ def __init__(self, dcm_data=None, csa_header=None):
407407

408408
@one_time
409409
def slice_normal(self):
410-
slice_normal = csar.get_slice_normal(self.csa_header)
411-
if not slice_normal is None:
412-
return np.array(slice_normal)
413-
iop = self.image_orient_patient
414-
if iop is None:
410+
std_slice_normal = super(SiemensWrapper, self).slice_normal
411+
csa_slice_normal = csar.get_slice_normal(self.csa_header)
412+
if std_slice_normal is None and csa_slice_normal is None:
415413
return None
416-
return np.cross(*iop.T[:])
417-
414+
elif std_slice_normal is None:
415+
return np.array(csa_slice_normal)
416+
elif csa_slice_normal is None:
417+
return std_slice_normal
418+
else:
419+
dot_prod = np.dot(csa_slice_normal, std_slice_normal)
420+
assert np.allclose(np.fabs(dot_prod), 1.0, atol=1e-5)
421+
if dot_prod < 0:
422+
return -std_slice_normal
423+
else:
424+
return std_slice_normal
425+
418426
@one_time
419427
def series_signature(self):
420428
''' Add ICE dims from CSA header to signature '''

0 commit comments

Comments
 (0)