diff --git a/skimage/transform/tests/test_geometric.py b/skimage/transform/tests/test_geometric.py index b25b1aef..d3e7f20c 100644 --- a/skimage/transform/tests/test_geometric.py +++ b/skimage/transform/tests/test_geometric.py @@ -39,20 +39,26 @@ def test_stackcopy(): def test_similarity_estimation(): - #: exact solution + # exact solution tform = estimate_transform('similarity', SRC[:2, :], DST[:2, :]) assert_array_almost_equal(tform(SRC[:2, :]), DST[:2, :]) assert_equal(tform._matrix[0, 0], tform._matrix[1, 1]) assert_equal(tform._matrix[0, 1], - tform._matrix[1, 0]) - #: over-determined - tform = estimate_transform('similarity', SRC, DST) - assert_array_almost_equal(tform.inverse(tform(SRC)), SRC) - assert_equal(tform._matrix[0, 0], tform._matrix[1, 1]) - assert_equal(tform._matrix[0, 1], - tform._matrix[1, 0]) + # over-determined + tform2 = estimate_transform('similarity', SRC, DST) + assert_array_almost_equal(tform2.inverse(tform2(SRC)), SRC) + assert_equal(tform2._matrix[0, 0], tform2._matrix[1, 1]) + assert_equal(tform2._matrix[0, 1], - tform2._matrix[1, 0]) + + # via estimate method + tform3 = SimilarityTransform() + tform3.estimate(SRC, DST) + assert_array_almost_equal(tform3._matrix, tform2._matrix) -def test_similarity_implicit(): +def test_similarity_init(): + # init with implicit parameters scale = 0.1 rotation = 1 translation = (1, 1) @@ -62,18 +68,30 @@ def test_similarity_implicit(): assert_array_almost_equal(tform.rotation, rotation) assert_array_almost_equal(tform.translation, translation) + # init with transformation matrix + tform2 = SimilarityTransform(tform._matrix) + assert_array_almost_equal(tform2.scale, scale) + assert_array_almost_equal(tform2.rotation, rotation) + assert_array_almost_equal(tform2.translation, translation) + def test_affine_estimation(): - #: exact solution + # exact solution tform = estimate_transform('affine', SRC[:3, :], DST[:3, :]) assert_array_almost_equal(tform(SRC[:3, :]), DST[:3, :]) - #: over-determined - tform = estimate_transform('affine', SRC, DST) - assert_array_almost_equal(tform.inverse(tform(SRC)), SRC) + # over-determined + tform2 = estimate_transform('affine', SRC, DST) + assert_array_almost_equal(tform2.inverse(tform2(SRC)), SRC) + + # via estimate method + tform3 = AffineTransform() + tform3.estimate(SRC, DST) + assert_array_almost_equal(tform3._matrix, tform2._matrix) -def test_affine_implicit(): +def test_affine_init(): + # init with implicit parameters scale = (0.1, 0.13) rotation = 1 shear = 0.1 @@ -85,21 +103,46 @@ def test_affine_implicit(): assert_array_almost_equal(tform.shear, shear) assert_array_almost_equal(tform.translation, translation) + # init with transformation matrix + tform2 = AffineTransform(tform._matrix) + assert_array_almost_equal(tform2.scale, scale) + assert_array_almost_equal(tform2.rotation, rotation) + assert_array_almost_equal(tform2.shear, shear) + assert_array_almost_equal(tform2.translation, translation) -def test_projective(): - #: exact solution + +def test_projective_estimation(): + # exact solution tform = estimate_transform('projective', SRC[:4, :], DST[:4, :]) assert_array_almost_equal(tform(SRC[:4, :]), DST[:4, :]) - #: over-determined + # over-determined + tform2 = estimate_transform('projective', SRC, DST) + assert_array_almost_equal(tform2.inverse(tform2(SRC)), SRC) + + # via estimate method + tform3 = ProjectiveTransform() + tform3.estimate(SRC, DST) + assert_array_almost_equal(tform3._matrix, tform2._matrix) + + +def test_projective_init(): tform = estimate_transform('projective', SRC, DST) - assert_array_almost_equal(tform.inverse(tform(SRC)), SRC) + # init with transformation matrix + tform2 = ProjectiveTransform(tform._matrix) + assert_array_almost_equal(tform2._matrix, tform._matrix) -def test_polynomial(): +def test_polynomial_estimation(): + # over-determined tform = estimate_transform('polynomial', SRC, DST, order=10) assert_array_almost_equal(tform(SRC), DST, 6) + # via estimate method + tform2 = PolynomialTransform() + tform2.estimate(SRC, DST, order=10) + assert_array_almost_equal(tform2._params, tform._params) + def test_union(): tform1 = SimilarityTransform(scale=0.1, rotation=0.3) diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 047b477b..7c2e52f2 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -11,8 +11,8 @@ def test_warp(): x = np.zeros((5, 5), dtype=np.uint8) x[2, 2] = 255 x = img_as_float(x) - theta = -np.pi/2 - tform = SimilarityTransform(1, theta, (0, 4)) + theta = - np.pi / 2 + tform = SimilarityTransform(scale=1, rotation=theta, translation=(0, 4)) x90 = warp(x, tform, order=1) assert_array_almost_equal(x90, np.rot90(x))