toupy.simulation package

Submodules

toupy.simulation.phantom_creator module

Module to create the Shepp-Logan phantom for simulation Forked from https://jenda.hrach.eu/f2/cat-py/phantom.py

toupy.simulation.phantom_creator.phantom(N=256, phantom_type='Modified Shepp-Logan', ellipses=None)[source]

Create a Shepp-Logan [#shepp-logan]_ or modified Shepp-Logan phantom [#toft]_ . A phantom is a known object (either real or purely mathematical) that is used for testing image reconstruction algorithms. The Shepp-Logan phantom is a popular mathematical model of a cranial slice, made up of a set of ellipses. This allows rigorous testing of computed tomography (CT) algorithms as it can be analytically transformed with the radon transform.

Parameters:
  • N (int) – The edge length of the square image to be produced

  • phantom_type (str, optional) – The type of phantom to produce. Either Modified Shepp-Logan or Shepp-Logan. The default value is Modified Shepp-Logan. This is overriden if ellipses is also specified.

  • ellipses (array like) – Custom set of ellipses to use.

Notes

To use ellipses, these should be in the form [[I, a, b, x0, y0, phi], [I, a, b, x0, y0, phi], ...] where each row defines an ellipse and:

  • I : Additive intensity of the ellipse.

  • a : Length of the major axis.

  • b : Length of the minor axis.

  • x0 : Horizontal offset of the centre of the ellipse.

  • y0 : Vertical offset of the centre of the ellipse.

  • phi : Counterclockwise rotation of the ellipse in degrees, measured as the angle between the horizontal axis and the ellipse major axis.

The image bouding box in the algorithm is [-1, -1], [1, 1], so the values of a, b, x0 and y0 should all be specified with respect to this box.

Returns:

P – A 2-dimensional array containing th Shepp-Logan phantom image.

Return type:

ndarray

Examples

>>> import matplotlib.pyplot as plt
>>> P = phantom()
>>> # P = phantom(256, 'Modified Shepp-Logan', None)
>>> plt.imshow(P)

References

toupy.simulation.phantom_creator.phantom3d(N=128, n_v=None, phantom_type='Modified Shepp-Logan', ellipsoids=None)[source]

Create a 3-D Shepp-Logan or modified Shepp-Logan phantom.

Extends phantom() to three dimensions by adding a z semi-axis c and a z centre offset z0 to each ellipsoid. The coordinate system is normalised to [-1, 1] along every axis, so all ellipsoid parameters should be given relative to that box.

Parameters:
  • N (int, optional) – Number of voxels along the transaxial (x and y) directions. Default is 128.

  • n_v (int or None, optional) – Number of voxels along the axial (z) direction. If None (default), n_v = N is used, producing a cube.

  • phantom_type (str, optional) – Built-in phantom variant. Either 'Shepp-Logan' or 'Modified Shepp-Logan' (default). Ignored when ellipsoids is supplied.

  • ellipsoids (array-like or None, optional) –

    Custom ellipsoid table. Each row must have eight elements:

    [I, a, b, c, x0, y0, z0, phi]
    

    where

    • I — additive intensity.

    • a — semi-axis length along x (after rotation by phi).

    • b — semi-axis length along y (after rotation by phi).

    • c — semi-axis length along z.

    • x0 — x centre offset in [-1, 1].

    • y0 — y centre offset in [-1, 1].

    • z0 — z centre offset in [-1, 1].

    • phi — counter-clockwise rotation of the ellipsoid in the xy-plane, in degrees.

Returns:

p – 3-D phantom volume. Axis order is (z, y, x).

Return type:

ndarray, shape (n_v, N, N)

Examples

>>> from toupy.simulation import phantom3d
>>> vol = phantom3d(N=64)            # cube, 64^3
>>> vol = phantom3d(N=64, n_v=48)   # 64 x 64 transaxial, 48 axial slices
>>> import matplotlib.pyplot as plt
>>> plt.imshow(vol[vol.shape[0]//2], cmap='bone')  # central axial slice

Notes

The 3-D Shepp-Logan ellipsoid parameters are taken from the extension of the original Shepp-Logan table commonly used in cone-beam CT simulation literature. The z semi-axes are chosen to give a realistic head-shaped volume at the typical aspect ratio used in medical imaging.

See also

phantom

2-D Shepp-Logan phantom.

References