ENH: test_warp test case to make sure _warp_coords works for grey and rgb images

This commit is contained in:
James Bergstra
2012-08-20 19:15:36 -04:00
committed by Johannes Schönberger
parent c22a176e8d
commit ce200f570f
+29
View File
@@ -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()