mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 08:30:06 +08:00
Full test coverage for structural similarity
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user