Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Michiel Cottaar
fslpy
Commits
6d1802e6
Commit
6d1802e6
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
new transform function rmsdev for calculating distance between two
transformations
parent
9bcb32c6
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/utils/transform.py
+47
-0
47 additions, 0 deletions
fsl/utils/transform.py
with
47 additions
and
0 deletions
fsl/utils/transform.py
+
47
−
0
View file @
6d1802e6
...
...
@@ -23,6 +23,7 @@ spaces. The following functions are provided:
axisBounds
flirtMatrixToSform
sformToFlirtMatrix
rmsdev
And a few more functions are provided for working with vectors:
...
...
@@ -593,3 +594,49 @@ def sformToFlirtMatrix(srcImage, refImage, srcXform=None):
refWorldToVoxMat
,
srcVoxToWorldMat
,
srcScaledVoxToVoxMat
)
def
rmsdev
(
T1
,
T2
,
R
=
None
,
xc
=
None
):
"""
Calculates the RMS deviation of the given affine transforms ``T1`` and
``T2``. This can be used as a measure of the
'
distance
'
between two
affines.
The ``T1`` and ``T2`` arguments may be either full ``(4, 4)`` affines, or
``(3, 3)`` rotation matrices.
See FMRIB technical report TR99MJ1, available at:
https://www.fmrib.ox.ac.uk/datasets/techrep/
:arg T1: First affine
:arg T2: Second affine
:arg R: Sphere radius
:arg xc: Sphere centre
:returns: The RMS deviation between ``T1`` and ``T2``.
"""
if
R
is
None
:
R
=
1
if
xc
is
None
:
xc
=
np
.
zeros
(
3
)
# rotations only
if
T1
.
shape
==
(
3
,
3
):
M
=
np
.
dot
(
T2
,
invert
(
T1
))
-
np
.
eye
(
3
)
A
=
M
[:
3
,
:
3
]
t
=
np
.
zeros
(
3
)
# full affine
else
:
M
=
np
.
dot
(
T2
,
invert
(
T1
))
-
np
.
eye
(
4
)
A
=
M
[:
3
,
:
3
]
t
=
M
[:
3
,
3
]
Axc
=
np
.
dot
(
A
,
xc
)
erms
=
np
.
dot
((
t
+
Axc
).
T
,
t
+
Axc
)
erms
=
0.2
*
R
**
2
*
np
.
dot
(
A
.
T
,
A
).
trace
()
+
erms
erms
=
np
.
sqrt
(
erms
)
return
erms
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