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

ImageWrapper.__expandCoverage uses the new collapseExpansions function

to collapse many little expansions (that cover individual volumes) into
a few larger ones (that cover many volumes).
parent e7ceb45e
No related branches found
No related tags found
No related merge requests found
...@@ -336,7 +336,8 @@ class ImageWrapper(notifier.Notifier): ...@@ -336,7 +336,8 @@ class ImageWrapper(notifier.Notifier):
given ``slices``. given ``slices``.
""" """
volumes, expansions = calcExpansion(slices, self.__coverage) _, expansions = calcExpansion(slices, self.__coverage)
expansions = collapseExpansions(expansions, self.__numRealDims - 1)
log.debug('Updating image {} data range [slice: {}] ' log.debug('Updating image {} data range [slice: {}] '
'(current range: [{}, {}]; ' '(current range: [{}, {}]; '
...@@ -346,30 +347,46 @@ class ImageWrapper(notifier.Notifier): ...@@ -346,30 +347,46 @@ class ImageWrapper(notifier.Notifier):
slices, slices,
self.__range[0], self.__range[0],
self.__range[1], self.__range[1],
len(volumes), len(expansions),
self.__coverage)) self.__coverage))
# As we access the data for each expansions,
# we want it to have the same dimensionality
# as the full image, so we can access data
# for each volume in the image separately.
# So we squeeze out the padding dimensions,
# but not the volume dimension.
squeezeDims = tuple(range(self.__numRealDims,
self.__numRealDims + self.__numPadDims))
# The calcExpansion function splits up the # The calcExpansion function splits up the
# expansions on volumes - here we calculate # expansions on volumes - here we calculate
# the min/max per volume/expansion, and # the min/max per volume/expansion, and
# iteratively update the stored per-volume # iteratively update the stored per-volume
# coverage and data range. # coverage and data range.
for vol, exp in zip(volumes, expansions): for i, exp in enumerate(expansions):
data = self.__getData(exp, isTuple=True)
data = data.squeeze(squeezeDims)
vlo, vhi = exp[self.__numRealDims - 1]
for vi, vol in enumerate(range(vlo, vhi)):
oldvmin, oldvmax = self.__volRanges[vol, :] oldvlo, oldvhi = self.__volRanges[vol, :]
voldata = data[..., vi]
data = self.__getData(exp, isTuple=True) newvlo = float(np.nanmin(voldata))
newvmin = float(np.nanmin(data)) newvhi = float(np.nanmax(voldata))
newvmax = float(np.nanmax(data))
if (not np.isnan(oldvmin)) and oldvmin < newvmin: newvmin = oldvmin if (not np.isnan(oldvlo)) and oldvlo < newvlo: newvlo = oldvlo
if (not np.isnan(oldvmax)) and oldvmax > newvmax: newvmax = oldvmax if (not np.isnan(oldvhi)) and oldvhi > newvhi: newvhi = oldvhi
# Update the stored range and # Update the stored range and
# coverage for each volume # coverage for each volume
self.__volRanges[vol, :] = newvmin, newvmax self.__volRanges[vol, :] = newvlo, newvhi
self.__coverage[..., vol] = adjustCoverage( self.__coverage[..., vol] = adjustCoverage(
self.__coverage[..., vol], exp) self.__coverage[..., vol], exp)
# Calculate the new known data # Calculate the new known data
# range over the entire image # range over the entire image
......
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