-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref: separate _Radon.py into radon_prl.py and radon_fan.py (#2)
- Loading branch information
1 parent
92bfff5
commit 1850c94
Showing
6 changed files
with
134 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import numpy as np | ||
import scipy.ndimage | ||
|
||
|
||
def radon_parallel(arr, angles, count=None, max_count=None,): | ||
"""Compute the Radon transform (sinogram) of a circular image. | ||
The :mod:`scipy` Radon transform performs this operation on the | ||
entire image, whereas this implementation requires an input | ||
image that has gray-scale values of 0 outside of a circle | ||
with diameter equal to the image size. | ||
Parameters | ||
---------- | ||
arr: ndarray, shape (N,N) | ||
the input image. | ||
angles: ndarray, length A | ||
angles or projections in radians | ||
count, max_count: multiprocessing.Value or `None` | ||
Can be used to monitor the progress of the algorithm. | ||
Initially, the value of `max_count.value` is incremented | ||
by the total number of steps. At each step, the value | ||
of `count.value` is incremented. | ||
Returns | ||
------- | ||
outarr: ndarray of floats, shape (A, N) | ||
Sinogram of the input image. The i'th row contains the | ||
projection data of the i'th angle. | ||
See Also | ||
-------- | ||
scipy.ndimage.interpolation.rotate : | ||
The interpolator used to rotate the image. | ||
""" | ||
# This function also works with single angles | ||
angles = np.atleast_1d(angles) | ||
A = angles.shape[0] | ||
N = len(arr) | ||
# The radon function from skimage.transform does not allow | ||
# to reshape the image (one could cut it of course). | ||
# outarray: x-axis: projection | ||
# y-axis: | ||
outarr = np.zeros((A, N)) | ||
|
||
# progress monitoring | ||
if max_count is not None: | ||
max_count.value += A + 1 | ||
if count is not None: | ||
count.value += 1 | ||
|
||
for i in np.arange(A): | ||
rotated = scipy.ndimage.rotate(arr, | ||
angles[i] / np.pi * 180, | ||
order=3, | ||
reshape=False, | ||
mode="constant", | ||
cval=0) | ||
# sum along the axis. | ||
outarr[i] = rotated.sum(axis=0) | ||
if count is not None: | ||
count.value += 1 | ||
return outarr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import numpy as np | ||
|
||
import radontea | ||
|
||
|
||
def test_radon_simple(): | ||
x = np.zeros((10, 10)) | ||
x[2:5, 3:6] = 1 | ||
sino = radontea.radon_parallel(x, angles=[0, np.pi/2, np.pi, np.pi*3/2]) | ||
assert np.allclose(sino[0], [0, 0, 0, 3, 3, 3, 0, 0, 0, 0]) | ||
assert np.allclose(sino[1], [0, 0, 3, 3, 3, 0, 0, 0, 0, 0]) | ||
assert np.allclose(sino[2], [0, 0, 0, 0, 3, 3, 3, 0, 0, 0]) | ||
assert np.allclose(sino[3], [0, 0, 0, 0, 0, 3, 3, 3, 0, 0]) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Run all tests | ||
loc = locals() | ||
for key in list(loc.keys()): | ||
if key.startswith("test_") and hasattr(loc[key], "__call__"): | ||
loc[key]() |