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

Function _scale_xfm

mne/coreg.py:1363–1442  ·  view source on GitHub ↗

Scale a transform.

(subject_to, xfm_fname, mri_name, subject_from, scale, subjects_dir)

Source from the content-addressed store, hash-verified

1361
1362
1363def _scale_xfm(subject_to, xfm_fname, mri_name, subject_from, scale, subjects_dir):
1364 """Scale a transform."""
1365 subjects_dir, subject_from, scale, _ = _scale_params(
1366 subject_to, subject_from, scale, subjects_dir
1367 )
1368
1369 # The nibabel warning should already be there in MRI step, if applicable,
1370 # as we only get here if T1.mgz is present (and thus a scaling was
1371 # attempted) so we can silently return here.
1372 fname_from = os.path.join(
1373 mri_transforms_dirname.format(subjects_dir=subjects_dir, subject=subject_from),
1374 xfm_fname,
1375 )
1376 fname_to = op.join(
1377 mri_transforms_dirname.format(subjects_dir=subjects_dir, subject=subject_to),
1378 xfm_fname,
1379 )
1380 assert op.isfile(fname_from), fname_from
1381 assert op.isdir(op.dirname(fname_to)), op.dirname(fname_to)
1382 # The "talairach.xfm" file stores the ras_mni transform.
1383 #
1384 # For "from" subj F, "to" subj T, F->T scaling S, some equivalent vertex
1385 # positions F_x and T_x in MRI (FreeSurfer RAS) coords, knowing that
1386 # we have T_x = S @ F_x, we want to have the same MNI coords computed
1387 # for these vertices:
1388 #
1389 # T_mri_mni @ T_x = F_mri_mni @ F_x
1390 #
1391 # We need to find the correct T_ras_mni (talaraich.xfm file) that yields
1392 # this. So we derive (where † indicates inversion):
1393 #
1394 # T_mri_mni @ S @ F_x = F_mri_mni @ F_x
1395 # T_mri_mni @ S = F_mri_mni
1396 # T_ras_mni @ T_mri_ras @ S = F_ras_mni @ F_mri_ras
1397 # T_ras_mni @ T_mri_ras = F_ras_mni @ F_mri_ras @ S⁻¹
1398 # T_ras_mni = F_ras_mni @ F_mri_ras @ S⁻¹ @ T_ras_mri
1399 #
1400
1401 # prepare the scale (S) transform
1402 scale = np.atleast_1d(scale)
1403 scale = np.tile(scale, 3) if len(scale) == 1 else scale
1404 S = Transform("mri", "mri", scaling(*scale)) # F_mri->T_mri
1405
1406 #
1407 # Get the necessary transforms of the "from" subject
1408 #
1409 xfm, kind = _read_fs_xfm(fname_from)
1410 assert kind == "MNI Transform File", kind
1411 _, _, F_mri_ras, _, _ = _read_mri_info(mri_name, units="mm")
1412 F_ras_mni = Transform("ras", "mni_tal", xfm)
1413 del xfm
1414
1415 #
1416 # Get the necessary transforms of the "to" subject
1417 #
1418 mri_name = op.join(
1419 mri_dirname.format(subjects_dir=subjects_dir, subject=subject_to),
1420 op.basename(mri_name),

Callers 1

scale_mriFunction · 0.85

Calls 8

_scale_paramsFunction · 0.85
TransformClass · 0.85
scalingFunction · 0.85
_read_fs_xfmFunction · 0.85
_read_mri_infoFunction · 0.85
invert_transformFunction · 0.85
combine_transformsFunction · 0.85
_write_fs_xfmFunction · 0.85

Tested by

no test coverage detected