diff --git a/skimage/transform/geometric.py b/skimage/transform/geometric.py index 03e088a2..06b0839e 100644 --- a/skimage/transform/geometric.py +++ b/skimage/transform/geometric.py @@ -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): diff --git a/skimage/transform/tests/test_geometric.py b/skimage/transform/tests/test_geometric.py index 0285a53d..14e839f0 100644 --- a/skimage/transform/tests/test_geometric.py +++ b/skimage/transform/tests/test_geometric.py @@ -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