mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-06 05:16:40 +08:00
fix transformation union and add test case
This commit is contained in:
@@ -106,13 +106,17 @@ class GeometricTransformation(object):
|
||||
return geometric_transform(coords, self.inverse_matrix)
|
||||
|
||||
def union(self, other):
|
||||
return GeometricTransformation(self.matrix.dot(other.matrix))
|
||||
if type(self) == type(other):
|
||||
transformation = self.__class__
|
||||
else:
|
||||
transformation = GeometricTransformation
|
||||
return transformation(self.matrix.dot(other.matrix))
|
||||
|
||||
def __mul__(self, other):
|
||||
return self.union(self, other)
|
||||
return self.union(other)
|
||||
|
||||
def __add__(self, other):
|
||||
return self.union(self, other)
|
||||
return self.union(other)
|
||||
|
||||
|
||||
class SimilarityTransformation(GeometricTransformation):
|
||||
|
||||
@@ -122,6 +122,27 @@ def test_polynomial():
|
||||
assert_array_almost_equal(tform.forward(SRC), DST, 6)
|
||||
|
||||
|
||||
def test_union():
|
||||
tform1 = SimilarityTransformation()
|
||||
scale1 = 0.1
|
||||
rotation1 = 1
|
||||
translation1 = (0, 0)
|
||||
tform1.from_params(scale1, rotation1, translation1)
|
||||
|
||||
tform2 = SimilarityTransformation()
|
||||
scale2 = 0.1
|
||||
rotation2 = 1
|
||||
translation2 = (0, 0)
|
||||
tform2.from_params(scale2, rotation2, translation2)
|
||||
|
||||
tform = tform1.union(tform2)
|
||||
tform = tform1 + tform2
|
||||
tform = tform1 * tform2
|
||||
|
||||
assert_array_almost_equal(tform.scale, scale1 * scale2)
|
||||
assert_array_almost_equal(tform.rotation, rotation1 + rotation2)
|
||||
|
||||
|
||||
def test_homography():
|
||||
x = np.zeros((5,5), dtype=np.uint8)
|
||||
x[1, 1] = 255
|
||||
|
||||
Reference in New Issue
Block a user