Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@fubel
Created September 4, 2016 09:43
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save fubel/ad01878c5a08a57be9b8b80605ad1247 to your computer and use it in GitHub Desktop.
Save fubel/ad01878c5a08a57be9b8b80605ad1247 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()
@shreyaspimpalgaonkar
Copy link

Hey!

Do you know of a implementation in python that gives radon transform as a matrix?

A MATLAB implementation is here

@maky-hnou
Copy link

@Shreyas-7, there is a function called radon() from scikit-image package

from skimage.transform import radon
import cv2
import numpy as np


img = cv2.imread('your_image', 0)  # read image in grayscale
I = img - np.mean(img)
sinogram = radon(I)

@nafe93
Copy link

nafe93 commented Mar 17, 2020

def discrete_radon_transform(img, steps): # shape w, h = img.shape zero = np.zeros((w, steps), dtype='float64') # sum and roatate for s in range(steps): rotation = rotate(img, s, reshape=False).astype('float64') # sum zero[:, s] = np.sum(rotation, axis=0) # rotate image zero = rotate(zero, 180, reshape=False).astype('float64') return zero

@hakao32
Copy link

hakao32 commented Mar 17, 2021

This code isnt working.

@fubel
Copy link
Author

fubel commented Mar 31, 2021

@hakao32 imrotate is deprecated, you have to substitute it with sklearn's transform.rotate:
https://docs.scipy.org/doc/scipy-1.2.1/reference/generated/scipy.misc.imrotate.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment