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
d637e26b
Commit
d637e26b
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ImageWrapper has a reset method which does initialisation stuff.
parent
414f8793
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/imagewrapper.py
+82
-52
82 additions, 52 deletions
fsl/data/imagewrapper.py
with
82 additions
and
52 deletions
fsl/data/imagewrapper.py
+
82
−
52
View file @
d637e26b
...
@@ -88,20 +88,9 @@ class ImageWrapper(notifier.Notifier):
...
@@ -88,20 +88,9 @@ class ImageWrapper(notifier.Notifier):
array proxy).
array proxy).
:arg dataRange: A tuple containing the initial ``(min, max)`` data
:arg dataRange: A tuple containing the initial ``(min, max)`` data
range to use.
range to use. See the :meth:`reset` method.
.. note:: The ``dataRange`` parameter is intended for situations where
the image data range is known (e.g. it was calculated
earlier, and the image is being re-loaded. If a
``dataRange`` is passed in, it will *not* be overwritten by
any range calculated from the data, unless the calculated
data range is wider than the provided ``dataRange``.
"""
"""
if
dataRange
is
None
:
dataRange
=
None
,
None
self
.
__image
=
image
self
.
__image
=
image
self
.
__name
=
name
self
.
__name
=
name
...
@@ -117,6 +106,86 @@ class ImageWrapper(notifier.Notifier):
...
@@ -117,6 +106,86 @@ class ImageWrapper(notifier.Notifier):
# 'padding' dimensions too.
# 'padding' dimensions too.
self
.
__numPadDims
=
len
(
image
.
shape
)
-
self
.
__numRealDims
self
.
__numPadDims
=
len
(
image
.
shape
)
-
self
.
__numRealDims
# The internal state is stored
# in these attributes - they're
# initialised in the reset method.
self
.
__range
=
None
self
.
__coverage
=
None
self
.
__volRanges
=
None
self
.
__covered
=
False
self
.
reset
(
dataRange
)
if
loadData
:
self
.
loadData
()
@property
def
dataRange
(
self
):
"""
Returns the currently known data range as a tuple of ``(min, max)``
values.
"""
# If no image data has been accessed, we
# default to whatever is stored in the
# header (which may or may not contain
# useful values).
low
,
high
=
self
.
__range
hdr
=
self
.
__image
.
get_header
()
if
low
is
None
:
low
=
float
(
hdr
[
'
cal_min
'
])
if
high
is
None
:
high
=
float
(
hdr
[
'
cal_max
'
])
return
low
,
high
@property
def
covered
(
self
):
"""
Returns ``True`` if this ``ImageWrapper`` has read the entire
image data, ``False`` otherwise.
"""
return
self
.
__covered
def
loadData
(
self
):
"""
Forces all of the image data to be loaded into memory.
.. note:: This method will be called by :meth:`__init__` if its
``loadData`` parameter is ``True``.
"""
# If the data is not already loaded, this will
# cause nibabel to load it. By default, nibabel
# will cache the numpy array that contains the
# image data, so subsequent calls to this
# method will not overwrite any changes that
# have been made to the data.
self
.
__image
.
get_data
()
def
reset
(
self
,
dataRange
=
None
):
"""
Reset the internal state and known data range of this
``ImageWrapper``.
:arg dataRange: A tuple containing the initial ``(min, max)`` data
range to use. See the :meth:`reset` method.
.. note:: The ``dataRange`` parameter is intended for situations where
the image data range is known (e.g. it was calculated
earlier, and the image is being re-loaded. If a
``dataRange`` is passed in, it will *not* be overwritten by
any range calculated from the data, unless the calculated
data range is wider than the provided ``dataRange``.
"""
if
dataRange
is
None
:
dataRange
=
None
,
None
image
=
self
.
__image
ndims
=
self
.
__numRealDims
-
1
nvols
=
image
.
shape
[
self
.
__numRealDims
-
1
]
# The current known image data range. This
# The current known image data range. This
# gets updated as more image data gets read.
# gets updated as more image data gets read.
self
.
__range
=
dataRange
self
.
__range
=
dataRange
...
@@ -143,9 +212,7 @@ class ImageWrapper(notifier.Notifier):
...
@@ -143,9 +212,7 @@ class ImageWrapper(notifier.Notifier):
# All of these indices are stored in a numpy array:
# All of these indices are stored in a numpy array:
# - first dimension: low/high index
# - first dimension: low/high index
# - second dimension: image dimension
# - second dimension: image dimension
# - third dimension: slice/volume index
# - third dimension: slice/volume index
ndims
=
self
.
__numRealDims
-
1
nvols
=
image
.
shape
[
self
.
__numRealDims
-
1
]
self
.
__coverage
=
np
.
zeros
((
2
,
ndims
,
nvols
),
dtype
=
np
.
float32
)
self
.
__coverage
=
np
.
zeros
((
2
,
ndims
,
nvols
),
dtype
=
np
.
float32
)
# Internally, we calculate and store the
# Internally, we calculate and store the
...
@@ -160,43 +227,6 @@ class ImageWrapper(notifier.Notifier):
...
@@ -160,43 +227,6 @@ class ImageWrapper(notifier.Notifier):
# (i.e. when all data has been loaded in).
# (i.e. when all data has been loaded in).
self
.
__covered
=
False
self
.
__covered
=
False
if
loadData
:
self
.
loadData
()
@property
def
dataRange
(
self
):
"""
Returns the currently known data range as a tuple of ``(min, max)``
values.
"""
# If no image data has been accessed, we
# default to whatever is stored in the
# header (which may or may not contain
# useful values).
low
,
high
=
self
.
__range
hdr
=
self
.
__image
.
get_header
()
if
low
is
None
:
low
=
float
(
hdr
[
'
cal_min
'
])
if
high
is
None
:
high
=
float
(
hdr
[
'
cal_max
'
])
return
low
,
high
def
loadData
(
self
):
"""
Forces all of the image data to be loaded into memory.
.. note:: This method will be called by :meth:`__init__` if its
``loadData`` parameter is ``True``.
"""
# If the data is not already loaded, this will
# cause nibabel to load it. By default, nibabel
# will cache the numpy array that contains the
# image data, so subsequent calls to this
# method will not overwrite any changes that
# have been made to the data.
self
.
__image
.
get_data
()
def
__getData
(
self
,
sliceobj
,
isTuple
=
False
):
def
__getData
(
self
,
sliceobj
,
isTuple
=
False
):
"""
Retrieves the image data at the location specified by ``sliceobj``.
"""
Retrieves the image data at the location specified by ``sliceobj``.
...
...
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