From d50afed18ebdf2b312745f9dc8eb2937cf2fd084 Mon Sep 17 00:00:00 2001 From: Juan Nunez-Iglesias Date: Fri, 26 Sep 2014 19:09:13 +1000 Subject: [PATCH] Add test for preserving image shape in deconv I can confirm that this test does not pass in the current master. --- skimage/restoration/tests/test_restoration.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/skimage/restoration/tests/test_restoration.py b/skimage/restoration/tests/test_restoration.py index 0e70af56..f248f613 100644 --- a/skimage/restoration/tests/test_restoration.py +++ b/skimage/restoration/tests/test_restoration.py @@ -2,6 +2,7 @@ from os.path import abspath, dirname, join as pjoin import numpy as np from scipy.signal import convolve2d +from scipy import ndimage as nd import skimage from skimage.data import camera @@ -53,6 +54,29 @@ def test_unsupervised_wiener(): rtol=1e-3) +def test_image_shape(): + """Test that shape of output image in deconvolution is same as input. + + This addresses issue #1172. + """ + point = np.zeros((5, 5), np.float) + point[2, 2] = 1. + psf = nd.gaussian_filter(point, sigma=1.) + # image shape: (45, 45), as reported in #1172 + image = skimage.img_as_float(camera()[110:155, 225:270]) # just the face + image_conv = nd.convolve(image, psf) + deconv_sup = restoration.wiener(image_conv, psf, 1) + deconv_un = restoration.unsupervised_wiener(image_conv, psf)[0] + # test the shape + np.testing.assert_equal(image.shape, deconv_sup.shape) + np.testing.assert_equal(image.shape, deconv_un.shape) + # test the reconstruction error + sup_relative_error = np.abs(deconv_sup - image) / image + un_relative_error = np.abs(deconv_un - image) / image + np.testing.assert_array_less(np.median(sup_relative_error), 0.1) + np.testing.assert_array_less(np.median(un_relative_error), 0.1) + + def test_richardson_lucy(): psf = np.ones((5, 5)) / 25 data = convolve2d(test_img, psf, 'same')