Skip to content
Snippets Groups Projects
Commit 9c4ce29a authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Image.calcRange thresholding is done on bytes, not voxels.

parent 0e37bd43
No related branches found
No related tags found
No related merge requests found
...@@ -531,31 +531,44 @@ class Image(Nifti1, notifier.Notifier): ...@@ -531,31 +531,44 @@ class Image(Nifti1, notifier.Notifier):
"""Forces calculation of the image data range. """Forces calculation of the image data range.
:arg sizethres: If not ``None``, specifies an image size threshold :arg sizethres: If not ``None``, specifies an image size threshold
(threshold on the number of values). If the number (total number of bytes). If the number of bytes in
of values in the image is greater than this threshold, the image is greater than this threshold, the range
the range is calculated on a sample (the first volume is calculated on a sample (the first volume for a
for a 4D image, or slice for a 3D image). 4D image, or slice for a 3D image).
""" """
# The ImageWrapper automatically calculates # The ImageWrapper automatically calculates
# the range of the specified slice, whenever # the range of the specified slice, whenever
# it gets indexed. All we have to do is # it gets indexed. All we have to do is
# access a portion of the data to trigger the # access a portion of the data to trigger the
# range calculation. # range calculation.
nbytes = np.prod(self.shape) * self.dtype.itemsize
# If an image size threshold has not been specified, # If an image size threshold has not been specified,
# then we'll calculate the full data range right now. # then we'll calculate the full data range right now.
if sizethres is None: if sizethres is None or nbytes < sizethres:
log.debug('{}: Forcing calculation of full '
'data range'.format(self.name))
self.__imageWrapper[:] self.__imageWrapper[:]
else:
log.debug('{}: Calculating data range '
'from sample'.format(self.name))
# Otherwise if the number of values in the # Otherwise if the number of values in the
# image is bigger than the size threshold, # image is bigger than the size threshold,
# we'll calculate the range from a sample: # we'll calculate the range from a sample:
elif np.prod(self.shape) < sizethres:
if len(self.shape) == 3: self.__imageWrapper[:, :, 0] if len(self.shape) == 3: self.__imageWrapper[:, :, 0]
else: self.__imageWrapper[:, :, :, 0] else: self.__imageWrapper[:, :, :, 0]
def loadData(self):
"""Makes sure that the image data is loaded into memory.
See :meth:`.ImageWrapper.loadData`.
"""
self.__imageWrapper.loadData()
def __getitem__(self, sliceobj): def __getitem__(self, sliceobj):
"""Access the image data with the specified ``sliceobj``. """Access the image data with the specified ``sliceobj``.
......
...@@ -224,6 +224,8 @@ class ImageWrapper(notifier.Notifier): ...@@ -224,6 +224,8 @@ class ImageWrapper(notifier.Notifier):
:arg sliceobj: Something which can slice the image data. :arg sliceobj: Something which can slice the image data.
""" """
log.debug('Getting image data: {}'.format(sliceobj))
sliceobj = nib.fileslice.canonical_slicers( sliceobj = nib.fileslice.canonical_slicers(
sliceobj, self.__image.shape) sliceobj, self.__image.shape)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment