diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 6eb0f70a..a134c9fa 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -620,9 +620,9 @@ class SimilarityTransform(ProjectiveTransform): @property def scale(self): - if math.cos(self.rotation) == 0: + if abs(math.cos(self.rotation)) < np.spacing(1): # sin(self.rotation) == 1 - scale = self.params[0, 1] + scale = self.params[1, 0] else: scale = self.params[0, 0] / math.cos(self.rotation) return scale diff --git a/skimage/transform/tests/test_geometric.py b/skimage/transform/tests/test_geometric.py index 1165365e..14a9305c 100644 --- a/skimage/transform/tests/test_geometric.py +++ b/skimage/transform/tests/test_geometric.py @@ -99,6 +99,17 @@ def test_similarity_init(): assert_array_almost_equal(tform.translation, translation) + # test special case for scale if rotation=90deg + scale = 0.1 + rotation = np.pi / 2 + translation = (1, 1) + tform = SimilarityTransform(scale=scale, rotation=rotation, + translation=translation) + assert_array_almost_equal(tform.scale, scale) + assert_array_almost_equal(tform.rotation, rotation) + assert_array_almost_equal(tform.translation, translation) + + def test_affine_estimation(): # exact solution tform = estimate_transform('affine', SRC[:3, :], DST[:3, :])