MCPcopy
hub / github.com/mne-tools/mne-python / _scale_mri

Function _scale_mri

mne/coreg.py:1341–1360  ·  view source on GitHub ↗

Scale an MRI by setting its affine.

(subject_to, mri_fname, subject_from, scale, subjects_dir)

Source from the content-addressed store, hash-verified

1339
1340
1341def _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
1363def _scale_xfm(subject_to, xfm_fname, mri_name, subject_from, scale, subjects_dir):

Callers 1

scale_mriFunction · 0.85

Calls 3

_scale_paramsFunction · 0.85
_import_nibabelFunction · 0.85
saveMethod · 0.45

Tested by

no test coverage detected