Scikit Image - Radon Transform



The Radon transform is a mathematical technique used in image processing and tomography to analyze and reconstruct images from their projections. It plays a significant role in computed tomography (CT) and other medical imaging applications.

In general, the Radon transform takes projections and mathematically transforms them into a different representation called a "sinogram", which is a linear transform of the original image. The sinogram captures the intensity values of the object's projections at different angles. The Radon transform essentially converts the data from the spatial domain (original image) into the Radon domain (sinogram).

To reconstruct the original image from the sinogram, the inverse Radon transform is applied.

In Scikit-image, the Radon transform and its inverse can be performed using the radon(), iradon(), and iradon_sart() functions. These functions allow you to simulate tomography experiments, perform the Radon transform, and reconstruct images using different algorithms.

Using the skimage.transform.radon() function

The skimage.transform.radon() function is used to compute the Radon transform of an input image, given specified projection angles.

Syntax

Following is the syntax of this function −

skimage.transform.radon(image, theta=None, circle=True, *, preserve_range=False)

Parameters

  • image: An array-like object representing the input image. The rotation axis for the Radon transform will be placed at the pixel indices (image.shape[0] // 2, image.shape[1] // 2), which corresponds to the center of the image.
  • theta (optional): An array-like object containing the projection angles(in degrees) at which the Radon transform should be computed. If set to None, the default value is np.arange(180).
  • circle (optional): A boolean flag that determines whether to assume the image is zero outside the inscribed circle. If set to True, the width of each projection in the resulting sinogram will be equal to the minimum of the image's width and height.
  • preserve_range (optional): A boolean flag that controls whether to keep the original range of values in the output sinogram. If set to True, the sinogram will retain the original value range. If set to False, the input image will be converted to a floating-point format following the conventions of img_as_float.

Return Value

It returns an ndarray(radon_image) representing the computed Radon transform (sinogram) of the input image. The tomography rotation axis will be positioned at the pixel index radon_image.shape[0] // 2 along the 0th dimension of radon_image.

Example

The following example demonstrates how to use the radon() function to perform the radon transform of an image with specified projection angles.

import numpy as np
import matplotlib.pyplot as plt
from skimage import transform, io

# Load an input image
image = io.imread('Images/test image.png', as_gray=True)
image = transform.rescale(image, scale=0.4, mode='reflect', channel_axis=None)

# Define projection angles
theta = np.linspace(0, 180, 180, endpoint=False)

# Perform Radon transform
sinogram = transform.radon(image, theta=theta)

# Perform inverse Radon transform using Filtered Back Projection algorithm
reconstructed = transform.iradon(sinogram , theta=theta)

# Plot the original and transformed images side by side
fig, axes = plt.subplots(1, 2, figsize=(10, 5))
axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(sinogram, cmap='gray', aspect='auto', extent=(0, 180, 0, sinogram.shape[0]))
axes[1].set_title('Radon Transform')
axes[1].set_xlabel('Projection Angle (degrees)')
axes[1].set_ylabel('Projection Position(pixels)')
plt.tight_layout()
plt.show()

Output

On executing the above program, you will get the following output −

Using the skimage.transform.iradon function

The skimage.transform.iradon() function is used for performing an inverse Radon transform to reconstruct an image from its radon transform (sinogram) using the filtered back projection algorithm.

Syntax

Following is the syntax of this function −

skimage.transform.iradon(radon_image, theta=None, output_size=None, filter_name='ramp', interpolation='linear', circle=True, preserve_range=True)

Parameters

  • radon_image: A 2D array representing the input radon transform (sinogram). Each column of the image corresponds to a projection along a different angle. The tomography rotation axis should positioned at the pixel index radon_image.shape[0] // 2 along the 0th dimension of radon_image.
  • theta (optional): A 1D array specifying the reconstruction angles (in degrees). The default is to use angles evenly spaced between 0 and 180 degrees, with the number of angles determined by the shape of radon_image.
  • output_size (optional): An integer specifying the number of rows and columns in the reconstructed image.
  • filter_name (optional): A string specifying the filter used for frequency domain filtering. The default is the ramp filter. Other available filters include: 'ramp', 'shepp-logan', 'cosine', 'hamming', and 'hann'. Assigning None results in no filtering.
  • interpolation (optional): A string indicating the interpolation method used during reconstruction. Options include: 'linear', 'nearest', and 'cubic' (note that 'cubic' can be slower).
  • circle (optional): A boolean flag that determines whether to assume that the reconstructed image is zero outside the inscribed circle. This also modifies the default output_size to match the behavior of the radon function when called with circle=True.
  • preserve_range (optional): A boolean flag determining whether to retain the original range of values. If set to True, the input image is preserved as is. Otherwise, the input image is converted according to the conventions of img_as_float.

Return Value

It returns an ndarray representing the reconstructed image. The rotation axis will be located at the pixel indices (reconstructed.shape[0] // 2, reconstructed.shape[1] // 2).

Example

The following example demonstrates how to use the iradon() function to perform the inverse radon transform to reconstruct an image from its radon transform (sinogram) using the Filtered Back Projection algorithm.

import numpy as np
import matplotlib.pyplot as plt
from skimage import transform, io

# Load an input image
image = io.imread('Images/test image.png', as_gray=True)
image = transform.rescale(image, scale=0.4, mode='reflect', channel_axis=None)

# Define projection angles
theta = np.linspace(0, 180, 180, endpoint=False)

# Perform Radon transform
sinogram = transform.radon(image, theta=theta)

# Perform inverse Radon transform using Filtered Back Projection algorithm
reconstructed = transform.iradon(sinogram , theta=theta)

# Plot the original, transformed, and Reconstructed images side by side
fig, axes = plt.subplots(1, 3, figsize=(12, 4))

axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(sinogram, cmap='gray', aspect='auto', extent=(0, 180, 0, sinogram.shape[0]))
axes[1].set_title('Radon Transform')
axes[1].set_xlabel('Projection Angle (degrees)')
axes[1].set_ylabel('Projection Position(pixels)')

axes[2].imshow(reconstructed, cmap='gray')
axes[2].set_title('Reconstructed Image\nFiltered back projection')
axes[2].axis('off')

plt.tight_layout()
plt.show()

Output

On executing the above program, you will get the following output −

Using the skimage.transform.iradon_sart() function

The skimage.transform.iradon_sart() function is used for performing an inverse radon transform to reconstruct an image from its radon transform (sinogram) using a single iteration of the Simultaneous Algebraic Reconstruction Technique (SART) algorithm. The SART algorithm is an iterative method commonly used in computed tomography (CT) for image reconstruction from projection data.

Syntax

Following is the syntax of this function −

skimage.transform.iradon_sart(radon_image, theta=None, image=None, projection_shifts=None, clip=None, relaxation=0.15, dtype=None)

Parameters

  • radon_image: A 2D array representing the input radon transform (sinogram). Each column of the image corresponds to a projection along a different angle. The tomography rotation axis should positioned at the pixel index radon_image.shape[0] // 2 along the 0th dimension of radon_image.
  • theta (optional): A 1D array specifying the reconstruction angles (in degrees). The default is to use angles evenly spaced between 0 and 180 degrees, with the number of angles determined by the shape of radon_image.
  • image (optional): A 2D array representing an initial reconstruction estimate. The shape of this array should match the shape of radon_image. The default is an array of zeros.
  • projection_shifts (optional): A 1D array specifying how much to shift the projections in radon_image before reconstructing the image. This can be useful for correcting alignment issues. The i'th value defines the shift of the i'th column of radon_image.
  • clip (optional): A length-2 sequence of floats that enforces the range of values in the reconstructed tomogram to lie between clip[0] and clip[1].
  • relaxation (optional): A float value controlling the relaxation parameter for the update step of the SART algorithm. A higher value can improve convergence rate, but too high values may lead to instability. Values close to or higher than 1 are not recommended.
  • dtype (optional): The output data type for the reconstructed image. By default, if the input data type is not float, the input is cast to double. Otherwise, dtype is set to the input data type.

Return Value

It returns an ndarray representing the reconstructed image. The rotation axis will be located at the pixel indices (reconstructed.shape[0] // 2, reconstructed.shape[1] // 2).

Example

The following example demonstrates how to use the iradon() function to perform the inverse radon transform to reconstruct an image from its radon transform (sinogram) using the SART algorithm.

import numpy as np
import matplotlib.pyplot as plt
from skimage import transform, io

# Load an input image
image = io.imread('Images/test image.png', as_gray=True)
image = transform.rescale(image, scale=0.4, mode='reflect', channel_axis=None)

# Define projection angles
theta = np.linspace(0, 180, 180, endpoint=False)

# Perform Radon transform
sinogram = transform.radon(image, theta=theta)

# Perform inverse Radon transform using the SART algorithm
reconstructed = transform.iradon_sart(sinogram , theta=theta)

# Plot the original, transformed, and Reconstructed images side by side
fig, axes = plt.subplots(1, 3, figsize=(12, 4))

axes[0].imshow(image, cmap='gray')
axes[0].set_title('Original Image')
axes[0].axis('off')

axes[1].imshow(sinogram, cmap='gray', aspect='auto', extent=(0, 180, 0, sinogram.shape[0]))
axes[1].set_title('Radon Transform')
axes[1].set_xlabel('Projection Angle (degrees)')
axes[1].set_ylabel('Projection Position(pixels)')

axes[2].imshow(reconstructed, cmap='gray')
axes[2].set_title('Reconstructed Image\nSART')
axes[2].axis('off')
plt.tight_layout()
plt.show()

Output

On executing the above program, you will get the following output −

Advertisements