From ce200f570f2e7e4b67c24d42a0d0e6f3cdd95243 Mon Sep 17 00:00:00 2001 From: James Bergstra Date: Mon, 20 Aug 2012 19:15:36 -0400 Subject: [PATCH] ENH: test_warp test case to make sure _warp_coords works for grey and rgb images --- skimage/transform/tests/test_warps.py | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/skimage/transform/tests/test_warps.py b/skimage/transform/tests/test_warps.py index 3ef5a2ee..2c2ecf53 100644 --- a/skimage/transform/tests/test_warps.py +++ b/skimage/transform/tests/test_warps.py @@ -1,6 +1,9 @@ +import sys from numpy.testing import assert_array_almost_equal, run_module_suite import numpy as np +import scipy.misc # -- greyscale lena that works without PIL png support + from skimage.transform import (warp, homography, fast_homography, SimilarityTransform, ProjectiveTransform, AffineTransform) @@ -66,6 +69,10 @@ def test_fast_homography(): def test_swirl(): + if not data.checkerboard().shape: + print >> sys.stderr, ('Failed to read image data.checkerboard()' + ' -- Skipping test_fast_homography') + return image = img_as_float(data.checkerboard()) swirl_params = {'radius': 80, 'rotation': 0, 'order': 2, 'mode': 'reflect'} @@ -81,6 +88,28 @@ def test_const_cval_out_of_range(): assert np.any(warped < 0) +def test_warp_identity(): + lena = scipy.misc.lena().astype('float32') / 255 + assert len(lena.shape) == 2 + assert np.allclose(lena, + warp(lena, AffineTransform(rotation=0))) + assert not np.allclose(lena, + warp(lena, AffineTransform(rotation=0.1))) + + rgb_lena = np.transpose( + np.asarray([lena, np.zeros_like(lena), lena]), + (1, 2, 0)) + warped_rgb_lena = warp(rgb_lena, AffineTransform(rotation=0.1)) + + assert np.allclose(rgb_lena, + warp(rgb_lena, AffineTransform(rotation=0))) + assert not np.allclose(rgb_lena, warped_rgb_lena) + # assert no cross-talk between bands + assert np.all(0 == warped_rgb_lena[:, :, 1]) + + + + if __name__ == "__main__": run_module_suite()