Skip to content

Commit 10c6d68

Browse files
committed
RF: Pxyz_c to c_ras
1 parent 3f56c7a commit 10c6d68

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

nibabel/freesurfer/mghformat.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
('x_ras', '>f4', (3, 1)),
3636
('y_ras', '>f4', (3, 1)),
3737
('z_ras', '>f4', (3, 1)),
38-
('Pxyz_c', '>f4', (3,))
38+
('c_ras', '>f4', (3, 1))
3939
]
4040
# Optional footer. Also has more stuff after this, optionally
4141
footer_dtd = [
@@ -150,16 +150,16 @@ def get_affine(self):
150150
''' Get the affine transform from the header information.
151151
MGH format doesn't store the transform directly. Instead it's gleaned
152152
from the zooms ( delta ), direction cosines ( Mdc ), RAS centers (
153-
Pxyz_c ) and the dimensions.
153+
c_ras ) and the dimensions.
154154
'''
155155
hdr = self._structarr
156156
d = np.diag(hdr['delta'])
157157
pcrs_c = hdr['dims'][:3] / 2.0
158-
Mdc = np.vstack((hdr['x_ras'], hdr['y_ras'], hdr['z_ras']))
159-
pxyz_0 = hdr['Pxyz_c'] - np.dot(Mdc, np.dot(d, pcrs_c))
158+
Mdc = np.hstack((hdr['x_ras'], hdr['y_ras'], hdr['z_ras']))
159+
pxyz_0 = hdr['c_ras'] - Mdc.dot(d).dot(pcrs_c.reshape(3, 1))
160160
M = np.eye(4, 4)
161-
M[0:3, 0:3] = np.dot(Mdc, d)
162-
M[0:3, 3] = pxyz_0.T
161+
M[:3, :3] = np.dot(Mdc, d)
162+
M[:3, [3]] = pxyz_0
163163
return M
164164

165165
# For compatibility with nifti (multiple affines)
@@ -320,19 +320,19 @@ def default_structarr(klass, endianness=None):
320320
hdr_data['x_ras'] = np.array([[-1], [0], [0]])
321321
hdr_data['y_ras'] = np.array([[0], [0], [1]])
322322
hdr_data['z_ras'] = np.array([[0], [-1], [0]])
323-
hdr_data['Pxyz_c'] = np.array([0, 0, 0]) # c_ras
323+
hdr_data['c_ras'] = 0
324324
hdr_data['mrparms'] = np.array([0, 0, 0, 0])
325325
return hdr_data
326326

327327
def _set_affine_default(self):
328-
''' If goodRASFlag is 0, return the default delta, Mdc and Pxyz_c
328+
''' If goodRASFlag is 0, return the default delta, Mdc and c_ras
329329
'''
330330
self._structarr['goodRASFlag'] = 1
331331
self._structarr['delta'][:] = np.array([1, 1, 1])
332332
self._structarr['x_ras'] = np.array([[-1], [0], [0]])
333333
self._structarr['y_ras'] = np.array([[0], [0], [1]])
334334
self._structarr['z_ras'] = np.array([[0], [-1], [0]])
335-
self._structarr['Pxyz_c'][:] = np.array([0, 0, 0]) # c_ras
335+
self._structarr['c_ras'] = 0
336336

337337
def writehdr_to(self, fileobj):
338338
''' Write header to fileobj
@@ -534,13 +534,13 @@ def _affine2header(self):
534534
Mdc = MdcD / np.tile(delta, (3, 1))
535535
Pcrs_c = np.array([0, 0, 0, 1], dtype=np.float)
536536
Pcrs_c[:3] = np.array(shape[:3]) / 2.0
537-
Pxyz_c = np.dot(self._affine, Pcrs_c)
537+
c_ras = self._affine.dot(Pcrs_c.reshape(4, 1))
538538

539539
hdr['delta'][:] = delta
540540
hdr['x_ras'] = Mdc[:, [0]]
541541
hdr['y_ras'] = Mdc[:, [1]]
542542
hdr['z_ras'] = Mdc[:, [2]]
543-
hdr['Pxyz_c'][:] = Pxyz_c[:3]
543+
hdr['c_ras'] = c_ras[:3]
544544

545545

546546
load = MGHImage.load

0 commit comments

Comments
 (0)