Add option to combine tform with inverse tform

This commit is contained in:
Johannes Schönberger
2014-09-22 08:45:51 -04:00
parent 69c87b5706
commit f846320d78
2 changed files with 8 additions and 0 deletions
+5
View File
@@ -261,6 +261,10 @@ class ProjectiveTransform(GeometricTransform):
else:
tform = ProjectiveTransform
return tform(other.params.dot(self.params))
elif (hasattr(other, '__name__')
and other.__name__ == 'inverse'
and hasattr(get_bound_method_class(other), '_inv_matrix')):
return ProjectiveTransform(self._inv_matrix.dot(self.params))
else:
raise TypeError("Cannot combine transformations of differing "
"types.")
@@ -789,6 +793,7 @@ TRANSFORMS = {
'projective': ProjectiveTransform,
'polynomial': PolynomialTransform,
}
HOMOGRAPHY_TRANSFORMS = (
SimilarityTransform,
AffineTransform,
@@ -218,6 +218,9 @@ def test_union():
assert_array_almost_equal(tform._matrix, tform3._matrix)
assert tform.__class__ == ProjectiveTransform
tform = AffineTransform(scale=(0.1, 0.1), rotation=0.3)
assert_array_almost_equal((tform + tform.inverse).params, np.eye(3))
def test_union_differing_types():
tform1 = SimilarityTransform()