Scale an MRI by setting its affine.
(subject_to, mri_fname, subject_from, scale, subjects_dir)
| 1339 | |
| 1340 | |
| 1341 | def _scale_mri(subject_to, mri_fname, subject_from, scale, subjects_dir): |
| 1342 | """Scale an MRI by setting its affine.""" |
| 1343 | subjects_dir, subject_from, scale, _ = _scale_params( |
| 1344 | subject_to, subject_from, scale, subjects_dir |
| 1345 | ) |
| 1346 | nibabel = _import_nibabel("scale an MRI") |
| 1347 | fname_from = op.join( |
| 1348 | mri_dirname.format(subjects_dir=subjects_dir, subject=subject_from), mri_fname |
| 1349 | ) |
| 1350 | fname_to = op.join( |
| 1351 | mri_dirname.format(subjects_dir=subjects_dir, subject=subject_to), mri_fname |
| 1352 | ) |
| 1353 | img = nibabel.load(fname_from) |
| 1354 | zooms = np.array(img.header.get_zooms()) |
| 1355 | zooms[[0, 2, 1]] *= scale |
| 1356 | img.header.set_zooms(zooms) |
| 1357 | # Hack to fix nibabel problems, see |
| 1358 | # https://github.com/nipy/nibabel/issues/619 |
| 1359 | img._affine = img.header.get_affine() # or could use None |
| 1360 | nibabel.save(img, fname_to) |
| 1361 | |
| 1362 | |
| 1363 | def _scale_xfm(subject_to, xfm_fname, mri_name, subject_from, scale, subjects_dir): |
no test coverage detected