-
Notifications
You must be signed in to change notification settings - Fork 28
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
Showing
3 changed files
with
112 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from . import base, moments, histogram, graph, contact | ||
|
||
def paper_em(): | ||
"""Return the feature manager used in the PLoS ONE paper. | ||
This manager was used both for the FIBSEM segmentation (with | ||
multi-channel probabilities) and the SNEMI3D segmentation. [1]_ | ||
Returns | ||
------- | ||
comp : `base.Composite` feature manager | ||
The feature manager to use for graph agglomeration. | ||
References | ||
---------- | ||
.. [1] http://brainiac2.mit.edu/SNEMI3D/content/gala-serial-2d-watershed | ||
""" | ||
fm = moments.Manager() | ||
fh = histogram.Manager(25, 0, 1, [0.1, 0.5, 0.9]) | ||
fg = graph.Manager() | ||
return base.Composite(children=[fm, fh, fg]) | ||
|
||
|
||
def snemi3d(): | ||
"""Return the best-performing feature manager for SNEMI3D. | ||
This correspond's to Neal Donnelly's last submission in 2014 [1]_. | ||
Returns | ||
------- | ||
comp : feature manager | ||
Same as the `paper_em` manager but including also a `contact` | ||
manager. | ||
References | ||
---------- | ||
.. [1] http://brainiac2.mit.edu/SNEMI3D/content/gala-new-watersheds | ||
""" | ||
fm = moments.Manager() | ||
fh = histogram.Manager(25, 0, 1, [0.1, 0.5, 0.9]) | ||
fg = graph.Manager() | ||
fc = contact.Manager() | ||
return base.Composite(children=[fm, fh, fg, fc]) | ||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from __future__ import absolute_import | ||
import os | ||
from six.moves import map | ||
from six.moves import range | ||
|
||
D = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
import numpy as np | ||
from numpy.testing import assert_equal, assert_allclose | ||
|
||
from gala import agglo | ||
from gala import evaluate as ev | ||
from gala.features import default | ||
|
||
|
||
fn_prob = os.path.join(D, 'toy-data/test-01-probabilities.txt') | ||
prob = np.loadtxt(fn_prob) | ||
fn_ws = os.path.join(D, 'toy-data/test-01-watershed.txt') | ||
ws = np.loadtxt(fn_ws, dtype=np.uint32) | ||
fn_gt = os.path.join(D, 'toy-data/test-01-groundtruth.txt') | ||
results = np.loadtxt(fn_gt, dtype=np.uint32) | ||
|
||
|
||
ans12 = np.array( | ||
[3.00, 2.00, 4.67, 6.00, 32.67,0.50, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.50, 0.01, 0.04, 0.99, | ||
3.00, 4.00, 7.00, 1.29, 1.92, 2.05, 9.00, 0.75, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.25, 0.01, | ||
0.03, 0.98, 4.00, 3.50, 2.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, | ||
1.00, 0.96, 0.98, 1.00, 2.00, 4.00, 0.71, 2.75, 3.95, 23.67, 0.03, | ||
-1.00, 0.50]) | ||
|
||
|
||
contact = np.array( | ||
[1.00, 1.50, 0.60, 2.10, 1.00, 1.50, 0.60, | ||
2.10, 1.00, 1.50, 0.60, 2.10, 0.00, 0.41, | ||
-0.51,0.74, 0.00, 0.41,-0.51, 0.74, 0.00, | ||
0.41,-0.51, 0.74,-0.41,-1.25, 0.67, 0.29]) | ||
|
||
|
||
def test_paper_em(): | ||
feat = default.paper_em() | ||
g = agglo.Rag(ws, prob, feature_manager=feat) | ||
assert_allclose(feat(g, 1, 2), ans12, atol=0.01) | ||
|
||
|
||
def test_snemi(): | ||
feat = default.snemi3d() | ||
g = agglo.Rag(ws, prob, feature_manager=feat) | ||
# contact are edge features, so they are inserted just before the 8 | ||
# difference features in the base paper_em vector. | ||
expected = np.concatenate((ans12[:-8], contact, ans12[-8:])) | ||
assert_allclose(feat(g, 1, 2), expected, atol=0.01) | ||
|
||
|
||
if __name__ == '__main__': | ||
from numpy import testing | ||
testing.run_module_suite() | ||
|