diff --git a/fsl/data/atlases.py b/fsl/data/atlases.py index c6cdc9117b253d479b2a77f4297eb200c4b705a5..3f5af0c0a8cef928b6ad7f795d4a23d3946a2b1e 100644 --- a/fsl/data/atlases.py +++ b/fsl/data/atlases.py @@ -825,16 +825,18 @@ class ProbabilisticAtlas(Atlas): # Make sure that the mask has the same # number of voxels as the atlas image - mask = mask.resample(self.shape[:3], order=1) + mask = mask.resample(self.shape[:3], dtype=np.float32, order=1)[0] boolmask = mask > 0 for label in range(self.shape[3]): - vals = self[..., label] - vals = vals[boolmask] * mask[boolmask] - prop = vals.mean() + weights = mask[boolmask] + vals = self[..., label] + vals = vals[boolmask] * weights + prop = vals.sum() / weights.sum() + + if not np.isclose(prop, 0): - if prop != 0: labels.append(label) props .append(prop)