From 2bfaafd9e2bdc5470c1c38a1cf568f49d0f00077 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jostein=20B=C3=B8=20Fl=C3=B8ystad?= Date: Sat, 13 Jul 2013 19:31:43 +0200 Subject: [PATCH] Radon transform: Redefine projection center for sinograms. This definition is chosen because it is simple to express in the documentation. No changes in accuracy are to be expected, but comparing sinograms and reconstructions before and after this commit will give different results in the cases where ``circle=False`` for ``radon`` or ``iradon``. --- skimage/transform/radon_transform.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/skimage/transform/radon_transform.py b/skimage/transform/radon_transform.py index 1ebd26c6..9fe1c6e1 100644 --- a/skimage/transform/radon_transform.py +++ b/skimage/transform/radon_transform.py @@ -82,12 +82,15 @@ def radon(image, theta=None, circle=False): else: diagonal = np.sqrt(2) * max(image.shape) pad = [int(np.ceil(diagonal - s)) for s in image.shape] - pad_width = [(p // 2, p - p // 2) for p in pad] + new_center = [(s + p) // 2 for s, p in zip(image.shape, pad)] + old_center = [s // 2 for s in image.shape] + pad_before = [nc - oc for oc, nc in zip(old_center, new_center)] + pad_width = [(pb, p - pb) for pb, p in zip(pad_before, pad)] padded_image = util.pad(image, pad_width, mode='constant', constant_values=0) out = np.zeros((max(padded_image.shape), len(theta))) - dh = pad[0] // 2 + image.shape[0] // 2 - dw = pad[1] // 2 + image.shape[1] // 2 + dh = padded_image.shape[0] // 2 + dw = padded_image.shape[1] // 2 shift0 = np.array([[1, 0, -dw], [0, 1, -dh], @@ -112,7 +115,10 @@ def radon(image, theta=None, circle=False): def _sinogram_circle_to_square(sinogram): diagonal = int(np.ceil(np.sqrt(2) * sinogram.shape[0])) pad = diagonal - sinogram.shape[0] - pad_width = ((pad // 2, pad - pad // 2), (0, 0)) + old_center = sinogram.shape[0] // 2 + new_center = diagonal // 2 + pad_before = new_center - old_center + pad_width = ((pad_before, pad - pad_before), (0, 0)) return util.pad(sinogram, pad_width, mode='constant', constant_values=0) @@ -216,9 +222,7 @@ def iradon(radon_image, theta=None, output_size=None, radon_filtered = radon_filtered[:radon_image.shape[0], :] reconstructed = np.zeros((output_size, output_size)) # Determine the center of the projections (= center of sinogram) - circle_size = int(np.floor(radon_image.shape[0] / np.sqrt(2))) - square_size = radon_image.shape[0] - mid_index = (square_size - circle_size) // 2 + circle_size // 2 + mid_index = radon_image.shape[0] // 2 x = output_size y = output_size