Files
scikit-image/skimage/graph/tests/test_anisotropy.py
T
Almar Klein 789ade3ca2 update-mcp: added tests for newly added features.
Also fix in existing test related to how the traceback arrays is initialized:
first it was initialized with all -1, now with -2, and -1 at the seed points.
2013-12-15 00:37:27 +01:00

54 lines
2.2 KiB
Python

import skimage.graph.mcp as mcp
from numpy.testing import (assert_array_equal,
assert_almost_equal,
)
import numpy as np
a = np.ones((8, 8), dtype=np.float32)
horizontal_ramp = np.array( [[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,],
[ 0., 1., 2., 3., 4., 5., 6., 7.,]])
vertical_ramp = np.array( [[ 0., 0., 0., 0., 0., 0., 0., 0.,],
[ 1., 1., 1., 1., 1., 1., 1., 1.,],
[ 2., 2., 2., 2., 2., 2., 2., 2.,],
[ 3., 3., 3., 3., 3., 3., 3., 3.,],
[ 4., 4., 4., 4., 4., 4., 4., 4.,],
[ 5., 5., 5., 5., 5., 5., 5., 5.,],
[ 6., 6., 6., 6., 6., 6., 6., 6.,],
[ 7., 7., 7., 7., 7., 7., 7., 7.,]])
def test_anisotropy():
# Create seeds; vertical seeds create a horizonral ramp
seeds_for_horizontal = [(i,0) for i in range(8) ]
seeds_for_vertcal = [(0,i) for i in range(8) ]
for sy in range(1, 5):
for sx in range(1,5):
sampling = sy, sx
# Trace horizontally
m1 = mcp.MCP_Geometric(a, sampling=sampling, fully_connected=True)
costs1, traceback = m1.find_costs(seeds_for_horizontal)
# Trace vertically
m2 = mcp.MCP_Geometric(a, sampling=sampling, fully_connected=True)
costs2, traceback = m2.find_costs(seeds_for_vertcal)
# Check
assert_array_equal(costs1, horizontal_ramp * sx)
assert_array_equal(costs2, vertical_ramp * sy)
if __name__ == "__main__":
np.testing.run_module_suite()