From 8ab0c9a32958e7a03946473c5dc6ea8a574765f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 10 Aug 2012 08:15:06 +0200 Subject: [PATCH] add test for shape of transformation matrix --- skimage/transform/_geometric.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index c2bd7cb3..54865b02 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -105,6 +105,8 @@ class ProjectiveTransform(GeometricTransform): coeffs = range(8) def __init__(self, matrix=None): + if matrix is not None and matrix.shape != (3, 3): + raise ValueError("invalid shape of transformation matrix") self._matrix = matrix @property @@ -269,10 +271,12 @@ class AffineTransform(ProjectiveTransform): def __init__(self, matrix=None, scale=None, rotation=None, shear=None, translation=None): + if matrix is not None and matrix.shape != (3, 3): + raise ValueError("invalid shape of transformation matrix") + self._matrix = matrix + params = (scale, rotation, shear, translation) - if matrix is not None: - self._matrix = matrix - elif any(param is not None for param in params): + if any(param is not None for param in params): if scale is None: scale = (1, 1) if rotation is None: @@ -340,10 +344,12 @@ class SimilarityTransform(ProjectiveTransform): def __init__(self, matrix=None, scale=None, rotation=None, translation=None): + if matrix is not None and matrix.shape != (3, 3): + raise ValueError("invalid shape of transformation matrix") + self._matrix = matrix + params = (scale, rotation, translation) - if matrix is not None: - self._matrix = matrix - elif any(param is not None for param in params): + if any(param is not None for param in params): if scale is None: scale = 1 if rotation is None: @@ -460,6 +466,8 @@ class PolynomialTransform(GeometricTransform): """ def __init__(self, params=None): + if params is not None and params.shape[0] != 2: + raise ValueError("invalid shape of transformation parameters") self._params = params def estimate(self, src, dst, order):