Skip to content
Snippets Groups Projects
Commit 95adaa45 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Atlas mask query methods raise an error if the provided mask is not

in the same space as the atlas. This might change in the future.
parent 56c71d6d
No related branches found
No related tags found
No related merge requests found
...@@ -711,12 +711,16 @@ class LabelAtlas(Atlas): ...@@ -711,12 +711,16 @@ class LabelAtlas(Atlas):
# Use nearest neighbour interpolation # Use nearest neighbour interpolation
# for resampling, as it is most likely # for resampling, as it is most likely
# that the mask is binary. # that the mask is binary.
mask = mask.resample(self.shape[:3], dtype=np.float32, order=0)[0] mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
boolmask = mask > 0
if not fslimage.Image(mask, xform=xform).sameSpace(self):
raise ValueError('Mask is not in the same space as atlas')
# Extract the labels that are in # Extract the labels that are in
# the mask, and their corresponding # the mask, and their corresponding
# mask weights # mask weights
boolmask = mask > 0
vals = self[boolmask] vals = self[boolmask]
weights = mask[boolmask] weights = mask[boolmask]
weightsum = weights.sum() weightsum = weights.sum()
...@@ -851,7 +855,11 @@ class ProbabilisticAtlas(Atlas): ...@@ -851,7 +855,11 @@ class ProbabilisticAtlas(Atlas):
# Make sure that the mask has the same # Make sure that the mask has the same
# number of voxels as the atlas image # number of voxels as the atlas image
mask = mask.resample(self.shape[:3], dtype=np.float32, order=0)[0] mask, xform = mask.resample(self.shape[:3], dtype=np.float32, order=0)
if not fslimage.Image(mask, xform=xform).sameSpace(self):
raise ValueError('Mask is not in the same space as atlas')
boolmask = mask > 0 boolmask = mask > 0
weights = mask[boolmask] weights = mask[boolmask]
weightsum = weights.sum() weightsum = weights.sum()
......
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