@@ -204,7 +204,7 @@ def _to_hdf5(self, x5_root):
|
204 | 204 |
|
205 | 205 | def to_filename(self, filename, fmt='X5', moving=None):
|
206 | 206 | """Store the transform in BIDS-Transforms HDF5 file format (.x5)."""
|
207 |
| -if fmt.lower() in ['itk', 'ants', 'elastix', 'nifty']: |
| 207 | +if fmt.lower() in ['itk', 'ants', 'elastix']: |
208 | 208 | with open(filename, 'w') as f:
|
209 | 209 | f.write('#Insight Transform File V1.0\n')
|
210 | 210 |
|
@@ -229,26 +229,25 @@ def to_filename(self, filename, fmt='X5', moving=None):
|
229 | 229 | T = self.matrix.copy()
|
230 | 230 | pre = LPS
|
231 | 231 | post = LPS
|
232 |
| -if any(obliquity(self.reference.affine) * 180 / pi > OBLIQUITY_THRESHOLD_DEG): |
| 232 | +if obliquity(self.reference.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG: |
233 | 233 | print('Reference affine axes are oblique.')
|
234 | 234 | M = self.reference.affine
|
235 | 235 | A = shape_zoom_affine(self.reference.shape,
|
236 |
| -voxel_sizes(M), x_flip=True) |
237 |
| -pre = M.dot(np.linalg.inv(A)) |
| 236 | +voxel_sizes(M), x_flip=False, y_flip=False) |
| 237 | +pre = M.dot(np.linalg.inv(A)).dot(LPS) |
238 | 238 |
|
239 | 239 | if not moving:
|
240 | 240 | moving = self.reference
|
241 | 241 |
|
242 |
| -if moving and any(obliquity(moving.affine) * 180 / pi > OBLIQUITY_THRESHOLD_DEG): |
| 242 | +if moving and obliquity(moving.affine).min() * 180 / pi > OBLIQUITY_THRESHOLD_DEG: |
243 | 243 | print('Moving affine axes are oblique.')
|
244 |
| -M = moving.affine |
245 |
| -A = shape_zoom_affine(moving.shape, |
246 |
| -voxel_sizes(M), x_flip=True) |
247 |
| -post = M.dot(np.linalg.inv(A)) |
| 244 | +M2 = moving.affine |
| 245 | +A2 = shape_zoom_affine(moving.shape, |
| 246 | +voxel_sizes(M2), x_flip=True, y_flip=True) |
| 247 | +post = A2.dot(np.linalg.inv(M2)) |
248 | 248 |
|
249 | 249 | # swapaxes is necessary, as axis 0 encodes series of transforms
|
250 |
| -T = np.swapaxes(post.dot(self.matrix.copy().dot(pre)), 0, 1) |
251 |
| -parameters = np.swapaxes(post.dot(T.dot(pre)), 0, 1) |
| 250 | +parameters = np.swapaxes(post.dot(self.matrix.copy().dot(pre)), 0, 1) |
252 | 251 | parameters = parameters[:, :3, :].reshape((T.shape[0], -1))
|
253 | 252 | np.savetxt(filename, parameters, delimiter='\t', header="""\
|
254 | 253 | 3dvolreg matrices (DICOM-to-DICOM, row-by-row):""", fmt='%g')
|
|
0 commit comments