diff --git a/skimage/transform/tests/test_radon_transform.py b/skimage/transform/tests/test_radon_transform.py index e5df9b8d..ae25c970 100644 --- a/skimage/transform/tests/test_radon_transform.py +++ b/skimage/transform/tests/test_radon_transform.py @@ -320,54 +320,57 @@ def test_iradon_sart(): shepp_logan = imread(os.path.join(data_dir, "phantom.png"), as_grey=True) image = rescale(shepp_logan, scale=0.4) - theta = np.linspace(0., 180., image.shape[0], endpoint=False) - sinogram = radon(image, theta, circle=True) - reconstructed = iradon_sart(sinogram, theta) + theta_ordered = np.linspace(0., 180., image.shape[0], endpoint=False) + theta_missing_wedge = np.linspace(0., 150., image.shape[0], endpoint=True) + for theta, error_factor in ((theta_ordered, 1.), + (theta_missing_wedge, 2.)): + sinogram = radon(image, theta, circle=True) + reconstructed = iradon_sart(sinogram, theta) - if debug: - from matplotlib import pyplot as plt - plt.figure() - plt.subplot(221) - plt.imshow(image, interpolation='nearest') - plt.subplot(222) - plt.imshow(sinogram, interpolation='nearest') - plt.subplot(223) - plt.imshow(reconstructed, interpolation='nearest') - plt.subplot(224) - plt.imshow(reconstructed - image, interpolation='nearest') - plt.show() + if debug: + from matplotlib import pyplot as plt + plt.figure() + plt.subplot(221) + plt.imshow(image, interpolation='nearest') + plt.subplot(222) + plt.imshow(sinogram, interpolation='nearest') + plt.subplot(223) + plt.imshow(reconstructed, interpolation='nearest') + plt.subplot(224) + plt.imshow(reconstructed - image, interpolation='nearest') + plt.show() - delta = np.mean(np.abs(reconstructed - image)) - print('delta (1 iteration) =', delta) - assert delta < 0.025 - reconstructed = iradon_sart(sinogram, theta, reconstructed) - delta = np.mean(np.abs(reconstructed - image)) - print('delta (2 iterations) =', delta) - assert delta < 0.015 + delta = np.mean(np.abs(reconstructed - image)) + print('delta (1 iteration) =', delta) + assert delta < 0.016 * error_factor + reconstructed = iradon_sart(sinogram, theta, reconstructed) + delta = np.mean(np.abs(reconstructed - image)) + print('delta (2 iterations) =', delta) + assert delta < 0.013 * error_factor - np.random.seed(1239867) - shifts = np.random.uniform(-3, 3, sinogram.shape[1]) - x = np.arange(sinogram.shape[0]) - sinogram_shifted = np.vstack(np.interp(x + shifts[i], x, sinogram[:, i]) - for i in range(sinogram.shape[1])).T - reconstructed = iradon_sart(sinogram_shifted, theta, - projection_shifts=shifts) - if debug: - from matplotlib import pyplot as plt - plt.figure() - plt.subplot(221) - plt.imshow(image, interpolation='nearest') - plt.subplot(222) - plt.imshow(sinogram_shifted, interpolation='nearest') - plt.subplot(223) - plt.imshow(reconstructed, interpolation='nearest') - plt.subplot(224) - plt.imshow(reconstructed - image, interpolation='nearest') - plt.show() + np.random.seed(1239867) + shifts = np.random.uniform(-3, 3, sinogram.shape[1]) + x = np.arange(sinogram.shape[0]) + sinogram_shifted = np.vstack(np.interp(x + shifts[i], x, sinogram[:, i]) + for i in range(sinogram.shape[1])).T + reconstructed = iradon_sart(sinogram_shifted, theta, + projection_shifts=shifts) + if debug: + from matplotlib import pyplot as plt + plt.figure() + plt.subplot(221) + plt.imshow(image, interpolation='nearest') + plt.subplot(222) + plt.imshow(sinogram_shifted, interpolation='nearest') + plt.subplot(223) + plt.imshow(reconstructed, interpolation='nearest') + plt.subplot(224) + plt.imshow(reconstructed - image, interpolation='nearest') + plt.show() - delta = np.mean(np.abs(reconstructed - image)) - print('delta (1 iteration, shifted sinogram) =', delta) - assert delta < 0.025 + delta = np.mean(np.abs(reconstructed - image)) + print('delta (1 iteration, shifted sinogram) =', delta) + assert delta < 0.018 * error_factor if __name__ == "__main__": from numpy.testing import run_module_suite