From c63c5e3239e612ba6a864b93d08f106dfa12e0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Fri, 4 Jul 2014 21:08:32 -0400 Subject: [PATCH] Fix bug in bicubic interpolation and extend test cases to higher orders --- skimage/_shared/interpolation.pxd | 6 +++--- skimage/transform/tests/test_warps.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/skimage/_shared/interpolation.pxd b/skimage/_shared/interpolation.pxd index 7d212969..07c54e2f 100644 --- a/skimage/_shared/interpolation.pxd +++ b/skimage/_shared/interpolation.pxd @@ -159,7 +159,7 @@ cdef inline double cubic_interpolation(double x, double[4] f): x : double Position in the interval [0, 1]. f : double[4] - Function values at positions [0, 1/3, 2/3, 1]. + Function values at positions [-1, 0, 1, 2]. Returns ------- @@ -206,8 +206,8 @@ cdef inline double bicubic_interpolation(double* image, Py_ssize_t rows, if c < 0: c0 -= 1 # scale position to range [0, 1] - cdef double xr = (r - r0) / 3 - cdef double xc = (c - c0) / 3 + cdef double xr = r - floor(r) + cdef double xc = c - floor(c) cdef double fc[4] cdef double fr[4] diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index b5206414..aa9cdee3 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -117,7 +117,7 @@ def test_fast_homography(): tform = ProjectiveTransform(H) coords = warp_coords(tform.inverse, (img.shape[0], img.shape[1])) - for order in range(4): + for order in range(6): for mode in ('constant', 'reflect', 'wrap', 'nearest'): p0 = map_coordinates(img, coords, mode=mode, order=order) p1 = warp(img, tform, mode=mode, order=order) @@ -130,8 +130,7 @@ def test_fast_homography(): # ax3.imshow(np.abs(p0 - p1), cmap=plt.cm.gray) # plt.show() - d = np.mean(np.abs(p0 - p1)) - assert d < 0.001 + assert_array_equal(p0, p1) def test_rotate():