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
414f8793
Commit
414f8793
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ImageWrapper now stores per-volume data ranges. Will make write support easier.
parent
b1bf0229
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
+34
-14
34 additions, 14 deletions
fsl/data/imagewrapper.py
with
34 additions
and
14 deletions
fsl/data/imagewrapper.py
+
34
−
14
View file @
414f8793
...
...
@@ -144,11 +144,16 @@ class ImageWrapper(notifier.Notifier):
# - first dimension: low/high index
# - second dimension: image dimension
# - third dimension: slice/volume index
self
.
__coverage
=
np
.
zeros
(
(
2
,
self
.
__numRealDims
-
1
,
image
.
shape
[
self
.
__numRealDims
-
1
]
),
dtype
=
np
.
float32
)
ndims
=
self
.
__numRealDims
-
1
nvols
=
image
.
shape
[
self
.
__numRealDims
-
1
]
self
.
__coverage
=
np
.
zeros
((
2
,
ndims
,
nvols
),
dtype
=
np
.
float32
)
self
.
__coverage
[:]
=
np
.
nan
# Internally, we calculate and store the
# data range for each volume/slice/vector
self
.
__volRanges
=
np
.
zeros
((
nvols
,
2
),
dtype
=
np
.
float32
)
self
.
__coverage
[
:]
=
np
.
nan
self
.
__volRanges
[:]
=
np
.
nan
# This flag is set to true if/when the
# full image data range becomes known
...
...
@@ -164,9 +169,10 @@ class ImageWrapper(notifier.Notifier):
"""
Returns the currently known data range as a tuple of ``(min, max)``
values.
"""
# If no image data has been read, we default
# to whatever is stored in the header (which
# may or may not contain useful 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
()
...
...
@@ -239,21 +245,35 @@ class ImageWrapper(notifier.Notifier):
oldmin
,
oldmax
=
self
.
__range
newmin
,
newmax
=
oldmin
,
oldmax
# The calcExpansion function splits up the
# expansions on volumes - here we calculate
# the min/max per volume/expansion, and
# iteratively update the stored per-volume
# coverage and data range.
for
vol
,
exp
in
zip
(
volumes
,
expansions
):
data
=
self
.
__getData
(
exp
,
isTuple
=
True
)
dmin
=
float
(
np
.
nanmin
(
data
))
dmax
=
float
(
np
.
nanmax
(
data
))
oldmin
,
oldmax
=
self
.
__volRanges
[
vol
,
:]
if
newmin
is
None
or
dmin
<
newmin
:
newmin
=
dmin
if
newmax
is
None
or
dmax
>
newmax
:
newmax
=
dmax
data
=
self
.
__getData
(
exp
,
isTuple
=
True
)
newmin
=
float
(
np
.
nanmin
(
data
))
newmax
=
float
(
np
.
nanmax
(
data
))
self
.
__range
=
(
newmin
,
newmax
)
if
(
not
np
.
isnan
(
oldmin
))
and
oldmin
<
newmin
:
newmin
=
oldmin
if
(
not
np
.
isnan
(
oldmax
))
and
oldmax
>
newmax
:
newmax
=
oldmax
for
vol
,
exp
in
zip
(
volumes
,
expansions
):
# Update the stored range and
# coverage for each volume
self
.
__volRanges
[
vol
,
:]
=
newmin
,
newmax
self
.
__coverage
[...,
vol
]
=
adjustCoverage
(
self
.
__coverage
[...,
vol
],
exp
)
# Calculate the new known data
# range over the entire image
# (i.e. over all volumes).
newmin
=
np
.
nanmin
(
self
.
__volRanges
[:,
0
])
newmax
=
np
.
nanmax
(
self
.
__volRanges
[:,
1
])
self
.
__range
=
(
newmin
,
newmax
)
self
.
__covered
=
self
.
__imageIsCovered
()
# TODO floating point error
...
...
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