Skip to content

Instantly share code, notes, and snippets.

@MatthewJA
Created November 24, 2017 00:51
Show Gist options
  • Save MatthewJA/12e74d26ba6f476cda88b8c85c3d8f84 to your computer and use it in GitHub Desktop.
Save MatthewJA/12e74d26ba6f476cda88b8c85c3d8f84 to your computer and use it in GitHub Desktop.
Fast(ish) approximation to a radon transform.
import numpy
import scipy.ndimage.interpolation
def radon_transform(ims):
"""Radon transform a batch of images.
Parameters
----------
ims : numpy.ndarray
(N x W x H) NumPy array of N images.
Returns
-------
(N x W x W) NumPy array of radon-transformed images.
"""
projections = numpy.linspace(0, 360, ims.shape[1])
rotations = numpy.transpose(numpy.stack([
scipy.ndimage.interpolation.rotate(ims, projection, axes=(1, 2), reshape=False)
for projection in projections]), (1, 0, 2, 3))
transformed = rotations.sum(axis=3)
return transformed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment