Commit b53db87d authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF: Remove fsl.transform package imports, to remove circular dependency

between fsl.transform.nonlinear and fsl.data.image.
parent c30f1c74
......@@ -54,7 +54,7 @@ import fsl.data.image as fslimage
import fsl.data.constants as constants
from fsl.utils.platform import platform as platform
import fsl.utils.image.resample as resample
import fsl.transform as transform
import fsl.transform.affine as affine
import fsl.utils.notifier as notifier
import fsl.utils.settings as fslsettings
......@@ -572,7 +572,7 @@ class AtlasDescription(object):
# Load the appropriate transformation matrix
# and transform all those voxel coordinates
# into world coordinates
coords = transform.transform(coords, self.xforms[0])
coords = affine.transform(coords, self.xforms[0])
# Update the coordinates
# in our label objects
......@@ -810,7 +810,7 @@ class LabelAtlas(Atlas):
"""
if not voxel:
loc = transform.transform([loc], self.worldToVoxMat)[0]
loc = affine.transform([loc], self.worldToVoxMat)[0]
loc = [int(v) for v in loc.round()]
if loc[0] < 0 or \
......@@ -983,7 +983,7 @@ class ProbabilisticAtlas(Atlas):
"""
if not voxel:
loc = transform.transform([loc], self.worldToVoxMat)[0]
loc = affine.transform([loc], self.worldToVoxMat)[0]
loc = [int(v) for v in loc.round()]
if loc[0] < 0 or \
......
......@@ -47,11 +47,10 @@ import logging
import os.path as op
import numpy as np
import fsl.utils.path as fslpath
import fsl.transform as transform
from . import image as fslimage
from . import featdesign
import fsl.utils.path as fslpath
import fsl.transform.affine as affine
from . import image as fslimage
from . import featdesign
log = logging.getLogger(__name__)
......@@ -467,9 +466,9 @@ def loadClusterResults(featdir, settings, contrast):
zcog = [c.zcogx, c.zcogy, c.zcogz]
copemax = [c.copemaxx, c.copemaxy, c.copemaxz]
zmax = transform.transform([zmax], coordXform)[0].round()
zcog = transform.transform([zcog], coordXform)[0].round()
copemax = transform.transform([copemax], coordXform)[0].round()
zmax = affine.transform([zmax], coordXform)[0].round()
zcog = affine.transform([zcog], coordXform)[0].round()
copemax = affine.transform([copemax], coordXform)[0].round()
c.zmaxx, c.zmaxy, c.zmaxz = zmax
c.zcogx, c.zcogy, c.zcogz = zcog
......
......@@ -46,7 +46,7 @@ import nibabel as nib
import nibabel.fileslice as fileslice
import fsl.utils.meta as meta
import fsl.transform as transform
import fsl.transform.affine as affine
import fsl.utils.notifier as notifier
import fsl.utils.memoize as memoize
import fsl.utils.path as fslpath
......@@ -332,9 +332,9 @@ class Nifti(notifier.Notifier, meta.Meta):
refpix = (header.get('intent_p1', 1),
header.get('intent_p2', 1),
header.get('intent_p3', 1))
voxToWorldMat = transform.concat(
transform.scaleOffsetXform(refpix, 0),
transform.scaleOffsetXform(knotpix, 0))
voxToWorldMat = affine.concat(
affine.scaleOffsetXform(refpix, 0),
affine.scaleOffsetXform(knotpix, 0))
# If the qform or sform codes are unknown,
# then we can't assume that the transform
......@@ -348,7 +348,7 @@ class Nifti(notifier.Notifier, meta.Meta):
# should just be a straight scaling matrix.
elif qform == 0 and sform == 0:
pixdims = header.get_zooms()
voxToWorldMat = transform.scaleOffsetXform(pixdims, 0)
voxToWorldMat = affine.scaleOffsetXform(pixdims, 0)
# Otherwise we let nibabel decide
# which transform to use.
......@@ -389,21 +389,21 @@ class Nifti(notifier.Notifier, meta.Meta):
if isneuro:
x = (shape[0] - 1) * pixdim[0]
flip = transform.scaleOffsetXform([-1, 1, 1],
[ x, 0, 0])
voxToScaledVoxMat = transform.concat(flip, voxToScaledVoxMat)
flip = affine.scaleOffsetXform([-1, 1, 1],
[ x, 0, 0])
voxToScaledVoxMat = affine.concat(flip, voxToScaledVoxMat)
affines['fsl', 'fsl'] = np.eye(4)
affines['voxel', 'voxel'] = np.eye(4)
affines['world', 'world'] = np.eye(4)
affines['voxel', 'world'] = voxToWorldMat
affines['world', 'voxel'] = transform.invert(voxToWorldMat)
affines['world', 'voxel'] = affine.invert(voxToWorldMat)
affines['voxel', 'fsl'] = voxToScaledVoxMat
affines['fsl', 'voxel'] = transform.invert(voxToScaledVoxMat)
affines['fsl', 'world'] = transform.concat(affines['voxel', 'world'],
affines['fsl', 'voxel'])
affines['world', 'fsl'] = transform.concat(affines['voxel', 'fsl'],
affines['world', 'voxel'])
affines['fsl', 'voxel'] = affine.invert(voxToScaledVoxMat)
affines['fsl', 'world'] = affine.concat(affines['voxel', 'world'],
affines['fsl', 'voxel'])
affines['world', 'fsl'] = affine.concat(affines['voxel', 'fsl'],
affines['world', 'voxel'])
return affines, isneuro
......
......@@ -33,9 +33,9 @@ import collections
import os.path as op
import numpy as np
import fsl.utils.meta as meta
import fsl.utils.notifier as notifier
import fsl.transform as transform
import fsl.utils.meta as meta
import fsl.utils.notifier as notifier
import fsl.transform.affine as affine
log = logging.getLogger(__name__)
......@@ -693,7 +693,7 @@ def calcFaceNormals(vertices, indices):
v2 = vertices[indices[:, 2]]
fnormals = np.cross((v1 - v0), (v2 - v0))
fnormals = transform.normalise(fnormals)
fnormals = affine.normalise(fnormals)
return fnormals
......@@ -724,7 +724,7 @@ def calcVertexNormals(vertices, indices, fnormals):
vnormals[v2, :] += fnormals[i]
# normalise to unit length
return transform.normalise(vnormals)
return affine.normalise(vnormals)
def needsFixing(vertices, indices, fnormals, loBounds, hiBounds):
......@@ -769,4 +769,4 @@ def needsFixing(vertices, indices, fnormals, loBounds, hiBounds):
# vertex to the camera is positive
# If it isn't, we need to flip the
# triangle winding order.
return np.dot(n, transform.normalise(camera - vert)) < 0
return np.dot(n, affine.normalise(camera - vert)) < 0
......@@ -14,9 +14,9 @@ import os.path as op
import six
import nibabel as nib
import fsl.utils.path as fslpath
import fsl.transform as transform
import fsl.data.image as fslimage
import fsl.utils.path as fslpath
import fsl.transform.affine as affine
import fsl.data.image as fslimage
ALLOWED_EXTENSIONS = ['.mgz', '.mgh']
......@@ -55,12 +55,12 @@ class MGHImage(fslimage.Image):
filename = None
data = image.get_data()
affine = image.affine
xform = image.affine
vox2surf = image.header.get_vox2ras_tkr()
fslimage.Image.__init__(self,
data,
xform=affine,
xform=xform,
name=name,
dataSource=filename)
......@@ -68,9 +68,9 @@ class MGHImage(fslimage.Image):
self.setMeta('mghImageFile', filename)
self.__voxToSurfMat = vox2surf
self.__surfToVoxMat = transform.invert(vox2surf)
self.__surfToWorldMat = transform.concat(affine, self.__surfToVoxMat)
self.__worldToSurfMat = transform.invert(self.__surfToWorldMat)
self.__surfToVoxMat = affine.invert(vox2surf)
self.__surfToWorldMat = affine.concat(affine, self.__surfToVoxMat)
self.__worldToSurfMat = affine.invert(self.__surfToWorldMat)
def save(self, filename=None):
......
......@@ -6,41 +6,14 @@
# Author: Paul McCarthy <pauldmccarthy@gmail.com>
#
"""This module contains functions for working with linear and non-linear FSL
transformations.
"""
from .affine import ( # noqa
invert,
concat,
veclength,
normalise,
scaleOffsetXform,
compose,
decompose,
rotMatToAffine,
rotMatToAxisAngles,
axisAnglesToRotMat,
axisBounds,
transform,
transformNormal,
rmsdev)
transformations. Functionality is split across the following modules:
from .flirt import ( # noqa
readFlirt,
writeFlirt,
fromFlirt,
toFlirt,
flirtMatrixToSform,
sformToFlirtMatrix)
.. autosummary::
:nosignatures:
from .fnirt import ( # noqa
readFnirt,
toFnirt,
fromFnirt)
from .x5 import ( # noqa
readLinearX5,
writeLinearX5,
readNonLinearX5,
writeNonLinearX5)
.affine
.flirt
.fnirt
.nonlinear
.x5
"""
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment