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

Some probabiliistic atlas descriptions refer to probabilistic files with more

labels than in the description (the striatum ones).
parent f3f8988e
No related branches found
No related tags found
No related merge requests found
...@@ -719,22 +719,30 @@ class LabelAtlas(Atlas): ...@@ -719,22 +719,30 @@ class LabelAtlas(Atlas):
vals = self[boolmask] vals = self[boolmask]
weights = mask[boolmask] weights = mask[boolmask]
weightsum = weights.sum() weightsum = weights.sum()
labels = np.unique(vals) gotLabels = np.unique(vals)
labels = []
props = [] props = []
for label in labels: # Only consider labels that
# this atlas is aware of
for label in self.desc.labels:
# Figure out the number of all voxels label = label.index + 1
# in the mask with this label, weighted
# by the mask.
prop = weights[vals == label].sum()
# Normalise it to be a proportion if label in gotLabels:
# of all voxels in the mask. We
# multiply by 100 because the FSL # Figure out the number of all voxels
# probabilistic atlases store their # in the mask with this label, weighted
# probabilities as percentages. # by the mask.
props.append(100 * prop / weightsum) prop = weights[vals == label].sum()
# Normalise it to be a proportion
# of all voxels in the mask. We
# multiply by 100 because the FSL
# probabilistic atlases store their
# probabilities as percentages.
labels.append(label)
props .append(100 * prop / weightsum)
return labels, props return labels, props
...@@ -812,7 +820,11 @@ class ProbabilisticAtlas(Atlas): ...@@ -812,7 +820,11 @@ class ProbabilisticAtlas(Atlas):
loc[2] >= self.shape[2]: loc[2] >= self.shape[2]:
return [] return []
return self[loc[0], loc[1], loc[2], :] # We only return labels for this atlas
props = self[loc[0], loc[1], loc[2], :]
props = [props[l.index] for l in self.desc.labels]
return props
def maskProportions(self, mask): def maskProportions(self, mask):
...@@ -841,11 +853,12 @@ class ProbabilisticAtlas(Atlas): ...@@ -841,11 +853,12 @@ class ProbabilisticAtlas(Atlas):
weights = mask[boolmask] weights = mask[boolmask]
weightsum = weights.sum() weightsum = weights.sum()
for label in range(self.shape[3]): for label in self.desc.labels:
vals = self[..., label] label = label.index
vals = vals[boolmask] * weights vals = self[..., label]
prop = vals.sum() / weightsum vals = vals[boolmask] * weights
prop = vals.sum() / weightsum
if not np.isclose(prop, 0): if not np.isclose(prop, 0):
labels.append(label) labels.append(label)
......
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