Skip to content

Commit

Permalink
Merge f9c5996 into 0d5187a
Browse files Browse the repository at this point in the history
  • Loading branch information
jni committed Sep 22, 2015
2 parents 0d5187a + f9c5996 commit 0d84403
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gala/features/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
base, \
contact, \
convex_hull, \
default, \
graph, \
histogram, \
inclusion, \
Expand All @@ -18,5 +19,6 @@
orientation, \
squiggliness

__all__ = ['base', 'contact', 'convex_hull', 'graph', 'histogram', 'inclusion',
'io', 'moments', 'orientation', 'squiggliness']
__all__ = ['base', 'contact', 'convex_hull', 'default',
'graph', 'histogram', 'inclusion',
'io', 'moments', 'orientation', 'squiggliness']
45 changes: 45 additions & 0 deletions gala/features/default.py
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])


63 changes: 63 additions & 0 deletions tests/test_defaults.py
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()

0 comments on commit 0d84403

Please sign in to comment.