Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
fslpy
Commits
e8501fc8
Commit
e8501fc8
authored
May 27, 2022
by
Paul McCarthy
🚵
Browse files
RF: Force-load image data when a fancy slice object is used
parent
432d73be
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/data/image.py
View file @
e8501fc8
...
...
@@ -1068,7 +1068,7 @@ class Image(Nifti):
Internally, the image data is managed using one of the following methods:
1. For read-only access, the ``Image`` class delegates
entirely
to the
1. For read-only access, the ``Image`` class delegates to the
underlying ``nibabel.Nifti1Image`` instance, accessing the data
via the ``Nifti1Image.dataobj`` attribute. Refer to
https://nipy.org/nibabel/nibabel_images.html#the-image-data-array for
...
...
@@ -1081,7 +1081,13 @@ class Image(Nifti):
the underlying ``nibabel.Nifti1Image`` object (refer to
https://nipy.org/nibabel/images_and_memory.html)
3. For more complicated requirements, a :class:`DataManager`,
3. The ``nibabel.Nifti1Image`` class does not support indexing of image
data with boolean mask arrays (e.g. ``image[mask > 0]``). If an
attempt is made to access image data in this way, the ``Image`` class
will be loaded into memory in the same way as described in point 2
above.
4. For more complicated requirements, a :class:`DataManager`,
implementing custom data access management logic, can be provided when
an ``Image`` is created. If a ``DataManager``is provided, an
internal reference to the data (see 2 above) will **not** be created or
...
...
@@ -1603,6 +1609,17 @@ class Image(Nifti):
expNdims
,
expShape
=
expectedShape
(
slc
,
shape
)
slc
=
canonicalSliceObj
(
slc
,
realShape
)
# The nibabel arrayproxy does not support
# boolean mask-based (a.k.a. "fancy")
# indexing. If we are given a mask, we
# force-load the image data into memory.
if
all
((
fancy
,
self
.
__dataMgr
is
None
,
self
.
__data
is
None
)):
log
.
debug
(
'Fancy slice detected - force-loading image '
'data into memory (%s)'
,
self
.
name
)
self
.
data
if
self
.
__dataMgr
is
not
None
:
data
=
self
.
__dataMgr
[
slc
]
elif
self
.
__data
is
not
None
:
data
=
self
.
__data
[
slc
]
else
:
data
=
self
.
__nibImage
.
dataobj
[
slc
]
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment