Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michiel Cottaar
fslpy
Commits
8bf574fa
Commit
8bf574fa
authored
7 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
Adjusted atlas mask query routines to be less inaccurate
parent
56fa033f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fsl/data/atlases.py
+32
-21
32 additions, 21 deletions
fsl/data/atlases.py
with
32 additions
and
21 deletions
fsl/data/atlases.py
+
32
−
21
View file @
8bf574fa
...
@@ -698,33 +698,43 @@ class LabelAtlas(Atlas):
...
@@ -698,33 +698,43 @@ class LabelAtlas(Atlas):
- A sequence of all labels which are present in the mask
- A sequence of all labels which are present in the mask
- A sequence containing the proportion, within the mask,
- A sequence containing the proportion, within the mask,
of each present label.
of each present label. The proportions are returned as
values between 0 and 100.
"""
"""
# Make sure that the mask has the
# Make sure that the mask has the same
# same number of voxels as the
# number of voxels as the atlas image.
# atlas image
# Use nearest neighbour interpolation
mask
=
mask
.
resample
(
self
.
shape
[:
3
],
order
=
1
)
# for resampling, as it is most likely
# that the mask is binary.
mask
=
mask
.
resample
(
self
.
shape
[:
3
],
dtype
=
np
.
float32
,
order
=
0
)[
0
]
boolmask
=
mask
>
0
boolmask
=
mask
>
0
fslimage
.
Image
(
mask
,
xform
=
self
.
voxToWorldMat
).
save
(
'
blag.nii.gz
'
)
# 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
vals
=
self
[
boolmask
]
vals
=
self
[
boolmask
]
weights
=
mask
[
boolmask
]
weights
=
mask
[
boolmask
]
labels
=
np
.
unique
(
vals
)
weightsum
=
weights
.
sum
()
props
=
[]
labels
=
np
.
unique
(
vals
)
props
=
[]
for
label
in
labels
:
for
label
in
labels
:
# Figure out the number of all voxels
# Figure out the number of all voxels
# in the mask with this label, weighted
# in the mask with this label, weighted
# by the mask
# by the mask
.
prop
=
((
vals
==
label
)
*
weights
)
.
sum
()
prop
=
weights
[
vals
==
label
]
.
sum
()
# Normalise it to be a proportion
# Normalise it to be a proportion
# of all voxels in the mask
# of all voxels in the mask. We
props
.
append
(
prop
/
float
(
len
(
vals
)))
# multiply by 100 because the FSL
# probabilistic atlases store their
# probabilities as percentages.
props
.
append
(
100
*
prop
/
weightsum
)
return
labels
,
props
return
labels
,
props
...
@@ -817,7 +827,8 @@ class ProbabilisticAtlas(Atlas):
...
@@ -817,7 +827,8 @@ class ProbabilisticAtlas(Atlas):
- A sequence of all labels which are present in the mask
- A sequence of all labels which are present in the mask
- A sequence containing the proportion, within the mask,
- A sequence containing the proportion, within the mask,
of each present label.
of each present label. The proportions are returned as
values between 0 and 100.
"""
"""
labels
=
[]
labels
=
[]
...
@@ -825,18 +836,18 @@ class ProbabilisticAtlas(Atlas):
...
@@ -825,18 +836,18 @@ 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
=
1
)[
0
]
mask
=
mask
.
resample
(
self
.
shape
[:
3
],
dtype
=
np
.
float32
,
order
=
0
)[
0
]
boolmask
=
mask
>
0
boolmask
=
mask
>
0
weights
=
mask
[
boolmask
]
weightsum
=
weights
.
sum
()
for
label
in
range
(
self
.
shape
[
3
]):
for
label
in
range
(
self
.
shape
[
3
]):
weights
=
mask
[
boolmask
]
vals
=
self
[...,
label
]
vals
=
self
[...,
label
]
vals
=
vals
[
boolmask
]
*
weights
vals
=
vals
[
boolmask
]
*
weights
prop
=
vals
.
sum
()
/
weightsum
prop
=
vals
.
sum
()
/
weights
.
sum
()
if
not
np
.
isclose
(
prop
,
0
):
if
not
np
.
isclose
(
prop
,
0
):
labels
.
append
(
label
)
labels
.
append
(
label
)
props
.
append
(
prop
)
props
.
append
(
prop
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment