def compare_xforms(lta_list, norm_threshold=15): """ Computes a normalized displacement between two affine transforms as the maximum overall displacement of the midpoints of the faces of a cube, when each transform is applied to the cube. This combines displacement resulting from scaling, translation and rotation. Although the norm is in mm, in a scaling context, it is not necessarily equivalent to that distance in translation. We choose a default threshold of 15mm as a rough heuristic. Normalized displacement above 20mm showed clear signs of distortion, while "good" BBR refinements were frequently below 10mm displaced from the rigid transform. The 10-20mm range was more ambiguous, and 15mm chosen as a compromise. This is open to revisiting in either direction. See discussion in `GitHub issue #681`_ <https://github.com/poldracklab/fmriprep/issues/681>`_ and the `underlying implementation <https://github.com/nipy/nipype/blob/56b7c81eedeeae884ba47c80096a5f66bd9f8116/nipype/algorithms/rapidart.py#L108-L159>`_. Parameters ---------- lta_list : list or tuple of str the two given affines in LTA format norm_threshold : float (default: 15) the upper bound limit to the normalized displacement caused by the second transform relative to the first """ from fmriprep.interfaces.surf import load_transform from nipype.algorithms.rapidart import _calc_norm_affine bbr_affine = load_transform(lta_list[0]) fallback_affine = load_transform(lta_list[1]) norm, _ = _calc_norm_affine([fallback_affine, bbr_affine], use_differences=True) return norm[1] > norm_threshold
def compare_xforms(lta_list, norm_threshold=15): """ Computes a normalized displacement between two affine transforms as the maximum overall displacement of the midpoints of the faces of a cube, when each transform is applied to the cube. This combines displacement resulting from scaling, translation and rotation. Although the norm is in mm, in a scaling context, it is not necessarily equivalent to that distance in translation. We choose a default threshold of 15mm as a rough heuristic. Normalized displacement above 20mm showed clear signs of distortion, while "good" BBR refinements were frequently below 10mm displaced from the rigid transform. The 10-20mm range was more ambiguous, and 15mm chosen as a compromise. This is open to revisiting in either direction. See discussion in `GitHub issue #681`_ <https://github.com/poldracklab/fmriprep/issues/681>`_ and the `underlying implementation <https://github.com/nipy/nipype/blob/56b7c81eedeeae884ba47c80096a5f66bd9f8116/nipype/algorithms/rapidart.py#L108-L159>`_. Parameters ---------- lta_list : list or tuple of str the two given affines in LTA format norm_threshold : float (default: 15) the upper bound limit to the normalized displacement caused by the second transform relative to the first """ from fmriprep.interfaces.surf import load_transform from nipype.algorithms.rapidart import _calc_norm_affine bbr_affine = load_transform(lta_list[0]) fallback_affine = load_transform(lta_list[1]) norm, _ = _calc_norm_affine([fallback_affine, bbr_affine], use_differences=True) return norm[1] > norm_threshold