Created
September 4, 2016 09:43
-
-
Save fubel/ad01878c5a08a57be9b8b80605ad1247 to your computer and use it in GitHub Desktop.
Python implementation of the Radon Transform
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
""" 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() |
@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)
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
This code isnt working.
@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
Hey!
Do you know of a implementation in python that gives radon transform as a matrix?
A MATLAB implementation is here