-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
iradon filter function #3099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
iradon filter function #3099
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a26dfd5
Correcting the filters in the iradon function to match those of MATLA…
a0decc7
Nothing
526c09f
Fix PEP8 Issues
31bdada
Fixed PEP8 Issues
949acb8
Deleted cache file
b564712
Removed cache files
4b6852d
transform: fix filter bias
kczimm b00d414
fix pep issues
kczimm 588e32b
add singleton dimension when necessary
kczimm abdccb0
add recon bias test
kczimm 8f8b945
add iradon_filter function
kczimm 170f021
start of tests
kczimm 89c344b
Merge branch 'master' into iradon-filter-tests
kczimm 0bdef5c
add reference
kczimm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -117,6 +117,67 @@ def _sinogram_circle_to_square(sinogram): | |
return np.pad(sinogram, pad_width, mode='constant', constant_values=0) | ||
|
||
|
||
def iradon_filter(filter_name, size): | ||
""" | ||
Create iradon filter. | ||
|
||
Generate a reconstruction kernel to be used in iradon during | ||
the filtered back-projection algorithm. | ||
|
||
Parameters | ||
---------- | ||
filter_name : str | ||
Name of the filter. | ||
size : int | ||
Length of the filter array. | ||
|
||
Returns | ||
------- | ||
kernel : array_like, dtype=float | ||
Reconstruction filter to be used in iradon. | ||
|
||
References | ||
---------- | ||
.. [1] AC Kak, M Slaney, "Principles of Computerized Tomographic | ||
Imaging", IEEE Press 1988. | ||
""" | ||
# Construct the Fourier filter | ||
|
||
# The ramp filter is implemented based on eq. 61 on p.72 of Kak and Slaney | ||
# https://engineering.purdue.edu/~malcolm/pct/CTI_Ch03.pdf | ||
n1 = np.arange(0, size / 2 + 1, dtype=np.int) | ||
n2 = np.arange(size / 2 - 1, 0, -1, dtype=np.int) | ||
n = np.concatenate((n1, n2)) | ||
f = np.zeros(size) | ||
f[0] = 0.25 | ||
f[1::2] = -1 / (np.pi * n[1::2])**2 | ||
|
||
omega = 2 * np.pi * fftfreq(size) | ||
kernel = 2 * np.real(fft(f)) # ramp filter | ||
if filter_name == "ramp": | ||
pass | ||
elif filter_name == "shepp-logan": | ||
# Start from first element to avoid divide by zero | ||
kernel[1:] *= np.sin(omega[1:] / 2) / (omega[1:] / 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be Since
|
||
elif filter_name == "cosine": | ||
freq = (0.5 * np.arange(0, size) | ||
/ size) | ||
cosine_filter = np.fft.fftshift(np.sin(2 * np.pi * np.abs(freq))) | ||
kernel *= cosine_filter | ||
elif filter_name == "hamming": | ||
hamming_filter = np.fft.fftshift(np.hamming(size)) | ||
kernel *= hamming_filter | ||
elif filter_name == "hann": | ||
hanning_filter = np.fft.fftshift(np.hanning(size)) | ||
kernel *= hanning_filter | ||
elif filter_name is None: | ||
kernel[:] = 1 | ||
else: | ||
raise ValueError("Unknown filter: %s" % filter_name) | ||
|
||
return kernel[:, np.newaxis] | ||
|
||
|
||
def iradon(radon_image, theta=None, output_size=None, | ||
filter="ramp", interpolation="linear", circle=True): | ||
""" | ||
|
@@ -203,25 +264,8 @@ def iradon(radon_image, theta=None, output_size=None, | |
pad_width = ((0, projection_size_padded - radon_image.shape[0]), (0, 0)) | ||
img = np.pad(radon_image, pad_width, mode='constant', constant_values=0) | ||
|
||
# Construct the Fourier filter | ||
f = fftfreq(projection_size_padded).reshape(-1, 1) # digital frequency | ||
omega = 2 * np.pi * f # angular frequency | ||
fourier_filter = 2 * np.abs(f) # ramp filter | ||
if filter == "ramp": | ||
pass | ||
elif filter == "shepp-logan": | ||
# Start from first element to avoid divide by zero | ||
fourier_filter[1:] = fourier_filter[1:] * np.sin(omega[1:]) / omega[1:] | ||
elif filter == "cosine": | ||
fourier_filter *= np.cos(omega) | ||
elif filter == "hamming": | ||
fourier_filter *= (0.54 + 0.46 * np.cos(omega / 2)) | ||
elif filter == "hann": | ||
fourier_filter *= (1 + np.cos(omega / 2)) / 2 | ||
elif filter is None: | ||
fourier_filter[:] = 1 | ||
else: | ||
raise ValueError("Unknown filter: %s" % filter) | ||
fourier_filter = iradon_filter(filter, projection_size_padded) | ||
|
||
# Apply filter in Fourier domain | ||
projection = fft(img, axis=0) * fourier_filter | ||
radon_filtered = np.real(ifft(projection, axis=0)) | ||
|
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please mention Kak & Slaney here and the number of the equation, otherwise it is very difficult to understand where it comes from (as opposed to the naive ramp filter, which is much easier to understand)