From 7f100ac1b465d088195802525bba2d3a557c481a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 15:23:23 +0200 Subject: [PATCH] Full test coverage for image pyramids --- skimage/transform/tests/test_pyramids.py | 49 +++++++++++++++++++----- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/skimage/transform/tests/test_pyramids.py b/skimage/transform/tests/test_pyramids.py index 611ecdec..dd976a7b 100644 --- a/skimage/transform/tests/test_pyramids.py +++ b/skimage/transform/tests/test_pyramids.py @@ -1,41 +1,72 @@ -from numpy.testing import assert_array_equal, run_module_suite +from numpy.testing import assert_array_equal, assert_raises, run_module_suite from skimage import data -from skimage.transform import (pyramid_reduce, pyramid_expand, - pyramid_gaussian, pyramid_laplacian) +from skimage.transform import pyramids image = data.lena() +image_gray = image[..., 0] def test_pyramid_reduce(): + # RGB image rows, cols, dim = image.shape - out = pyramid_reduce(image, downscale=2) + out = pyramids.pyramid_reduce(image, downscale=2) assert_array_equal(out.shape, (rows / 2, cols / 2, dim)) + # grayscale image + rows, cols = image_gray.shape + out = pyramids.pyramid_reduce(image_gray, downscale=2) + assert_array_equal(out.shape, (rows / 2, cols / 2)) + def test_pyramid_expand(): + # RGB image rows, cols, dim = image.shape - out = pyramid_expand(image, upscale=2) + out = pyramids.pyramid_expand(image, upscale=2) assert_array_equal(out.shape, (rows * 2, cols * 2, dim)) + # grayscale image + rows, cols = image_gray.shape + out = pyramids.pyramid_expand(image_gray, upscale=2) + assert_array_equal(out.shape, (rows * 2, cols * 2)) + def test_build_gaussian_pyramid(): + # RGB image rows, cols, dim = image.shape - pyramid = pyramid_gaussian(image, downscale=2) - + pyramid = pyramids.pyramid_gaussian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) + # grayscale image + rows, cols = image_gray.shape + pyramid = pyramids.pyramid_gaussian(image_gray, downscale=2) + for layer, out in enumerate(pyramid): + layer_shape = (rows / 2 ** layer, cols / 2 ** layer) + assert_array_equal(out.shape, layer_shape) + def test_build_laplacian_pyramid(): + # RGB image rows, cols, dim = image.shape - pyramid = pyramid_laplacian(image, downscale=2) - + pyramid = pyramids.pyramid_laplacian(image, downscale=2) for layer, out in enumerate(pyramid): layer_shape = (rows / 2 ** layer, cols / 2 ** layer, dim) assert_array_equal(out.shape, layer_shape) + # grayscale image + rows, cols = image_gray.shape + pyramid = pyramids.pyramid_laplacian(image_gray, downscale=2) + for layer, out in enumerate(pyramid): + layer_shape = (rows / 2 ** layer, cols / 2 ** layer) + assert_array_equal(out.shape, layer_shape) + + +def test_check_factor(): + assert_raises(ValueError, pyramids._check_factor, 0.99) + assert_raises(ValueError, pyramids._check_factor, - 2) + if __name__ == "__main__": run_module_suite()