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
9924ee86
Commit
9924ee86
authored
5 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
RF: Changed shape.affine generation methods to be staticmethods, as they may
be useful outside of the Nifti class (for testing, at least)
parent
0b1b35bb
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
+25
-11
25 additions, 11 deletions
fsl/data/image.py
with
25 additions
and
11 deletions
fsl/data/image.py
+
25
−
11
View file @
9924ee86
...
...
@@ -244,7 +244,7 @@ class Nifti(notifier.Notifier, meta.Meta):
raise
ValueError
(
'
Unrecognised header: {}
'
.
format
(
header
))
header
=
header
origShape
,
shape
,
pixdim
=
self
.
__
determineShape
(
header
)
origShape
,
shape
,
pixdim
=
Nifti
.
determineShape
(
header
)
self
.
header
=
header
self
.
__shape
=
shape
...
...
@@ -253,14 +253,15 @@ class Nifti(notifier.Notifier, meta.Meta):
self
.
__intent
=
header
.
get
(
'
intent_code
'
,
constants
.
NIFTI_INTENT_NONE
)
voxToWorldMat
=
self
.
__
determineAffine
(
header
)
affines
,
isneuro
=
self
.
__
generateAffines
(
voxToWorldMat
)
voxToWorldMat
=
Nifti
.
determineAffine
(
header
)
affines
,
isneuro
=
Nifti
.
generateAffines
(
voxToWorldMat
,
shape
,
pixdim
)
self
.
__affines
=
affines
self
.
__isNeurological
=
isneuro
def
__determineShape
(
self
,
header
):
@staticmethod
def
determineShape
(
header
):
"""
This method is called by :meth:`__init__`. It figures out the actual
shape of the image data, and the zooms/pixdims for each data axis. Any
empty trailing dimensions are squeezed, but the returned shape is
...
...
@@ -287,10 +288,17 @@ class Nifti(notifier.Notifier, meta.Meta):
pixdims
=
pixdims
[:
len
(
shape
)]
# should never happen, but if we only
# have zoom values for the original
# (< 3D) shape, pad them with 1s.
if
len
(
pixdims
)
<
len
(
shape
):
pixdims
=
pixdims
+
[
1
]
*
(
len
(
shape
)
-
len
(
pixdims
))
return
origShape
,
shape
,
pixdims
def
__determineAffine
(
self
,
header
):
@staticmethod
def
determineAffine
(
header
):
"""
Called by :meth:`__init__`. Figures out the voxel-to-world
coordinate transformation matrix that is associated with this
``Nifti`` instance.
...
...
@@ -333,7 +341,8 @@ class Nifti(notifier.Notifier, meta.Meta):
return
voxToWorldMat
def
__generateAffines
(
self
,
voxToWorldMat
):
@staticmethod
def
generateAffines
(
voxToWorldMat
,
shape
,
pixdim
):
"""
Called by :meth:`__init__`, and the :meth:`voxToWorldMat` setter.
Generates and returns a dictionary containing affine transformations
between the ``voxel``, ``fsl``, and ``world`` coordinate
...
...
@@ -341,6 +350,9 @@ class Nifti(notifier.Notifier, meta.Meta):
method.
:arg voxToWorldMat: The voxel-to-world affine transformation
:arg shape: Image shape (number of voxels along each dimension
:arg pixdim: Image pixdims (size of one voxel along each
dimension)
:returns: A tuple containing:
- a dictionary of affine transformations between
...
...
@@ -353,8 +365,8 @@ class Nifti(notifier.Notifier, meta.Meta):
import
numpy.linalg
as
npla
affines
=
{}
shape
=
list
(
self
.
shape
[
:
3
])
pixdim
=
list
(
self
.
pixdim
[:
3
])
shape
=
list
(
shape
[
:
3
])
pixdim
=
list
(
pixdim
[:
3
])
voxToScaledVoxMat
=
np
.
diag
(
pixdim
+
[
1.0
])
isneuro
=
npla
.
det
(
voxToWorldMat
)
>
0
...
...
@@ -370,8 +382,8 @@ class Nifti(notifier.Notifier, meta.Meta):
affines
[
'
fsl
'
,
'
voxel
'
]
=
transform
.
invert
(
voxToScaledVoxMat
)
affines
[
'
fsl
'
,
'
world
'
]
=
transform
.
concat
(
affines
[
'
voxel
'
,
'
world
'
],
affines
[
'
fsl
'
,
'
voxel
'
])
affines
[
'
world
'
,
'
fsl
'
]
=
transform
.
concat
(
affines
[
'
fs
l
'
,
'
voxe
l
'
],
affines
[
'
voxel
'
,
'
world
'
])
affines
[
'
world
'
,
'
fsl
'
]
=
transform
.
concat
(
affines
[
'
voxe
l
'
,
'
fs
l
'
],
affines
[
'
world
'
,
'
voxel
'
])
return
affines
,
isneuro
...
...
@@ -546,7 +558,9 @@ class Nifti(notifier.Notifier, meta.Meta):
header
.
set_sform
(
xform
,
code
=
sformCode
)
affines
,
isneuro
=
self
.
__generateAffines
(
xform
)
affines
,
isneuro
=
Nifti
.
generateAffines
(
xform
,
self
.
shape
,
self
.
pixdim
)
self
.
__affines
=
affines
self
.
__isNeurological
=
isneuro
...
...
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