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
Package Registry
Model registry
Operate
Environments
Terraform modules
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
Evan Edmond
fslpy
Commits
6ef44e19
Commit
6ef44e19
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Fix to Nifti1 handling of images with unknown qform/sform codes.
parent
19a30365
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/data/image.py
+32
-8
32 additions, 8 deletions
fsl/data/image.py
with
32 additions
and
8 deletions
fsl/data/image.py
+
32
−
8
View file @
6ef44e19
...
@@ -95,6 +95,23 @@ class Nifti1(object):
...
@@ -95,6 +95,23 @@ class Nifti1(object):
if
len
(
shape
)
<
3
or
len
(
shape
)
>
4
:
if
len
(
shape
)
<
3
or
len
(
shape
)
>
4
:
raise
RuntimeError
(
'
Only 3D or 4D images are supported
'
)
raise
RuntimeError
(
'
Only 3D or 4D images are supported
'
)
voxToWorldMat
=
self
.
__determineTransform
(
header
)
worldToVoxMat
=
transform
.
invert
(
voxToWorldMat
)
self
.
header
=
header
self
.
shape
=
shape
self
.
__origShape
=
origShape
self
.
pixdim
=
pixdim
self
.
voxToWorldMat
=
voxToWorldMat
self
.
worldToVoxMat
=
worldToVoxMat
def
__determineTransform
(
self
,
header
):
"""
Called by :meth:`__init__`. Figures out the voxel-to-world
coordinate transformation matrix that is associated with this
``Nifti1`` instance.
"""
# We have to treat FSL/FNIRT images
# We have to treat FSL/FNIRT images
# specially, as FNIRT clobbers the
# specially, as FNIRT clobbers the
# sform section of the NIFTI header
# sform section of the NIFTI header
...
@@ -106,19 +123,26 @@ class Nifti1(object):
...
@@ -106,19 +123,26 @@ class Nifti1(object):
log
.
debug
(
'
FNIRT output image detected - using qform matrix
'
)
log
.
debug
(
'
FNIRT output image detected - using qform matrix
'
)
voxToWorldMat
=
np
.
array
(
header
.
get_qform
())
voxToWorldMat
=
np
.
array
(
header
.
get_qform
())
# If the qform or sform codes are unknown,
# then we can't assume that the transform
# matrices are valid. So we fall back to a
# pixdim scaling matrix.
#
# n.b. For images like this, nibabel returns
# a scaling matrix where the centre voxel
# corresponds to world location (0, 0, 0).
# This goes against the NIFTI1 spec - it
# should just be a straight scaling matrix.
elif
header
[
'
qform_code
'
]
==
0
or
header
[
'
sform_code
'
]
==
0
:
pixdims
=
header
.
get_zooms
()
voxToWorldMat
=
transform
.
scaleOffsetXform
(
pixdims
,
0
)
# Otherwise we let nibabel decide
# Otherwise we let nibabel decide
# which transform to use.
# which transform to use.
else
:
else
:
voxToWorldMat
=
np
.
array
(
header
.
get_best_affine
())
voxToWorldMat
=
np
.
array
(
header
.
get_best_affine
())
worldToVoxMat
=
transform
.
invert
(
voxToWorldMat
)
return
voxToWorldMat
self
.
header
=
header
self
.
shape
=
shape
self
.
__origShape
=
origShape
self
.
pixdim
=
pixdim
self
.
voxToWorldMat
=
voxToWorldMat
self
.
worldToVoxMat
=
worldToVoxMat
def
__determineShape
(
self
,
header
):
def
__determineShape
(
self
,
header
):
...
...
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