Fixed error in peak_snr, now uses float arithmetic throughout.

This commit is contained in:
Steven Silvester
2012-12-11 23:14:30 -06:00
parent b5f9cf269f
commit 73f5e9dccc
+4 -1
View File
@@ -85,7 +85,7 @@ def test_adapthist_scalar():
assert img.shape == adapted.shape
full_scale = skimage.exposure.rescale_intensity(skimage.img_as_uint(img))
assert_almost_equal = np.testing.assert_almost_equal
assert_almost_equal(peak_snr(full_scale, adapted), 28.626, 3)
assert_almost_equal(peak_snr(full_scale, adapted), 101.231, 3)
assert_almost_equal(norm_brightness_err(full_scale, adapted),
0.041, 3)
return img, adapted
@@ -137,8 +137,11 @@ def peak_snr(img1, img2):
'''
if img1.ndim == 3:
img1, img2 = rgb2gray(img1.copy()), rgb2gray(img2.copy())
img1 = skimage.img_as_float(img1)
img2 = skimage.img_as_float(img2)
mse = 1. / img1.size * np.square(img1 - img2).sum()
_, max_ = dtype_range[img1.dtype.type]
print mse, max_
return 20 * np.log(max_ / mse)