[][src]Crate shepplogan

Shepp-Logan phantom

Have you ever had the need to create hundreds to thousands of Shepp-Logan phantoms per second? Well if you do, you're doing something wrong, but you've come to the right place. The Shepp-Logan phantom is a numerical phantom which is defined as the sum of 10 ellipses. It is often used as a test image for image reconstruction algorithms. This crate provides a dependency-free, efficient implementation for creating Shepp-Logan phantoms in 2D. The following results were obtained with cargo bench on an Intel Core i7 with 2.70GHz:

Resolution time fps
128x128 111,000ns 9000
256x256 440,000ns 2200
512x512 1,780,000ns 560

Two versions are provided: The original version as described in [0] and a modified version, which has higher contrast as described in [1]. If you do not know the difference between those two, you most likely want the modified version.

To use the crate, add shepplogan to your Cargo.toml:

shepplogan = "^1"


extern crate shepplogan;
use shepplogan::{shepplogan, shepplogan_modified};

// Dimensions of the image grid
let (nx, ny) = (256, 320);

// Original Shepp-Logan Phantom (the dynamic range is between 0.0 and 2.0)
let phantom = shepplogan(nx, ny);

// Modified Shepp-Logan Phantom (the dynamic range is between 0.0 and 1.0)
let phantom_modified = shepplogan_modified(nx, ny);

See examples/example.rs for an example which saves the phantom to disk.

You can also create your own phantom by defining ellipses:

extern crate shepplogan;
use shepplogan::{phantom, Ellipse};

// Dimensions of the image grid
let (nx, ny) = (256, 320);

// Define two ellipses
let ellipses =
        Ellipse::new(0.0, -0.0184, 0.6624, 0.874, 0.0, -0.98),
        Ellipse::new(0.0, 0.0, 0.69, 0.92, 0.0, 2.0),

let ph = phantom(&ellipses, nx, ny);

This will create a phantom consisting of two ellipses.


[0] Shepp, LA and Logan BF, "The Fourier reconstruction of a head section." IEEE Transactions on Nuclear Science 21, No. 3 (1974)

[1] Toft, PA, "The Radon Transform - Theory and Implementation", PhD dissertation, Departement of Mathematical Modelling, Technical University of Denmark (1996)






Creates a phantom based on given ellipses


Original Shepp-Logan phantom


Modified Shepp-Logan phantom with better contrast