def test_wiener(dtype): psf = np.ones((5, 5), dtype=dtype) / 25 data = convolve2d(test_img, psf, 'same') np.random.seed(0) data += 0.1 * data.std() * np.random.standard_normal(data.shape) data = data.astype(dtype, copy=False) deconvolved = restoration.wiener(data, psf, 0.05) assert deconvolved.dtype == _supported_float_type(dtype) rtol, atol = _get_rtol_atol(dtype) path = fetch('restoration/tests/camera_wiener.npy') np.testing.assert_allclose(deconvolved, np.load(path), rtol=rtol, atol=atol) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) assert otf.real.dtype == _supported_float_type(dtype) deconvolved = restoration.wiener(data, otf, 0.05, reg=laplacian, is_real=False) assert deconvolved.real.dtype == _supported_float_type(dtype) np.testing.assert_allclose(np.real(deconvolved), np.load(path), rtol=rtol, atol=atol)
def test_wiener(): psf = np.ones((5, 5)) / 25 data = convolve2d(test_img, psf, "same") np.random.seed(0) data += 0.1 * data.std() * np.random.standard_normal(data.shape) deconvolved = restoration.wiener(data, psf, 0.05) path = pjoin(dirname(abspath(__file__)), "camera_wiener.npy") np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) deconvolved = restoration.wiener(data, otf, 0.05, reg=laplacian, is_real=False) np.testing.assert_allclose(np.real(deconvolved), np.load(path), rtol=1e-3)
def test_unsupervised_wiener_deprecated_user_param(): psf = np.ones((5, 5), dtype=float) / 25 data = convolve2d(test_img, psf, 'same') otf = uft.ir2tf(psf, data.shape, is_real=False) _, laplacian = uft.laplacian(2, data.shape) with expected_warnings( ["`max_iter` is a deprecated key", "`min_iter` is a deprecated key"]): restoration.unsupervised_wiener(data, otf, reg=laplacian, is_real=False, user_params={ "max_iter": 200, "min_iter": 30 }, random_state=5)
def test_wiener(): psf = np.ones((5, 5)) / 25 data = convolve2d(test_img, psf, 'same') np.random.seed(0) data += 0.1 * data.std() * np.random.standard_normal(data.shape) deconvolved = restoration.wiener(data, psf, 0.05) path = fetch('restoration/tests/camera_wiener.npy') np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) deconvolved = restoration.wiener(data, otf, 0.05, reg=laplacian, is_real=False) np.testing.assert_allclose(np.real(deconvolved), np.load(path), rtol=1e-3)
def test_unsupervised_wiener(): psf = np.ones((5, 5)) / 25 data = convolve2d(test_img, psf, "same") np.random.seed(0) data += 0.1 * data.std() * np.random.standard_normal(data.shape) deconvolved, _ = restoration.unsupervised_wiener(data, psf) path = pjoin(dirname(abspath(__file__)), "camera_unsup.npy") np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) np.random.seed(0) deconvolved = restoration.unsupervised_wiener( data, otf, reg=laplacian, is_real=False, user_params={"callback": lambda x: None} )[0] path = pjoin(dirname(abspath(__file__)), "camera_unsup2.npy") np.testing.assert_allclose(np.real(deconvolved), np.load(path), rtol=1e-3)
def test_unsupervised_wiener(dtype): psf = np.ones((5, 5), dtype=dtype) / 25 data = convolve2d(test_img, psf, 'same') seed = 16829302 # keep old-style RandomState here for compatibility with previously stored # reference data in camera_unsup.npy and camera_unsup2.npy rng = np.random.RandomState(seed) data += 0.1 * data.std() * rng.standard_normal(data.shape) data = data.astype(dtype, copy=False) deconvolved, _ = restoration.unsupervised_wiener(data, psf, random_state=seed) float_type = _supported_float_type(dtype) assert deconvolved.dtype == float_type rtol, atol = _get_rtol_atol(dtype) path = fetch('restoration/tests/camera_unsup.npy') np.testing.assert_allclose(deconvolved, np.load(path), rtol=rtol, atol=atol) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) assert otf.real.dtype == _supported_float_type(dtype) deconvolved2 = restoration.unsupervised_wiener(data, otf, reg=laplacian, is_real=False, user_params={ "callback": lambda x: None, "max_num_iter": 200, "min_num_iter": 30, }, random_state=seed)[0] assert deconvolved2.real.dtype == float_type path = fetch('restoration/tests/camera_unsup2.npy') np.testing.assert_allclose(np.real(deconvolved2), np.load(path), rtol=rtol, atol=atol)
def test_unsupervised_wiener(): psf = np.ones((5, 5)) / 25 data = convolve2d(test_img, psf, 'same') np.random.seed(0) data += 0.1 * data.std() * np.random.standard_normal(data.shape) deconvolved, _ = restoration.unsupervised_wiener(data, psf) path = fetch('restoration/tests/camera_unsup.npy') np.testing.assert_allclose(deconvolved, np.load(path), rtol=1e-3) _, laplacian = uft.laplacian(2, data.shape) otf = uft.ir2tf(psf, data.shape, is_real=False) np.random.seed(0) deconvolved = restoration.unsupervised_wiener( data, otf, reg=laplacian, is_real=False, user_params={"callback": lambda x: None})[0] path = fetch('restoration/tests/camera_unsup2.npy') np.testing.assert_allclose(np.real(deconvolved), np.load(path), rtol=1e-3)