Skip to content
Snippets Groups Projects
Commit 62b151c7 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

New function to transform module to generate a FLIRT matrix. Bugfix in melodic

labels - failing when trying to load a label file with no noise components.
parent 0c815365
No related branches found
No related tags found
No related merge requests found
...@@ -423,8 +423,10 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None): ...@@ -423,8 +423,10 @@ def loadLabelFile(filename, includeLabel=None, excludeLabel=None):
else: else:
melDir = lines[0] melDir = lines[0]
noisyComps = map(int, lines[-1].strip(' []').split(',')) noisyComps = lines[-1].strip(' []').split(',')
noisyComps = [c for c in noisyComps if c != '']
noisyComps = [int(c) for c in noisyComps]
# The melodic directory path should # The melodic directory path should
# either be an absolute path, or # either be an absolute path, or
# be specified relative to the location # be specified relative to the location
......
...@@ -20,6 +20,7 @@ spaces. The following functions are provided: ...@@ -20,6 +20,7 @@ spaces. The following functions are provided:
axisAnglesToRotMat axisAnglesToRotMat
axisBounds axisBounds
flirtMatrixToSform flirtMatrixToSform
sformToFlirtMatrix
""" """
import numpy as np import numpy as np
...@@ -413,3 +414,32 @@ def flirtMatrixToSform(flirtMat, srcImage, refImage): ...@@ -413,3 +414,32 @@ def flirtMatrixToSform(flirtMat, srcImage, refImage):
refInvScaledVoxelMat, refInvScaledVoxelMat,
flirtMat, flirtMat,
srcScaledVoxelMat) srcScaledVoxelMat)
def sformToFlirtMatrix(srcImage, refImage, srcXform=None):
"""Under the assumption that the given ``srcImage`` and ``refImage``
share a common world coordinate system (defined by their
:attr:`voxToWorldMat` attributes), this function will calculate and
return a transformation matrix from the ``srcImage`` scaled voxel
coordinate system to the ``refImage`` scaled voxel coordinate system,
that can be saved to disk and used with FLIRT, to resample the source
image to the reference image.
:arg srcImage: Source :class:`.Image`
:arg refImage: Reference :class:`.Image`
:arg srcXform: Optionally used in place of the ``scrImage``
:attr:`.voxToWorldMat`
"""
srcScaledVoxelsToVoxelsMat = invert(srcImage.voxelsToScaledVoxels())
srcVoxToWorldMat = srcImage.voxToWorldMat
refWorldToVoxMat = invert(refImage.voxToWorldMat)
refVoxelsToScaledVoxelsMat = refImage.voxelsToScaledVoxels()
if srcXform is not None:
srcVoxToWorldMat = srcXform
return concat(refVoxelsToScaledVoxelsMat,
refWorldToVoxMat,
srcVoxToWorldMat,
srcScaledVoxelsToVoxelsMat)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment