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
31c3b7af
Commit
31c3b7af
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
BF: Fix resampling matrix for higher dimensions
parent
92466953
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/image/resample.py
+31
-3
31 additions, 3 deletions
fsl/utils/image/resample.py
with
31 additions
and
3 deletions
fsl/utils/image/resample.py
+
31
−
3
View file @
31c3b7af
...
...
@@ -45,15 +45,43 @@ def resampleToReference(image, reference, **kwargs):
This is a wrapper around :func:`resample` - refer to its documenttion
for details on the other arguments and the return values.
When resampling to a reference image, resampling will only be applied
along the spatial (first three) dimensions.
:arg image: :class:`.Image` to resample
:arg reference: :class:`.Nifti` defining the space to resample ``image``
into
"""
oldShape
=
list
(
image
.
shape
)
newShape
=
list
(
reference
.
shape
[:
3
])
# If the input image is >3D, pad the
# new shape so that we only resample
# along the first 3 dimensions.
if
len
(
newShape
)
<
len
(
oldShape
):
newShape
=
newShape
+
oldShape
[
len
(
newShape
):]
# Align the two images together
# via their vox-to-world affines.
matrix
=
transform
.
concat
(
image
.
worldToVoxMat
,
reference
.
voxToWorldMat
)
# If the input image is >3D, we
# have to adjust the resampling
# matrix to take into account the
# additional dimensions (see scipy.
# ndimage.affine_transform)
if
len
(
newShape
)
>
3
:
rotmat
=
matrix
[:
3
,
:
3
]
offsets
=
matrix
[:
3
,
3
]
matrix
=
np
.
eye
(
len
(
newShape
)
+
1
)
matrix
[:
3
,
:
3
]
=
rotmat
matrix
[:
3
,
-
1
]
=
offsets
kwargs
[
'
mode
'
]
=
kwargs
.
get
(
'
mode
'
,
'
constant
'
)
kwargs
[
'
newShape
'
]
=
reference
.
s
hape
kwargs
[
'
matrix
'
]
=
transform
.
concat
(
image
.
worldToVoxMat
,
reference
.
voxToWorldMat
)
kwargs
[
'
newShape
'
]
=
newS
hape
kwargs
[
'
matrix
'
]
=
matrix
return
resample
(
image
,
**
kwargs
)
...
...
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