Modules

flexTOMO includes three modules: projector, phantom and model.

The projector module provides access to forward- / back-projection operators and whole reconstruction algorithms. It supports out-of-memory input arrays (numpy.memmap) and can be accelerated through the use of subsets.

Modules model and phantom can be used to simulate both monochromatic and polychromatic conde-beam tomographic acquisition.

flextomo.projector

Created on Oct 2018 @author: Alex Kostenko

This module contains: building blocks for reconstruction algorithms:

back- and forward-projection operators, gradient descent updates

All of the functions support large datasets implemented using numpy.memmap arrays and geometry classes defined in flexData.geometry.

All projectors are based on ASTRA and are GPU-accelerated (CUDA).

flextomo.projector.EM(projections, volume, geometry, iterations)[source]

Expectation Maximization

flextomo.projector.FDK(projections, volume, geometry)[source]

Feldkamp, Davis and Kress cone beam reconstruction. Args:

projections : input numpy.array (dtype = float32) with the following dimensions: [vrt, rot, hrz] volume : output numpy.array (dtype = float32) with the following dimensions: [vrt, mag, hrz] geometry : geometry description - one of threee types: ‘simple’, ‘static_offsets’, ‘linear_offsets’

flextomo.projector.FISTA(projections, volume, geometry, iterations, lmbda=0)[source]

FISTA reconstruction. Right now there is no TV minimization substep here!

flextomo.projector.PWLS(projections, volume, geometry, iterations)[source]

Simple implementation of the Penalized Weighted Least Squeares. Gives better results when photon starvation and metal artifacts are present in small parts of the volume. Needs more memory than SIRT!

flextomo.projector.SIRT(projections, volume, geometry, iterations)[source]

Simultaneous Iterative Reconstruction Technique.

flextomo.projector.backproject(projections, volume, geometry, filtered=False, sign=1)[source]

Backproject using standard ASTRA functionality. If data array is memmap, backprojection is done using 10+ subsets to save RAM.

Args:

projections : input numpy.array (dtype = float32) with the following dimensions: [vrt, rot, hrz] volume : output numpy.array (dtype = float32) with the following dimensions: [vrt, mag, hrz] geometry : geometry description. See flexData.geometry filtered : use Feldkamp (True) or unfiltered (False) backprojection sign : either +1 or -1 (add or subtract from volume)

flextomo.projector.em_update(projections, volume, geometry)[source]

A single Expecrtation Maximization step. Supports blocking and subsets.

flextomo.projector.fista_update(projections, vol, vol_old, vol_t, vol_tv, t, geometry, lmbda=0)[source]

A single FISTA step. Supports blocking and subsets.

flextomo.projector.forwardproject(projections, volume, geometry, sign=1)[source]

Forwardproject using standard ASTRA functionality. If projections array is numpy.memmap, projection is done in blocks to save RAM.

Args:

projections : output numpy.array (dtype = float32) with the following dimensions: [vrt, rot, hrz] volume : input numpy.array (dtype = float32) with the following dimensions: [vrt, mag, hrz] geometry : geometry description - one of threee types: ‘simple’, ‘static_offsets’, ‘linear_offsets’ sign : either +1 or -1 (add or subtract the data)

flextomo.projector.init_volume(projections)[source]

Initialize a standard-size volume array.

flextomo.projector.l1_update(vol_tv, vol_t, vol, L, lamb)[source]

Calculate image with lower TV. Stores the results in vol. It uses residual vol_tv from the last time it was called.

flextomo.projector.l2_update(projections, volume, geometry)[source]

A single L2-norm minimization update. Supports subsets.

flextomo.projector.pwls_update(projections, volume, geometry)[source]

A single L2-norm update that applies weights based on Poisson statistics to both residual and volume update. Uses more memory than the standard l2_update.

class flextomo.projector.settings[source]

Bases: object

Settings container used by projectors and reconstruction algorithms. Attributes:

progress_bar : show a progress bar preview : show previews update_residual : update the cost function

subsets : Number of projection subsets sorting : Sorting of projections: ‘sequential’ or ‘equidistant’

poisson : Weight pixels according to a Poisson statistics (only backprojection) student : Use Students-T norm for regularization pixel_mask : (scalar or 3d array) Mask applied to projections. If 3d, any dimension can be 0 voxel_mask : (scalar or 3d array) Mask applied to volume during forward projection. If 3d, any dimension can be 0 fourier_filter : (scalar or 2d array) Fourier filter applied to every projection (CTF) bounds : Lower and upper bounds for the reconstruction values

bounds = None
fourier_filter = None
pixel_mask = None
poisson = False
preview = False
progress_bar = True
sorting = 'sequential'
student = False
subsets = 1
update_residual = False
voxel_mask = None

flextomo.phantom

Created on Fri Nov 2017

@author: kostenko

Genereation of CT phantoms from geometrical primitives. Reads geometry data to compute dimensions correctly.

flextomo.phantom.abstract_nudes(shape, geometry, complexity=10)[source]

