From aa85b22f6da450d258931efec8f87ac5165cdb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Sat, 6 Oct 2012 19:36:09 +0200 Subject: [PATCH] Full test coverage for structural similarity --- .../tests/test_structural_similarity.py | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/skimage/measure/tests/test_structural_similarity.py b/skimage/measure/tests/test_structural_similarity.py index 3eb2a7e9..d2ddc774 100644 --- a/skimage/measure/tests/test_structural_similarity.py +++ b/skimage/measure/tests/test_structural_similarity.py @@ -1,5 +1,5 @@ import numpy as np -from numpy.testing import assert_equal +from numpy.testing import assert_equal, assert_raises from skimage.measure import structural_similarity as ssim @@ -24,20 +24,18 @@ def test_ssim_image(): S1 = ssim(X, Y, win_size=3) assert(S1 < 0.3) -## Come up with a better way of testing the gradient -## -## def test_ssim_grad(): -## N = 30 -## X = np.random.random((N, N)) * 255 -## Y = np.random.random((N, N)) * 255 -## def func(Y): -## return ssim(X, Y, dynamic_range=255) +def test_ssim_grad(): + N = 30 + X = np.random.random((N, N)) * 255 + Y = np.random.random((N, N)) * 255 -## def grad(Y): -## return ssim(X, Y, dynamic_range=255, gradient=True)[1] + f = ssim(X, Y, dynamic_range=255) + g = ssim(X, Y, dynamic_range=255, gradient=True) -## assert(np.all(opt.check_grad(func, grad, Y) < 0.05)) + assert f < 0.05 + assert g[0] < 0.05 + assert np.all(g[1] < 0.05) def test_ssim_dtype(): @@ -56,5 +54,15 @@ def test_ssim_dtype(): assert S2 < 0.1 +def test_invalid_input(): + X = np.zeros((3, 3), dtype=np.double) + Y = np.zeros((3, 3), dtype=np.int) + assert_raises(ValueError, ssim, X, Y) + + Y = np.zeros((4, 4), dtype=np.double) + assert_raises(ValueError, ssim, X, Y) + + assert_raises(ValueError, ssim, X, X, win_size=8) + if __name__ == "__main__": np.testing.run_module_suite()