From 92008901ef353178bd4445635b9df8ce83a0b17a Mon Sep 17 00:00:00 2001 From: Stefan van der Walt Date: Fri, 25 Oct 2013 01:40:41 -0700 Subject: [PATCH 1/2] Merge pull request #796 from ahojnnes/warp-fix Fix bug in homography detection --- skimage/transform/_geometric.py | 30 +++++++++++++++++------------- skimage/transform/_warps_cy.pyx | 8 ++++---- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/skimage/transform/_geometric.py b/skimage/transform/_geometric.py index 25a13765..c1f49fa5 100644 --- a/skimage/transform/_geometric.py +++ b/skimage/transform/_geometric.py @@ -341,7 +341,7 @@ class AffineTransform(ProjectiveTransform): return self._matrix[0:2, 2] -class PiecewiseAffineTransform(ProjectiveTransform): +class PiecewiseAffineTransform(GeometricTransform): """2D piecewise affine transformation. @@ -1031,21 +1031,24 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, out = None - # use fast Cython version for specific interpolation orders + # use fast Cython version for specific interpolation orders and input if order in range(4) and not map_args: + matrix = None + # inverse_map is a transformation matrix as numpy array if isinstance(inverse_map, np.ndarray) and inverse_map.shape == (3, 3): matrix = inverse_map - elif inverse_map in HOMOGRAPHY_TRANSFORMS: + # inverse_map is a homography + elif isinstance(inverse_map, HOMOGRAPHY_TRANSFORMS): matrix = inverse_map._matrix + # inverse_map is the inverse of a homography elif (hasattr(inverse_map, '__name__') and inverse_map.__name__ == 'inverse' - and get_bound_method_class(inverse_map) - in HOMOGRAPHY_TRANSFORMS): - + and isinstance(get_bound_method_class(inverse_map), + HOMOGRAPHY_TRANSFORMS)): matrix = np.linalg.inv(six.get_method_self(inverse_map)._matrix) if matrix is not None: @@ -1067,6 +1070,7 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, rows, cols = output_shape[:2] + # inverse_map is a transformation matrix as numpy array if isinstance(inverse_map, np.ndarray) and inverse_map.shape == (3, 3): inverse_map = ProjectiveTransform(matrix=inverse_map) @@ -1075,19 +1079,19 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1, coords = warp_coords(coord_map, (rows, cols, bands)) - # Prefilter not necessary for order 0, 1 interpolation + # Pre-filtering not necessary for order 0, 1 interpolation prefilter = order > 1 out = ndimage.map_coordinates(image, coords, prefilter=prefilter, mode=mode, order=order, cval=cval) - # The spline filters sometimes return results outside [0, 1], - # so clip to ensure valid data - clipped = np.clip(out, 0, 1) + # The spline filters sometimes return results outside [0, 1], + # so clip to ensure valid data + clipped = np.clip(out, 0, 1) - if mode == 'constant' and not (0 <= cval <= 1): - clipped[out == cval] = cval + if mode == 'constant' and not (0 <= cval <= 1): + clipped[out == cval] = cval - out = clipped + out = clipped if out.ndim == 3 and orig_ndim == 2: # remove singleton dimension introduced by atleast_3d diff --git a/skimage/transform/_warps_cy.pyx b/skimage/transform/_warps_cy.pyx index b3136c22..433c586d 100644 --- a/skimage/transform/_warps_cy.pyx +++ b/skimage/transform/_warps_cy.pyx @@ -89,11 +89,11 @@ def _warp_fast(cnp.ndarray image, cnp.ndarray H, output_shape=None, cdef Py_ssize_t out_r, out_c if output_shape is None: - out_r = img.shape[0] - out_c = img.shape[1] + out_r = int(img.shape[0]) + out_c = int(img.shape[1]) else: - out_r = output_shape[0] - out_c = output_shape[1] + out_r = int(output_shape[0]) + out_c = int(output_shape[1]) cdef double[:, ::1] out = np.zeros((out_r, out_c), dtype=np.double) From af16654230a0323ed67ed8931f74fc4d7ff6244c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sun, 27 Oct 2013 08:25:47 +0100 Subject: [PATCH 2/2] Set version to 0.9.3 --- bento.info | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bento.info b/bento.info index 55b31a99..b01a09d1 100644 --- a/bento.info +++ b/bento.info @@ -1,5 +1,5 @@ Name: scikit-image -Version: 0.9.2 +Version: 0.9.3 Summary: Image processing routines for SciPy Url: http://scikit-image.org DownloadUrl: http://github.com/scikit-image/scikit-image diff --git a/setup.py b/setup.py index fdd05274..2420c33c 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ MAINTAINER_EMAIL = 'stefan@sun.ac.za' URL = 'http://scikit-image.org' LICENSE = 'Modified BSD' DOWNLOAD_URL = 'http://github.com/scikit-image/scikit-image' -VERSION = '0.9.2' +VERSION = '0.9.3' PYTHON_VERSION = (2, 5) DEPENDENCIES = { 'numpy': (1, 6),