Skip to content

Instantly share code, notes, and snippets.

@vanishinggradient
Forked from fubel/radon_transform.py
Created July 14, 2022 22:41
Show Gist options
  • Save vanishinggradient/b08b55a79bef75c912168424ece6bae7 to your computer and use it in GitHub Desktop.
Save vanishinggradient/b08b55a79bef75c912168424ece6bae7 to your computer and use it in GitHub Desktop.
Python implementation of the Radon Transform
""" Radon Transform as described in Birkfellner, Wolfgang. Applied Medical Image Processing: A Basic Course. [p. 344] """
from scipy import misc
import numpy as np
import matplotlib.pyplot as plt
def discrete_radon_transform(image, steps):
R = np.zeros((steps, len(image)), dtype='float64')
for s in range(steps):
rotation = misc.imrotate(image, -s*180/steps).astype('float64')
R[:,s] = sum(rotation)
return R
# Read image as 64bit float gray scale
image = misc.imread('shepplogan.png', flatten=True).astype('float64')
radon = discrete_radon_transform(image, 220)
# Plot the original and the radon transformed image
plt.subplot(1, 2, 1), plt.imshow(image, cmap='gray')
plt.xticks([]), plt.yticks([])
plt.subplot(1, 2, 2), plt.imshow(radon, cmap='gray')
plt.xticks([]), plt.yticks([])
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment