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
Model registry
Operate
Environments
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
FSL
fslpy
Commits
e4e92711
Commit
e4e92711
authored
8 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
ImageWrapper coverage is stored as a numpy array
parent
64862743
No related branches found
Branches containing commit
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
+44
-37
44 additions, 37 deletions
fsl/data/imagewrapper.py
with
44 additions
and
37 deletions
fsl/data/imagewrapper.py
+
44
−
37
View file @
e4e92711
...
@@ -92,28 +92,35 @@ class ImageWrapper(notifier.Notifier):
...
@@ -92,28 +92,35 @@ class ImageWrapper(notifier.Notifier):
# values).
# values).
self
.
__range
=
(
float
(
hdr
[
'
cal_min
'
]),
float
(
hdr
[
'
cal_max
'
]))
self
.
__range
=
(
float
(
hdr
[
'
cal_min
'
]),
float
(
hdr
[
'
cal_max
'
]))
# For each entry in the last (real) dimension of
# The coverage array is used to keep track of
# the image (slice for 3D or volume for 4D), we
# the portions of the image which have been
# record the portions of the image that have
# considered in the data range calculation.
# been included in the data range calculation, so
# We use this coverage to avoid unnecessarily
# we do not unnecessarily re-calculate ranges on
# re-calculating the data range on the same
# the same part of the image.
# part of the image.
self
.
__coverage
=
[]
#
# First of all, we're going to store a separate
# TODO Use a numpy array of size
# 'coverage' for each 2D slice in the 3D image
# (2, [numRealDims - 1], [shape[numRealDims - 1]])
# (or 3D volume for 4D images). This effectively
# instead of a list of lists
# means a seaprate coverage for each index in the
# last 'real' image dimension (see above).
# This is a list of lists of (low, high) pairs,
#
# one list for each entry in the last dimension
# For each slice/volume, the the coverage is
# (e.g. one list per 2D slice or 3D volume), and
# stored as sequences of (low, high) indices, one
# one pair for each dimension in the entry (e.g.
# for each dimension in the slice/volume (e.g.
# row/column for each slice, or row/column/depth
# row/column for a slice, or row/column/depth
# for each volume).
# for a volume).
for
i
in
range
(
image
.
shape
[
self
.
__numRealDims
-
1
]):
#
# All of these indices are stored in a big numpy
# array:
# - 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
.
uint32
)
cov
=
[[
None
,
None
]
for
i
in
range
(
self
.
__numRealDims
-
1
)]
self
.
__coverage
[:]
=
np
.
nan
self
.
__coverage
.
append
(
cov
)
if
loadData
:
if
loadData
:
self
.
loadData
()
self
.
loadData
()
...
@@ -207,7 +214,8 @@ class ImageWrapper(notifier.Notifier):
...
@@ -207,7 +214,8 @@ class ImageWrapper(notifier.Notifier):
self
.
__range
=
(
newmin
,
newmax
)
self
.
__range
=
(
newmin
,
newmax
)
for
vol
,
exp
in
zip
(
volumes
,
expansions
):
for
vol
,
exp
in
zip
(
volumes
,
expansions
):
self
.
__coverage
[
vol
]
=
adjustCoverage
(
self
.
__coverage
[
vol
],
exp
)
self
.
__coverage
[...,
vol
]
=
adjustCoverage
(
self
.
__coverage
[...,
vol
],
exp
)
# TODO floating point error
# TODO floating point error
if
newmin
!=
oldmin
or
newmax
!=
oldmax
:
if
newmin
!=
oldmin
or
newmax
!=
oldmax
:
...
@@ -310,25 +318,28 @@ def adjustCoverage(oldCoverage, slices):
...
@@ -310,25 +318,28 @@ def adjustCoverage(oldCoverage, slices):
"""
Adjusts/expands the given ``oldCoverage`` so that it covers the
"""
Adjusts/expands the given ``oldCoverage`` so that it covers the
given set of ``slices``.
given set of ``slices``.
:arg oldCoverage: A sequence of (low, high) index pairs
:arg oldCoverage: A ``numpy`` array of shape ``(2, n)`` containing
the (low, high) index pairs for a single slice/volume
in the image.
:arg slices: A sequence of (low, high) index pairs. If ``slices``
:arg slices: A sequence of (low, high) index pairs. If ``slices``
contains more dimensions than are specified in
contains more dimensions than are specified in
``oldCoverage``, the trailing dimensions are ignored.
``oldCoverage``, the trailing dimensions are ignored.
:return: A
list of (low, high) tuples
containing the adjusted coverage.
:return: A
``numpy`` array
containing the adjusted
/expanded
coverage.
"""
"""
newCoverage
=
[]
newCoverage
=
np
.
zeros
(
oldCoverage
.
shape
,
dtype
=
np
.
uint32
)
for
dim
in
range
(
len
(
oldCoverage
)
):
for
dim
in
range
(
oldCoverage
.
shape
[
1
]
):
low
,
high
=
slices
[
dim
]
low
,
high
=
slices
[
dim
]
lowCover
,
highCover
=
oldCoverage
[
dim
]
lowCover
,
highCover
=
oldCoverage
[
:,
dim
]
if
lowCover
is
None
or
low
<
lowCover
:
lowCover
=
low
if
lowCover
is
None
or
low
<
lowCover
:
lowCover
=
low
if
highCover
is
None
or
high
>
highCover
:
highCover
=
high
if
highCover
is
None
or
high
>
highCover
:
highCover
=
high
newCoverage
.
append
((
lowCover
,
highCover
))
newCoverage
[:,
dim
]
=
lowCover
,
highCover
return
newCoverage
return
newCoverage
...
@@ -348,17 +359,14 @@ def sliceCovered(slices, coverage, shape, realDims):
...
@@ -348,17 +359,14 @@ def sliceCovered(slices, coverage, shape, realDims):
for
vol
in
range
(
lowVol
,
highVol
):
for
vol
in
range
(
lowVol
,
highVol
):
volCoverage
=
coverage
[
vol
]
for
dim
,
size
in
enumerate
(
shape
):
for
dim
,
size
in
enumerate
(
shape
):
lowCover
,
highCover
=
volCoverage
[
dim
]
lowCover
,
highCover
=
coverage
[:,
dim
,
vol
]
lowSlice
,
highSlice
=
slices
[
dim
]
if
lowCover
is
None
or
highCover
is
None
:
if
lowCover
is
None
or
highCover
is
None
:
return
False
return
False
lowSlice
,
highSlice
=
slices
[
dim
]
if
lowSlice
is
None
:
lowSlice
=
0
if
lowSlice
is
None
:
lowSlice
=
0
if
highSlice
is
None
:
highSlice
=
size
if
highSlice
is
None
:
highSlice
=
size
...
@@ -383,12 +391,11 @@ def calcSliceExpansion(slices, coverage, realDims, padDims):
...
@@ -383,12 +391,11 @@ def calcSliceExpansion(slices, coverage, realDims, padDims):
for
vol
in
volumes
:
for
vol
in
volumes
:
volCoverage
=
coverage
[
vol
]
expansion
=
[]
expansion
=
[]
for
dim
in
range
(
realDims
-
1
):
for
dim
in
range
(
realDims
-
1
):
lowCover
,
highCover
=
volC
overage
[
dim
]
lowCover
,
highCover
=
c
overage
[
:,
dim
,
vol
]
lowSlice
,
highSlice
=
slices
[
dim
]
lowSlice
,
highSlice
=
slices
[
dim
]
if
lowCover
is
None
:
lowCover
=
lowSlice
if
lowCover
is
None
:
lowCover
=
lowSlice
...
...
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