Creates works of abstract art.

flextomo.phantom.checkers(shape, geometry, frequency, offset=[0.0, 0.0, 0.0])[source]

Make a 3D checkers board.

flextomo.phantom.cuboid(shape, geometry, a, b, c, offset=[0.0, 0.0, 0.0])[source]

Make a cuboid. Dimensions are in units (geometry.parameters[‘unit’])

flextomo.phantom.cylinder(shape, geometry, r, h, offset=[0.0, 0.0, 0.0])[source]

Make a cylinder with a specified radius and height.

flextomo.phantom.random_spheroids(shape, geometry, number=3, overlap='xor', rotation=True)[source]

Make a bunch of spheroids…

flextomo.phantom.sphere(shape, geometry, r, offset=[0.0, 0.0, 0.0])[source]

Make sphere. Radius is in units (geometry.parameters[‘unit’])

flextomo.phantom.spheroid(shape, geometry, r1, r2, r3, offset=[0.0, 0.0, 0.0])[source]

Make a spheroid.

flextomo.model

@author: kostenko

This module can be used to simulate spectral effects and resolution/photon-count effects. NIST data is used (embedded in xraylib module) to simulate x-ray spectra of compounds

flextomo.model.apply_noise(image, mode='poisson', parameter=1)[source]

Add noise to the data.

Args:

image (numpy.array): image to apply noise to mode (str): poisson or normal parameter (float): norm factor for poisson or a standard deviation

flextomo.model.bremsstrahlung(energy, energy_max)[source]

Simple bremstrahlung model (Kramer formula). Emax

flextomo.model.compton(energy, compound)[source]

Compton scaterring crossection for a given compound in cm2g. Energy is given in KeV

flextomo.model.ctf(shape, mode='gaussian', parameter=(1, 1))[source]

Get a CTF (fft2(PSF)) of one of the following types: gaussian, dual_ctf, fresnel, TIE

Args:

shape (list): shape of a projection image mode (str): ‘gaussian’ (blurr), ‘dual_ctf’, fresnel, TIE (phase contrast) parameter (list / float): PSF/CTF parameters.

For gaussian: [detector_pixel, sigma] For dual_ctf/tie: [detector_pixel, energy, src2obj, det2obj, alpha] For fresnel: [detector_pixel, energy, src2obj, det2obj]

flextomo.model.effective_spectrum(energy=None, kv=90, filtr={'density': 8, 'material': 'Cu', 'thickness': 0.1}, detector={'density': 5, 'material': 'Si', 'thickness': 1})[source]

Generate an effective specturm of a CT scanner.

flextomo.model.find_nist_name(compound_name)[source]

Get physical properties of one of the compounds registered in nist database

flextomo.model.forward_spectral(vol, proj, geometry, materials, energy, spectrum, n_phot=100000000.0)[source]

Simulate spectral data using labeled volume.

flextomo.model.gaussian_spectrum(energy, energy_mean, energy_sigma)[source]

Generates gaussian-like spectrum with given mean and STD.

flextomo.model.linear_attenuation(energy, compound, rho)[source]

Total X-ray absorption for a given compound in 1/mm. Energy is given in KeV

flextomo.model.mass_attenuation(energy, compound)[source]

Total X-ray absorption for a given compound in cm2g. Energy is given in KeV

flextomo.model.material_refraction(energy, compound, rho)[source]

Calculate complex refrative index of the material taking into account it’s density.

Args:

compound (str): compound chemical formula rho (float): density in g / cm3 energy (numpy.array): energy in KeV

Returns:

float: refraction index in [1/mm]

flextomo.model.nist_names()[source]

Get a list of registered compound names understood by nist

flextomo.model.parse_compound(compund)[source]

Parse chemical formula

flextomo.model.photoelectric(energy, compound)[source]

Photoelectric effect for a given compound in cm2g. Energy is given in KeV

flextomo.model.rayleigh(energy, compound)[source]

Compton scaterring crossection for a given compound in cm2g. Energy is given in KeV

flextomo.model.scintillator_efficiency(energy, compound='BaFBr', rho=5, thickness=1)[source]

Generate QDE of a detector (scintillator). Units: KeV, g/cm3, mm.

flextomo.model.spectralize(proj, kv=90, n_phot=100000000.0, specimen={'density': 2.7, 'material': 'Al'}, filtr={'density': 8, 'material': 'Cu', 'thickness': 0.1}, detector={'density': 5, 'material': 'Si', 'thickness': 1})[source]

Simulate spectral data.

flextomo.model.total_transmission(energy, compound, rho, thickness)[source]

Compute fraction of x-rays transmitted through the filter. Units: KeV, g/cm3, mm.

Module contents

Backend

The backend of the projector module (and by extension all of flexTOMO and flexCALC) is provided by the GPU-accelerated ASTRA Toolbox. It is encapsulated in four functions: flextomo.projector.forwardproject(), flextomo.projector.backproject(), flexdata.geometry.astra_volume_geom(), and flexdata.geometry.astra_projection_geom().