-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4c2848c
commit 5ecc85d
Showing
3 changed files
with
101 additions
and
18 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
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,11 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
import numpy as np | ||
|
||
from scilpy.reconst.fiber_coherence import (compute_fiber_coherence_fliptable, | ||
compute_fiber_coherence) | ||
|
||
def test_compute_fiber_coherence_table(): | ||
# toDO | ||
pass | ||
|
||
def test_compute_fiber_coherence_fliptable(): | ||
# Just checking that we get 24 values. | ||
# See below for the real tests. | ||
directions = np.zeros((3, 3, 5, 3), dtype=float) | ||
fa = np.zeros((3, 3, 5), dtype=float) | ||
coherence, transforms = compute_fiber_coherence_fliptable(directions, fa) | ||
assert len(coherence) == 24 | ||
assert len(transforms) == 24 | ||
|
||
|
||
def test_compute_fiber_coherence(): | ||
# toDO | ||
pass | ||
# Coherence will be strong if we have voxels were the peak points towards | ||
# the neighbor. Ex: Imagine the corpus callosum, where the voxels in X | ||
# all have peaks in X. | ||
|
||
# Test 1. | ||
# Aligned on the last dimension (z), we have 4 peaks all pointing in the | ||
# z direction, with strong FA. | ||
directions = np.zeros((3, 3, 5, 3), dtype=float) | ||
directions[1, 1, :, :] = np.asarray([[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, -1], | ||
[0, 0, 0]], dtype=float) | ||
fa = np.zeros((3, 3, 5), dtype=float) | ||
fa[1, 1, :] = [1, 1, 1, 1, 0] | ||
|
||
# There should be a good coherence (actually we get 10). | ||
coherence1 = compute_fiber_coherence(directions, fa) | ||
assert coherence1 > 0 | ||
|
||
# Test 2. Testing symmetry: reversing the 4th voxel should not change the | ||
# result | ||
directions[1, 1, :, :] = np.asarray([[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, 0]], dtype=float) | ||
coherence2 = compute_fiber_coherence(directions, fa) | ||
assert coherence2 == coherence1 | ||
|
||
# Test 3 | ||
# Same directions, but with low FA | ||
fa = np.zeros((3, 3, 5), dtype=float) | ||
fa[1, 1, :] = [0.2, 0.2, 0.2, 0.2, 0] | ||
|
||
# There should be a good coherence (actually we get 2). | ||
coherence3 = compute_fiber_coherence(directions, fa) | ||
assert coherence3 < coherence2 | ||
|
||
# Test 4. Voxels with non-zero peaks still have peaks in z, but they are | ||
# aligned in y. | ||
directions = np.zeros((3, 5, 3, 3), dtype=float) | ||
directions[1, :, 1, :] = np.asarray([[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, 1], | ||
[0, 0, -1], | ||
[0, 0, 0]], dtype=float) | ||
fa = np.zeros((3, 3, 5), dtype=float) | ||
fa[1, 1, :] = [1, 1, 1, 1, 0] | ||
coherence4 = compute_fiber_coherence(directions, fa) | ||
assert coherence4 == 0 | ||
|
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