Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
28a64c40
Commit
28a64c40
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: New affine.identify function, for figuring out what an affine
encodes. Might be moved to a different location
parent
f6111f9f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/transform/affine.py
+55
-0
55 additions, 0 deletions
fsl/transform/affine.py
with
55 additions
and
0 deletions
fsl/transform/affine.py
+
55
−
0
View file @
28a64c40
...
...
@@ -21,6 +21,7 @@ transformations. The following functions are available:
axisAnglesToRotMat
axisBounds
rmsdev
identify
And a few more functions are provided for working with vectors:
...
...
@@ -582,3 +583,57 @@ def rmsdev(T1, T2, R=None, xc=None):
erms
=
np
.
sqrt
(
erms
)
return
erms
def
identify
(
image
,
xform
,
from_
=
None
,
to
=
None
):
"""
Attempt to identify the source or destination space for the given
affine.
``xform`` is assumed to be an affine transformation which can be used
to transform coordinates between two coordinate systems associated with
``image``.
One of ``from_`` or ``to`` must be provided. Whichever is not provided
will be derived. See the :meth:`.Nifti.getAffine` method for details on
the valild values that ``from_`` and ``to`` may take.
:arg image: :class:`.Nifti` instance associated with the affine.
:arg xform: ``(4, 4)`` ``numpy`` array encoding an affine transformation
:arg from_: Label specifying the coordinate system which ``xform``
takes as input
:arg to: Label specifying the coordinate system which ``xform``
produces as output
:returns: A tuple containing:
- A label for the ``from_`` coordinate system
- A label for the ``to`` coordinate system
"""
if
(
from_
is
None
)
and
(
to
is
None
):
raise
ValueError
(
'
One of from_ or to must be provided
'
)
if
(
from_
is
not
None
)
and
(
to
is
not
None
):
return
from_
,
to
if
from_
is
None
:
voxel
=
image
.
getAffine
(
'
voxel
'
,
to
)
fsl
=
image
.
getAffine
(
'
fsl
'
,
to
)
world
=
image
.
getAffine
(
'
world
'
,
to
)
if
np
.
all
(
np
.
isclose
(
voxel
,
xform
)):
return
'
voxel
'
,
to
if
np
.
all
(
np
.
isclose
(
fsl
,
xform
)):
return
'
fsl
'
,
to
if
np
.
all
(
np
.
isclose
(
world
,
xform
)):
return
'
world
'
,
to
if
to
is
None
:
voxel
=
image
.
getAffine
(
from_
,
'
voxel
'
)
fsl
=
image
.
getAffine
(
from_
,
'
fsl
'
)
world
=
image
.
getAffine
(
from_
,
'
world
'
)
if
np
.
all
(
np
.
isclose
(
voxel
,
xform
)):
return
'
voxel
'
,
to
if
np
.
all
(
np
.
isclose
(
fsl
,
xform
)):
return
'
fsl
'
,
to
if
np
.
all
(
np
.
isclose
(
world
,
xform
)):
return
'
world
'
,
to
raise
ValueError
(
'
Could not identify affine
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment