-
Notifications
You must be signed in to change notification settings - Fork 533
ENH: Revise the implementation of FuzzyOverlap #2530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
76b0e34
[ENH] Revise the implementation of FuzzyOverlap
oesteban 9d4f39c
update specs
oesteban 36e43d2
address @effigies' comments
oesteban 63519b8
Merge branch 'master' into enh/add-masks-overlap
effigies 140b159
add regression tests
oesteban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
|
||
import numpy as np | ||
import nibabel as nb | ||
from nipype.testing import example_data | ||
from ..metrics import FuzzyOverlap | ||
|
||
|
||
def test_fuzzy_overlap(tmpdir): | ||
tmpdir.chdir() | ||
|
||
# Tests with tissue probability maps | ||
in_mask = example_data('tpms_msk.nii.gz') | ||
tpms = [example_data('tpm_%02d.nii.gz' % i) for i in range(3)] | ||
out = FuzzyOverlap(in_ref=tpms[0], in_tst=tpms[0]).run().outputs | ||
assert out.dice == 1 | ||
|
||
out = FuzzyOverlap( | ||
in_mask=in_mask, in_ref=tpms[0], in_tst=tpms[0]).run().outputs | ||
assert out.dice == 1 | ||
|
||
out = FuzzyOverlap( | ||
in_mask=in_mask, in_ref=tpms[0], in_tst=tpms[1]).run().outputs | ||
assert 0 < out.dice < 1 | ||
|
||
out = FuzzyOverlap(in_ref=tpms, in_tst=tpms).run().outputs | ||
assert out.dice == 1.0 | ||
|
||
out = FuzzyOverlap( | ||
in_mask=in_mask, in_ref=tpms, in_tst=tpms).run().outputs | ||
assert out.dice == 1.0 | ||
|
||
# Tests with synthetic 3x3x3 images | ||
data = np.zeros((3, 3, 3), dtype=float) | ||
data[0, 0, 0] = 0.5 | ||
data[2, 2, 2] = 0.25 | ||
data[1, 1, 1] = 0.3 | ||
nb.Nifti1Image(data, np.eye(4)).to_filename('test1.nii.gz') | ||
|
||
data = np.zeros((3, 3, 3), dtype=float) | ||
data[0, 0, 0] = 0.6 | ||
data[1, 1, 1] = 0.3 | ||
nb.Nifti1Image(data, np.eye(4)).to_filename('test2.nii.gz') | ||
|
||
out = FuzzyOverlap(in_ref='test1.nii.gz', in_tst='test2.nii.gz').run().outputs | ||
assert np.allclose(out.dice, 0.82051) | ||
|
||
# Just considering the mask, the central pixel | ||
# that raised the index now is left aside. | ||
data = np.zeros((3, 3, 3), dtype=int) | ||
data[0, 0, 0] = 1 | ||
data[2, 2, 2] = 1 | ||
nb.Nifti1Image(data, np.eye(4)).to_filename('mask.nii.gz') | ||
|
||
out = FuzzyOverlap(in_ref='test1.nii.gz', in_tst='test2.nii.gz', | ||
in_mask='mask.nii.gz').run().outputs | ||
assert np.allclose(out.dice, 0.74074) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These shapes look guaranteed to be 2D, already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If only one item in the input lists are passed, numpy squeezes the redundant dimension. This was necessary for this interface to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well that's surprising and annoying. Okay.