remove multichannel magic and default to False. fix bugs in tests introduced during rebase

This commit is contained in:
Gregory R. Lee
2015-05-15 14:28:48 -04:00
parent d781fc5774
commit 9090aa6afb
2 changed files with 8 additions and 16 deletions
+1 -9
View File
@@ -43,7 +43,7 @@ def gaussian_filter2(X, sigma=1.5, size=11):
def structural_similarity(X, Y, win_size=None, gradient=False,
dynamic_range=None, multichannel=None,
dynamic_range=None, multichannel=False,
gaussian_weights=False, full=False,
image_content_weighting=False, **kwargs):
"""Compute the mean structural similarity index between two images.
@@ -64,7 +64,6 @@ def structural_similarity(X, Y, win_size=None, gradient=False,
multichannel : int or None
If True, treat the last dimension of the array as channels. Similarity
calculations are done independently for each channel then averaged.
Defaults to True only if X is 3D and ``X.shape[2] == 3``.
gaussian_weights : bool
If True, each patch (of size `win_size`) has its mean and variance
spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
@@ -127,13 +126,6 @@ def structural_similarity(X, Y, win_size=None, gradient=False,
raise ValueError(
"gradient not implemented for image content weighted case")
# default treats 3D arrays with shape[2] == 3 as multichannel
if multichannel is None:
if X.ndim == 3 and X.shape[2] == 3:
multichannel = True
else:
multichannel = False
if multichannel:
# loop over channels
args = dict(win_size=win_size,
@@ -93,19 +93,19 @@ def test_ssim_multichannel():
# replicate across three channels. should get identical value
Xc = np.tile(X[..., np.newaxis], (1, 1, 3))
Yc = np.tile(Y[..., np.newaxis], (1, 1, 3))
S2 = ssim(Xc, Yc, win_size=3)
S2 = ssim(Xc, Yc, multichannel=True, win_size=3)
assert_almost_equal(S1, S2)
# full case should return an image as well
m, S3 = ssim(Xc, Yc, full=True)
m, S3 = ssim(Xc, Yc, multichannel=True, full=True)
assert_equal(S3.shape, Xc.shape)
# gradient case
m, grad = ssim(Xc, Yc, gradient=True)
m, grad = ssim(Xc, Yc, multichannel=True, gradient=True)
assert_equal(grad.shape, Xc.shape)
# full and gradient case
m, grad, S3 = ssim(Xc, Yc, full=True, gradient=True)
m, grad, S3 = ssim(Xc, Yc, multichannel=True, full=True, gradient=True)
assert_equal(grad.shape, Xc.shape)
assert_equal(S3.shape, Xc.shape)
@@ -133,12 +133,12 @@ def test_ssim_multichannel_chelsea():
Yc = Yc.astype(Xc.dtype)
# multichannel result should be mean of the individual channel results
mssim = ssim(Xc, Yc)
mssim = ssim(Xc, Yc, multichannel=True)
mssim_sep = [ssim(Yc[..., c], Xc[..., c]) for c in range(Xc.shape[-1])]
assert_almost_equal(mssim, np.mean(mssim_sep))
# ssim of image with itself should be 1.0
assert_equal(ssim(Xc, Xc), 1.0)
assert_equal(ssim(Xc, Xc, multichannel=True), 1.0)
def test_gaussian_mssim_vs_IPOL():
@@ -160,7 +160,7 @@ def test_gaussian_mssim_vs_author_ref():
img2 = imread('camera_noisy.png')
mssim = ssim_index(img1, img2)
"""
mssim_matlab = 0.218987555561590
mssim_matlab = 0.327314295673357
mssim = ssim(cam, cam_noisy, gaussian_weights=True,
use_sample_covariance=False)
assert_almost_equal(mssim, mssim_matlab, decimal=7)