fsleyes.plugins.tools.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:
The
FlirtFileDialog
class is awx.Dialog
which prompts the user to select a FLIRT (or other affine) transformation matrix and reference image associated with a source image.Displays a dialog prompting the user to select a FLIRT transformation matrix file and associated reference image for the given overlay.
Given a
path
to a NIFTI image file, tries to guess an appropriate FLIRT transformation matrix file and reference image.Calculates a source voxel -> reference world transformation matrix from the given FLIRT transform and refernece image files.
- class fsleyes.plugins.tools.applyflirtxfm.ApplyFlirtXfmAction(*args, **kwargs)[source]
Bases:
NeedOverlayAction
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 anImage
instance.A
FlirtFileDialog
is used to prompt the user to select a transformation matrix and reference image. ThecalculateTransform()
function is used to calculate the source voxel -> reference world transformation, and the imagevoxToWorldMat
is then updated accordingly.- __init__(overlayList, displayCtx, frame)[source]
Create an
ApplyFlirtXfmAction
.- Parameters:
overlayList – The
OverlayList
.displayCtx – The
DisplayContext
.frame – The
FSLeyesFrame
.
- __applyFlirtXfm()
Called when this action is executed.
- __annotations__ = {}
- __module__ = 'fsleyes.plugins.tools.applyflirtxfm'
- fsleyes.plugins.tools.applyflirtxfm.calculateTransform(overlay, overlayList, displayCtx, matFile, refFile)[source]
Calculates a source voxel -> reference world transformation matrix from the given FLIRT transform and refernece image files.
See the
fsl.transform.flirt.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.plugins.tools.applyflirtxfm.promptForFlirtFiles(parent, overlay, overlayList, displayCtx, save=False)[source]
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
ifaffType is 'v2w'
)
If the user cancelled the dialog, all elements of this tuple will be
None
.
- fsleyes.plugins.tools.applyflirtxfm.guessFlirtFiles(path)[source]
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.plugins.tools.applyflirtxfm.FlirtFileDialog(parent, srcFile, refOpts=None, refOptFiles=None, selectedRef=None, matFile=None, refFile=None, save=False)[source]
Bases:
Dialog
The
FlirtFileDialog
class is awx.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)[source]
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.
- property ok
Return a reference to the OK button.
- property cancel
Return a reference to the cancel button.
- property matFileText
Return a reference to the matrix file text entry widget.
- property refFileText
Return a reference to the reference file text entry widget.
- property affType
Return a reference to the affine type dropdown widget.
- property refChoice
Return a reference to the reference file dropdown widget.
- GetAffineType()[source]
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()[source]
Returns the current value of the matrix file as a string, or
None
, if the file path is not valid.
- GetRefFile()[source]
Returns the current value of the reference file, as a string, or
None
, if the file path is not valid.
- __onOkButton(ev)
Called when the user clicks the ok button. Closes the dialog.
- __onCancelButton(ev)
Called when the user clicks the cancel button. Closes the dialog.
- __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).
- __annotations__ = {}
- __module__ = 'fsleyes.plugins.tools.applyflirtxfm'
- __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.
- __onMatFileButton(ev)
Called when the user clicks the matrix file select button. Displays a file dialog prompting the user to select a matrix file.
- __onRefFileButton(ev)
Called when the user clicks the reference file select button. Displays a file dialog prompting the user to select a reference file.