|
35 | 35 | ('x_ras', '>f4', (3, 1)),
|
36 | 36 | ('y_ras', '>f4', (3, 1)),
|
37 | 37 | ('z_ras', '>f4', (3, 1)),
|
38 |
| - ('Pxyz_c', '>f4', (3,)) |
| 38 | + ('c_ras', '>f4', (3, 1)) |
39 | 39 | ]
|
40 | 40 | # Optional footer. Also has more stuff after this, optionally
|
41 | 41 | footer_dtd = [
|
@@ -150,16 +150,16 @@ def get_affine(self):
|
150 | 150 | ''' Get the affine transform from the header information.
|
151 | 151 | MGH format doesn't store the transform directly. Instead it's gleaned
|
152 | 152 | from the zooms ( delta ), direction cosines ( Mdc ), RAS centers (
|
153 |
| - Pxyz_c ) and the dimensions. |
| 153 | + c_ras ) and the dimensions. |
154 | 154 | '''
|
155 | 155 | hdr = self._structarr
|
156 | 156 | d = np.diag(hdr['delta'])
|
157 | 157 | 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)) |
160 | 160 | 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 |
163 | 163 | return M
|
164 | 164 |
|
165 | 165 | # For compatibility with nifti (multiple affines)
|
@@ -320,19 +320,19 @@ def default_structarr(klass, endianness=None):
|
320 | 320 | hdr_data['x_ras'] = np.array([[-1], [0], [0]])
|
321 | 321 | hdr_data['y_ras'] = np.array([[0], [0], [1]])
|
322 | 322 | 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 |
324 | 324 | hdr_data['mrparms'] = np.array([0, 0, 0, 0])
|
325 | 325 | return hdr_data
|
326 | 326 |
|
327 | 327 | 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 |
329 | 329 | '''
|
330 | 330 | self._structarr['goodRASFlag'] = 1
|
331 | 331 | self._structarr['delta'][:] = np.array([1, 1, 1])
|
332 | 332 | self._structarr['x_ras'] = np.array([[-1], [0], [0]])
|
333 | 333 | self._structarr['y_ras'] = np.array([[0], [0], [1]])
|
334 | 334 | 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 |
336 | 336 |
|
337 | 337 | def writehdr_to(self, fileobj):
|
338 | 338 | ''' Write header to fileobj
|
@@ -534,13 +534,13 @@ def _affine2header(self):
|
534 | 534 | Mdc = MdcD / np.tile(delta, (3, 1))
|
535 | 535 | Pcrs_c = np.array([0, 0, 0, 1], dtype=np.float)
|
536 | 536 | 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)) |
538 | 538 |
|
539 | 539 | hdr['delta'][:] = delta
|
540 | 540 | hdr['x_ras'] = Mdc[:, [0]]
|
541 | 541 | hdr['y_ras'] = Mdc[:, [1]]
|
542 | 542 | hdr['z_ras'] = Mdc[:, [2]]
|
543 |
| - hdr['Pxyz_c'][:] = Pxyz_c[:3] |
| 543 | + hdr['c_ras'] = c_ras[:3] |
544 | 544 |
|
545 | 545 |
|
546 | 546 | load = MGHImage.load
|
|
0 commit comments