Merge pull request #1167 from ahojnnes/inv-comb

Add option to combine tform with inverse tform. Closes gh-1165.
This commit is contained in:
Stefan van der Walt
2014-09-22 16:03:19 +02:00
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()