fsleyes.actions.applyflirtxfm

This module provides the ApplyFlirtXfmAction class, an Action which allows the user to load a FLIRT transformation matrix and apply it to an Image overlay.

A number of related standalone classes and functions are also defined in this module:

FlirtFileDialog The FlirtFileDialog class is a wx.Dialog which prompts the user to select a FLIRT (or other affine) transformation matrix and reference image associated with a source image.
promptForFlirtFiles Displays a dialog prompting the user to select a FLIRT transformation matrix file and associated reference image for the given overlay.
guessFlirtFiles Given a path to a NIFTI image file, tries to guess an appropriate FLIRT transformation matrix file and reference image.
calculateTransform Calculates a source voxel -> reference world transformation matrix from the given FLIRT transform and refernece image files.
class fsleyes.actions.applyflirtxfm.ApplyFlirtXfmAction(overlayList, displayCtx, frame)

Bases: fsleyes.actions.base.Action

The ApplyFlirtXfmAction class is an action which allows the user to load a FLIRT transformation matrix (or other affine file) and apply it to the currently selected overlay, if it is an Image instance.

A FlirtFileDialog is used to prompt the user to select a transformation matrix and reference image. The calculateTransform() function is used to calculate the source voxel -> reference world transformation, and the image voxToWorldMat is then updated accordingly.

__init__(overlayList, displayCtx, frame)

Create an ApplyFlirtXfmAction.

Parameters:
_ApplyFlirtXfmAction__applyFlirtXfm()

Called when this action is executed.

_ApplyFlirtXfmAction__selectedOverlayChanged(*a)

Called when the DisplayContext.selectedOverlay changes. Updates the Action.enabled state of this action.

__module__ = 'fsleyes.actions.applyflirtxfm'
fsleyes.actions.applyflirtxfm.calculateTransform(overlay, overlayList, displayCtx, matFile, refFile)

Calculates a source voxel -> reference world transformation matrix from the given FLIRT transform and refernece image files.

See the fsl.utils.transform.flirtMatrixToSform() function.

Parameters:
  • overlay – The Image overlay - the source image of the FLIRT transformation.
  • overlayList – The OverlayList.
  • displayCtx – The DisplayContext.
  • matFile – Path to the FLIRT transformation matrix file.
  • refFile – Path to the FLIRT reference image file.
fsleyes.actions.applyflirtxfm.promptForFlirtFiles(parent, overlay, overlayList, displayCtx, save=False)

Displays a dialog prompting the user to select a FLIRT transformation matrix file and associated reference image for the given overlay.

Parameters:
  • parent – The wx parent object.
  • overlay – The overlay to load a FLIRT matrix for.
  • overlayList – The OverlayList instance.
  • displayCtx – The DisplayContext instance.
  • save – Prompt the user to save a transformation matrix instead.
Returns:

A tuple containing:

  • The affine type currently one of 'flirt', indicating a FLIRT matrix, or 'v2w', indicating a “raw” voxel-to-world matrix.
  • The selected matrix file.
  • The selected reference image file (None if affType is 'v2w')

If the user cancelled the dialog, all elements of this tuple will be None.

fsleyes.actions.applyflirtxfm.guessFlirtFiles(path)

Given a path to a NIFTI image file, tries to guess an appropriate FLIRT transformation matrix file and reference image. The guess is based on the path location (e.g. if it is a FEAT or MELODIC image).

Returns a tuple containing paths to the matrix file and reference image, or (None, None) if a guess couldn’t be made.

class fsleyes.actions.applyflirtxfm.FlirtFileDialog(parent, srcFile, refOpts=None, refOptFiles=None, selectedRef=None, matFile=None, refFile=None, save=False)

Bases: __main__.MockClass

The FlirtFileDialog class is a wx.Dialog which prompts the user to select a FLIRT (or other affine) transformation matrix and reference image associated with a source image.

The user can select a reference image either from a drop down box, or by selecting a file in the file system.

__init__(parent, srcFile, refOpts=None, refOptFiles=None, selectedRef=None, matFile=None, refFile=None, save=False)

Create a FlirtFileDialog.

Parameters:
  • parent – The wx parent object.
  • srcFile – Path to the FLIRT source image file
  • refOpts – Options to use in the reference image drop down box.
  • refOptFiles – File paths which correspond to the refOpts.
  • selectedRef – Index of initially selected refOpt.
  • matFile – Initial path to a FLIRT transformation matrix file
  • refFile – Initial Path to a FLIRT reference image file
  • save – If True, the user will be prompted to save a FLIRT matrix. Otherwise (the default), the user will be prompted to load an existing FLIRT matrix.
GetAffineType()

Return the currently selected affine type - currently either 'flirt' (indicating a FSL FLIRT matrix file), or 'v2w' (indicating a “raw” voxel-to-world affine).

GetMatFile()

Returns the current value of the matrix file as a string, or None, if the file path is not valid.

GetRefFile()

Returns the current value of the reference file, as a string, or None, if the file path is not valid.

_FlirtFileDialog__onAffType(ev)

Called when the user changes the affine type. Enables/disables widgets related to the reference image (as they are only used for FLIRT affines).

_FlirtFileDialog__onCancelButton(ev)

Called when the user clicks the cancel button. Closes the dialog.

_FlirtFileDialog__onMatFileButton(ev)

Called when the user clicks the matrix file select button. Displays a file dialog prompting the user to select a matrix file.

_FlirtFileDialog__onOkButton(ev)

Called when the user clicks the ok button. Closes the dialog.

_FlirtFileDialog__onRefChoice(ev)

Called when the user changes the selection in the reference image drop down box. Enables/disables the reference image file selection widgets as necessary.

_FlirtFileDialog__onRefFileButton(ev)

Called when the user clicks the reference file select button. Displays a file dialog prompting the user to select a reference file.

__module__ = 'fsleyes.actions.applyflirtxfm'