"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "skimage/transform/tests/test_geometric.py" between
scikit-image-0.19.1.tar.gz and scikit-image-0.19.2.tar.gz

About: scikit-image is a collection of algorithms for image processing in Python.

test_geometric.py  (scikit-image-0.19.1):test_geometric.py  (scikit-image-0.19.2)
skipping to change at line 66 skipping to change at line 66
assert_almost_equal(tform.params[0, 1], - tform.params[1, 0]) assert_almost_equal(tform.params[0, 1], - tform.params[1, 0])
# over-determined # over-determined
tform2 = estimate_transform('euclidean', SRC, DST) tform2 = estimate_transform('euclidean', SRC, DST)
assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC)
assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1]) assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1])
assert_almost_equal(tform2.params[0, 1], - tform2.params[1, 0]) assert_almost_equal(tform2.params[0, 1], - tform2.params[1, 0])
# via estimate method # via estimate method
tform3 = EuclideanTransform() tform3 = EuclideanTransform()
tform3.estimate(SRC, DST) assert tform3.estimate(SRC, DST)
assert_almost_equal(tform3.params, tform2.params) assert_almost_equal(tform3.params, tform2.params)
def test_euclidean_init(): def test_euclidean_init():
# init with implicit parameters # init with implicit parameters
rotation = 1 rotation = 1
translation = (1, 1) translation = (1, 1)
tform = EuclideanTransform(rotation=rotation, translation=translation) tform = EuclideanTransform(rotation=rotation, translation=translation)
assert_almost_equal(tform.rotation, rotation) assert_almost_equal(tform.rotation, rotation)
assert_almost_equal(tform.translation, translation) assert_almost_equal(tform.translation, translation)
skipping to change at line 111 skipping to change at line 111
assert_almost_equal(tform.params[0, 1], - tform.params[1, 0]) assert_almost_equal(tform.params[0, 1], - tform.params[1, 0])
# over-determined # over-determined
tform2 = estimate_transform('similarity', SRC, DST) tform2 = estimate_transform('similarity', SRC, DST)
assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC)
assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1]) assert_almost_equal(tform2.params[0, 0], tform2.params[1, 1])
assert_almost_equal(tform2.params[0, 1], - tform2.params[1, 0]) assert_almost_equal(tform2.params[0, 1], - tform2.params[1, 0])
# via estimate method # via estimate method
tform3 = SimilarityTransform() tform3 = SimilarityTransform()
tform3.estimate(SRC, DST) assert tform3.estimate(SRC, DST)
assert_almost_equal(tform3.params, tform2.params) assert_almost_equal(tform3.params, tform2.params)
def test_similarity_init(): def test_similarity_init():
# init with implicit parameters # init with implicit parameters
scale = 0.1 scale = 0.1
rotation = 1 rotation = 1
translation = (1, 1) translation = (1, 1)
tform = SimilarityTransform(scale=scale, rotation=rotation, tform = SimilarityTransform(scale=scale, rotation=rotation,
translation=translation) translation=translation)
assert_almost_equal(tform.scale, scale) assert_almost_equal(tform.scale, scale)
skipping to change at line 175 skipping to change at line 175
# exact solution # exact solution
tform = estimate_transform('affine', SRC[:3, :], DST[:3, :]) tform = estimate_transform('affine', SRC[:3, :], DST[:3, :])
assert_almost_equal(tform(SRC[:3, :]), DST[:3, :]) assert_almost_equal(tform(SRC[:3, :]), DST[:3, :])
# over-determined # over-determined
tform2 = estimate_transform('affine', SRC, DST) tform2 = estimate_transform('affine', SRC, DST)
assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC)
# via estimate method # via estimate method
tform3 = AffineTransform() tform3 = AffineTransform()
tform3.estimate(SRC, DST) assert tform3.estimate(SRC, DST)
assert_almost_equal(tform3.params, tform2.params) assert_almost_equal(tform3.params, tform2.params)
def test_affine_init(): def test_affine_init():
# init with implicit parameters # init with implicit parameters
scale = (0.1, 0.13) scale = (0.1, 0.13)
rotation = 1 rotation = 1
shear = 0.1 shear = 0.1
translation = (1, 1) translation = (1, 1)
tform = AffineTransform(scale=scale, rotation=rotation, shear=shear, tform = AffineTransform(scale=scale, rotation=rotation, shear=shear,
translation=translation) translation=translation)
skipping to change at line 203 skipping to change at line 203
assert_almost_equal(tform2.scale, scale) assert_almost_equal(tform2.scale, scale)
assert_almost_equal(tform2.rotation, rotation) assert_almost_equal(tform2.rotation, rotation)
assert_almost_equal(tform2.shear, shear) assert_almost_equal(tform2.shear, shear)
assert_almost_equal(tform2.translation, translation) assert_almost_equal(tform2.translation, translation)
# scalar vs. tuple scale arguments # scalar vs. tuple scale arguments
assert_almost_equal(AffineTransform(scale=0.5).scale, AffineTransform(scale= (0.5, 0.5)).scale) assert_almost_equal(AffineTransform(scale=0.5).scale, AffineTransform(scale= (0.5, 0.5)).scale)
def test_piecewise_affine(): def test_piecewise_affine():
tform = PiecewiseAffineTransform() tform = PiecewiseAffineTransform()
tform.estimate(SRC, DST) assert tform.estimate(SRC, DST)
# make sure each single affine transform is exactly estimated # make sure each single affine transform is exactly estimated
assert_almost_equal(tform(SRC), DST) assert_almost_equal(tform(SRC), DST)
assert_almost_equal(tform.inverse(DST), SRC) assert_almost_equal(tform.inverse(DST), SRC)
def test_fundamental_matrix_estimation(): def test_fundamental_matrix_estimation():
src = np.array([1.839035, 1.924743, 0.543582, 0.375221, src = np.array([1.839035, 1.924743, 0.543582, 0.375221,
0.473240, 0.142522, 0.964910, 0.598376, 0.473240, 0.142522, 0.964910, 0.598376,
0.102388, 0.140092, 15.994343, 9.622164, 0.102388, 0.140092, 15.994343, 9.622164,
0.285901, 0.430055, 0.091150, 0.254594]).reshape(-1, 2) 0.285901, 0.430055, 0.091150, 0.254594]).reshape(-1, 2)
dst = np.array([1.002114, 1.129644, 1.521742, 1.846002, dst = np.array([1.002114, 1.129644, 1.521742, 1.846002,
skipping to change at line 307 skipping to change at line 307
# exact solution # exact solution
tform = estimate_transform('projective', SRC[:4, :], DST[:4, :]) tform = estimate_transform('projective', SRC[:4, :], DST[:4, :])
assert_almost_equal(tform(SRC[:4, :]), DST[:4, :]) assert_almost_equal(tform(SRC[:4, :]), DST[:4, :])
# over-determined # over-determined
tform2 = estimate_transform('projective', SRC, DST) tform2 = estimate_transform('projective', SRC, DST)
assert_almost_equal(tform2.inverse(tform2(SRC)), SRC) assert_almost_equal(tform2.inverse(tform2(SRC)), SRC)
# via estimate method # via estimate method
tform3 = ProjectiveTransform() tform3 = ProjectiveTransform()
tform3.estimate(SRC, DST) assert tform3.estimate(SRC, DST)
assert_almost_equal(tform3.params, tform2.params) assert_almost_equal(tform3.params, tform2.params)
def test_projective_weighted_estimation(): def test_projective_weighted_estimation():
# Exact solution with same points, and unity weights # Exact solution with same points, and unity weights
tform = estimate_transform('projective', SRC[:4, :], DST[:4, :]) tform = estimate_transform('projective', SRC[:4, :], DST[:4, :])
tform_w = estimate_transform('projective', tform_w = estimate_transform('projective',
SRC[:4, :], DST[:4, :], np.ones(4)) SRC[:4, :], DST[:4, :], np.ones(4))
assert_almost_equal(tform.params, tform_w.params) assert_almost_equal(tform.params, tform_w.params)
skipping to change at line 348 skipping to change at line 348
tform2 = ProjectiveTransform(tform.params) tform2 = ProjectiveTransform(tform.params)
assert_almost_equal(tform2.params, tform.params) assert_almost_equal(tform2.params, tform.params)
def test_polynomial_estimation(): def test_polynomial_estimation():
# over-determined # over-determined
tform = estimate_transform('polynomial', SRC, DST, order=10) tform = estimate_transform('polynomial', SRC, DST, order=10)
assert_almost_equal(tform(SRC), DST, 6) assert_almost_equal(tform(SRC), DST, 6)
# via estimate method # via estimate method
tform2 = PolynomialTransform() tform2 = PolynomialTransform()
tform2.estimate(SRC, DST, order=10) assert tform2.estimate(SRC, DST, order=10)
assert_almost_equal(tform2.params, tform.params) assert_almost_equal(tform2.params, tform.params)
def test_polynomial_weighted_estimation(): def test_polynomial_weighted_estimation():
# Over-determined solution with same points, and unity weights # Over-determined solution with same points, and unity weights
tform = estimate_transform('polynomial', SRC, DST, order=10) tform = estimate_transform('polynomial', SRC, DST, order=10)
tform_w = estimate_transform('polynomial', tform_w = estimate_transform('polynomial',
SRC, SRC,
DST, DST,
order=10, order=10,
weights=np.ones(SRC.shape[0])) weights=np.ones(SRC.shape[0]))
skipping to change at line 491 skipping to change at line 491
EssentialMatrixTransform(rotation=np.eye(3), EssentialMatrixTransform(rotation=np.eye(3),
translation=np.zeros((2,))) translation=np.zeros((2,)))
with pytest.raises(ValueError): with pytest.raises(ValueError):
EssentialMatrixTransform( EssentialMatrixTransform(
rotation=np.eye(3), translation=np.zeros((3,))) rotation=np.eye(3), translation=np.zeros((3,)))
def test_degenerate(): def test_degenerate():
src = dst = np.zeros((10, 2)) src = dst = np.zeros((10, 2))
tform = SimilarityTransform() tform = SimilarityTransform()
tform.estimate(src, dst) assert not tform.estimate(src, dst)
assert np.all(np.isnan(tform.params))
tform = EuclideanTransform()
assert not tform.estimate(src, dst)
assert np.all(np.isnan(tform.params)) assert np.all(np.isnan(tform.params))
tform = AffineTransform() tform = AffineTransform()
tform.estimate(src, dst) assert not tform.estimate(src, dst)
assert np.all(np.isnan(tform.params)) assert np.all(np.isnan(tform.params))
tform = ProjectiveTransform() tform = ProjectiveTransform()
tform.estimate(src, dst) assert not tform.estimate(src, dst)
assert np.all(np.isnan(tform.params)) assert np.all(np.isnan(tform.params))
# See gh-3926 for discussion details # See gh-3926 for discussion details
tform = ProjectiveTransform() tform = ProjectiveTransform()
for i in range(20): for i in range(20):
# Some random coordinates # Some random coordinates
src = np.random.rand(4, 2) * 100 src = np.random.rand(4, 2) * 100
dst = np.random.rand(4, 2) * 100 dst = np.random.rand(4, 2) * 100
# Degenerate the case by arranging points on a single line # Degenerate the case by arranging points on a single line
src[:, 1] = np.random.rand() src[:, 1] = np.random.rand()
# Prior to gh-3926, under the above circumstances, # Prior to gh-3926, under the above circumstances,
# a transform could be returned with nan values. # a transform could be returned with nan values.
assert(not tform.estimate(src, dst) or np.isfinite(tform.params).all()) assert(not tform.estimate(src, dst) or np.isfinite(tform.params).all())
src = np.array([[0, 2, 0], [0, 2, 0], [0, 4, 0]])
dst = np.array([[0, 1, 0], [0, 1, 0], [0, 3, 0]])
tform = AffineTransform()
assert not tform.estimate(src, dst)
# Prior to gh-6207, the above would set the parameters as the identity.
assert np.all(np.isnan(tform.params))
# The tesselation on the following points produces one degenerate affine
# warp within PiecewiseAffineTransform.
src = np.asarray([
[0, 192, 256], [0, 256, 256], [5, 0, 192], [5, 64, 0], [5, 64, 64],
[5, 64, 256], [5, 192, 192], [5, 256, 256], [0, 192, 256],
])
dst = np.asarray([
[0, 142, 206], [0, 206, 206], [5, -50, 142], [5, 14, 0], [5, 14, 64],
[5, 14, 206], [5, 142, 142], [5, 206, 206], [0, 142, 206],
])
tform = PiecewiseAffineTransform()
assert not tform.estimate(src, dst)
assert np.all(np.isnan(tform.affines[4].params)) # degenerate affine
for idx, affine in enumerate(tform.affines):
if idx != 4:
assert not np.all(np.isnan(affine.params))
for affine in tform.inverse_affines:
assert not np.all(np.isnan(affine.params))
def test_normalize_degenerate_points(): def test_normalize_degenerate_points():
"""Return nan matrix *of appropriate size* when point is repeated.""" """Return nan matrix *of appropriate size* when point is repeated."""
pts = np.array([[73.42834308, 94.2977623 ],] * 3) pts = np.array([[73.42834308, 94.2977623 ],] * 3)
mat, pts_tf = _center_and_normalize_points(pts) mat, pts_tf = _center_and_normalize_points(pts)
assert np.all(np.isnan(mat)) assert np.all(np.isnan(mat))
assert np.all(np.isnan(pts_tf)) assert np.all(np.isnan(pts_tf))
assert mat.shape == (3, 3) assert mat.shape == (3, 3)
assert pts_tf.shape == pts.shape assert pts_tf.shape == pts.shape
def test_projective_repr(): def test_projective_repr():
skipping to change at line 578 skipping to change at line 609
matrix = np.array( matrix = np.array(
[[4.8, 0.1, 0.2, 25], [[4.8, 0.1, 0.2, 25],
[0.0, 1.0, 0.1, 30], [0.0, 1.0, 0.1, 30],
[0.0, 0.0, 1.0, -2], [0.0, 0.0, 1.0, -2],
[0.0, 0.0, 0.0, 1.]] [0.0, 0.0, 0.0, 1.]]
) )
tf = AffineTransform(matrix=matrix) tf = AffineTransform(matrix=matrix)
dst = tf(src) dst = tf(src)
dst_noisy = dst + np.random.random((25, ndim)) dst_noisy = dst + np.random.random((25, ndim))
tf2 = AffineTransform(dimensionality=ndim) tf2 = AffineTransform(dimensionality=ndim)
tf2.estimate(src, dst_noisy) assert tf2.estimate(src, dst_noisy)
# we check rot/scale/etc more tightly than translation because translation # we check rot/scale/etc more tightly than translation because translation
# estimation is on the 1 pixel scale # estimation is on the 1 pixel scale
assert_almost_equal(tf2.params[:, :-1], matrix[:, :-1], decimal=2) assert_almost_equal(tf2.params[:, :-1], matrix[:, :-1], decimal=2)
assert_almost_equal(tf2.params[:, -1], matrix[:, -1], decimal=0) assert_almost_equal(tf2.params[:, -1], matrix[:, -1], decimal=0)
_assert_least_squares(tf2, src, dst_noisy) _assert_least_squares(tf2, src, dst_noisy)
def test_fundamental_3d_not_implemented(): def test_fundamental_3d_not_implemented():
with pytest.raises(NotImplementedError): with pytest.raises(NotImplementedError):
_ = FundamentalMatrixTransform(dimensionality=3) _ = FundamentalMatrixTransform(dimensionality=3)
with pytest.raises(NotImplementedError): with pytest.raises(NotImplementedError):
 End of changes. 11 change blocks. 
10 lines changed or deleted 41 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)