forked from yeatmanlab/pyAFQ
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request yeatmanlab#484 from 36000/dice_coeff
ENH: Dice coeff
- Loading branch information
Showing
2 changed files
with
123 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,13 +1,55 @@ | ||
import numpy as np | ||
import numpy.testing as npt | ||
import pytest | ||
import os.path as op | ||
|
||
import AFQ.utils.volume as AFV | ||
import nibabel as nib | ||
|
||
from dipy.io.stateful_tractogram import Space | ||
from dipy.io.streamline import StatefulTractogram | ||
|
||
import AFQ.utils.volume as afv | ||
import AFQ.data as afd | ||
|
||
|
||
def test_patch_up_roi(): | ||
roi_bad = np.zeros((10, 10, 10)) | ||
roi_good = np.ones((10, 10, 10)) | ||
|
||
AFV.patch_up_roi(roi_good) | ||
afv.patch_up_roi(roi_good) | ||
with pytest.raises(ValueError): | ||
AFV.patch_up_roi(roi_bad) | ||
afv.patch_up_roi(roi_bad) | ||
|
||
|
||
def test_density_map(): | ||
file_dict = afd.read_stanford_hardi_tractography() | ||
|
||
# subsample even more | ||
subsampled_tractography = file_dict["tractography_subsampled.trk"][441:444] | ||
sft = StatefulTractogram( | ||
subsampled_tractography, | ||
file_dict["mapping.nii.gz"], | ||
Space.VOX) | ||
density_map = afv.density_map(sft) | ||
npt.assert_equal(int(np.sum(density_map.get_fdata())), 69) | ||
|
||
|
||
def test_dice_coeff(): | ||
affine = np.asarray([ | ||
[1, 0, 0, 0], | ||
[0, 1, 0, 0], | ||
[0, 0, 1, 0], | ||
[0, 0, 0, 0]]) | ||
img1 = nib.Nifti1Image( | ||
np.asarray([ | ||
[0.8, 0.9, 0], | ||
[0, 0, 0], | ||
[0, 0, 0]]), | ||
affine) | ||
img2 = nib.Nifti1Image( | ||
np.asarray([ | ||
[0.5, 0, 0], | ||
[0.6, 0, 0], | ||
[0, 0, 0]]), | ||
affine) | ||
npt.assert_equal(afv.dice_coeff(img1, img2), 0.5) |
This file contains 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