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
8f758af8
Commit
8f758af8
authored
1 year ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ENH: New afffine.flip function; make scaleOffsetXform args optional
parent
1dbb17d1
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
+39
-1
39 additions, 1 deletion
fsl/transform/affine.py
with
39 additions
and
1 deletion
fsl/transform/affine.py
+
39
−
1
View file @
8f758af8
...
...
@@ -13,6 +13,7 @@ transformations. The following functions are available:
transform
scaleOffsetXform
invert
flip
concat
compose
decompose
...
...
@@ -79,7 +80,41 @@ def normalise(vec):
return
n
def
scaleOffsetXform
(
scales
,
offsets
):
def
flip
(
shape
,
xform
,
*
axes
):
"""
Applies a flip/inversion to an affine transform along specified axes.
:arg shape: The ``(x, y, z)`` shape of the data.
:arg xform: Transformation matrix which transforms voxel coordinates
to a world coordinate system.
:arg axes: Indices of axes to flip
"""
if
len
(
axes
)
==
0
:
return
xform
axes
=
sorted
(
set
(
axes
))
if
any
(
a
not
in
(
0
,
1
,
2
)
for
a
in
axes
):
raise
ValueError
(
f
'
Invalid axis:
{
axes
}
'
)
los
,
his
=
axisBounds
(
shape
,
xform
,
axes
)
scales
=
[
1
,
1
,
1
]
pre
=
[
0
,
0
,
0
]
post
=
[
0
,
0
,
0
]
for
ax
,
lo
,
hi
in
zip
(
axes
,
los
,
his
):
mid
=
lo
+
(
hi
-
lo
)
/
2
scales
[
ax
]
=
-
1
pre
[
ax
]
=
-
mid
post
[
ax
]
=
mid
pre
=
scaleOffsetXform
(
None
,
pre
)
post
=
scaleOffsetXform
(
None
,
post
)
scales
=
scaleOffsetXform
(
scales
)
return
concat
(
post
,
scales
,
pre
,
xform
)
def
scaleOffsetXform
(
scales
=
None
,
offsets
=
None
):
"""
Creates and returns an affine transformation matrix which encodes
the specified scale(s) and offset(s).
...
...
@@ -95,6 +130,9 @@ def scaleOffsetXform(scales, offsets):
:returns: A ``numpy.float32`` array of size :math:`4
\\
times 4`.
"""
if
scales
is
None
:
scales
=
[
1
,
1
,
1
]
if
offsets
is
None
:
offsets
=
[
0
,
0
,
0
]
oktypes
=
(
abc
.
Sequence
,
np
.
ndarray
)
if
not
isinstance
(
scales
,
oktypes
):
scales
=
[
scales
]
...
...
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