tomophantom.artefacts#

Copyright 2023 The University of Manchester & Diamond Light Source Licensed under the Apache License, Version 2.0.

tomophantom.artefacts.artefacts_mix(data: numpy.ndarray, **artefacts_dict: Any) Union[numpy.ndarray, list][source]#
A module to generate and apply a mix of various typical imaging artefacts to add to the simulated data.

One can build various dictionaries with keywords arguments specified bellow and pass it to the function as: artefacts_mix(data, **noise_dict, **zingers, **etc).

DISCLAIMER: Note that most of the features are experimental and do not always reflect the accurate modelling of the inaccuracies.

Parameters
  • data (3D projection) – 2D or 3D numpy array (sinogram or 3D projection data).

  • shape (The input data must be of the following) – 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • **artefacts_dict (dict) – A dictionary with keyword arguments related to different artefact type.

Keyword Arguments
  • noise_type (str) – Define noise type as ‘Poisson’ or ‘Gaussian’.

  • noise_amplitude (int, float) – Photon flux for Poisson or variance for Gaussian noise.

  • noise_seed (int) – Seeds for noise generator. ‘None’ defines random generation.

  • noise_prelog (bool) – Set to True if prelog (raw) data required.

  • zingers_percentage (float) – The amount of zingers (dead pixels, outliers) to be added to the data.

  • zingers_modulus (int) – Modulus to control the amount of 4/6 pixel clusters to be added.

  • stripes_percentage (float) – The amount of stripes in the data (rings in reconstruction).

  • stripes_maxthickness (int) – Maxthickness defines the maximal thickness of a stripe.

  • stripes_intensity (float) – Controls the intensity levels of stripes.

  • stripe_type (str) – Stripe types can be ‘partial’ or ‘full’.

  • stripes_variability (float) – Variability multiplier to incorporate the change of intensity in stripe.

  • datashifts_maxamplitude_pixel (int) – Controls pixel-wise (integer) misalignment in data.

  • datashifts_maxamplitude_subpixel (float) – Controls subpixel misalignment in data.

  • pve_strength (int) – The strength of partial volume effect, responsible for the limited resolution of a scanner.

  • fresnel_dist_observation (int) – The distance for obervation for fresnel propagator.

  • fresnel_scale_factor (float) – Fresnel propagator sacaling.

  • fresnel_wavelenght (float) – Fresnel propagator wavelength.

  • verbose (bool) – Make the output of modules verbose.

Returns

2D/3D numpy array with artefacts applied to input data. [np.ndarray, shifts]: a list of 2D/3D numpy array and simulated shifts.

Return type

np.ndarray

tomophantom.artefacts.datashifts(data: numpy.ndarray, maxamplitude: int) list[source]#

Function to add random pixel shifts to 3D or 3D data as an offset for each angular position.

Parameters
  • data (3D projection) – 2D sinogram or 3D projection data. The input data must be of the following shape: 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • maxamplitude (int) – The misilighnment ammplitude. Defines the maximal amplitude of each shift in pixels.

Returns

2D or 3d data with misalignment and shifts vectors [data, shifts].

Return type

list

tomophantom.artefacts.datashifts_subpixel(data: numpy.ndarray, maxamplitude: float) list[source]#

Function to add random sub-pixel shifts to 3D or 3D data as an offset for each angular position.

Parameters
  • data (3D projection) – 2D sinogram or 3D projection data. The input data must be of the following shape: 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • maxamplitude (float) – The misilighnment ammplitude. Defines the maximal amplitude of each shift.

Returns

2D or 3d data with misalignment and shifts vectors [data, shifts].

Return type

list

tomophantom.artefacts.fresnel_propagator(data: numpy.ndarray, dist_observation: int, scale_factor: float, wavelenght: float) numpy.ndarray[source]#
Fresnel propagator applied to data.

Adapted from the script by Adrián Carbajal-Domínguez, adrian.carbajal@ujat.mx

Parameters
  • data (3D projection) – 2D sinogram or 3D projection data. The input data must be of the following shape: 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • dist_observation (int) – The distance for obervation for fresnel propagator.

  • scale_factor (float) – Scaling.

  • wavelenght (float) – Wavelength.

Returns

2D or 3D data with propagation.

Return type

np.ndarray

tomophantom.artefacts.noise(data: numpy.ndarray, sigma: Union[int, float], noisetype: str, seed: bool = True, prelog: bool = False) Union[list, numpy.ndarray][source]#

Adding random noise to data (adapted from LD-CT simulator)

Parameters
  • data (np.ndarray) – N-d array

  • sigma (Union[int, float]) – int for Poisson or float for Gaussian

  • noisetype (str) – ‘Gaussian’ or ‘Poisson’

  • seed (bool, optional) – Initiate random seed with True. Defaults to True.

  • prelog (bool, optional) – get raw data if true, returns a list [noisy, raw]!. Defaults to False.

Returns

N-d array

Return type

np.ndarray

tomophantom.artefacts.pve(data: numpy.ndarray, pve_strength: int) numpy.ndarray[source]#

Applying Partial Volume effect (smoothing) to data.

Parameters
  • data (3D projection) – 2D sinogram or 3D projection data. The input data must be of the following shape: 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • pve_strength (int) – The level of smoothing, defined by kernel size.

Raises

ValueError – Smoothing kernel must be positive

Returns

Smoothed 2D or 3D data.

Return type

np.ndarray

tomophantom.artefacts.stripes(data: numpy.ndarray, percentage: float, maxthickness: int, intensity_thresh: float, stripe_type: str, variability: float) numpy.ndarray[source]#

Function to add stripes (constant offsets) to sinograms or 3D projection data which results in rings in the reconstructed image.

Parameters
  • data (np.ndarray) – 2D sinogram (anglesDim, DetectorsHoriz) or 3D projection data (DetectorsVert, anglesDim, DetectorsHoriz).

  • percentage (float) – Percentage defines the amount of stripes in the data.

  • maxthickness (int) – Defines the maximal thickness of a stripe.

  • intensity_thresh (float) – Controls the intensity levels of stripes.

  • stripe_type (str) – Choose between ‘partial’ or ‘full’.

  • variability (float) – Variability multiplier to incorporate change of intensity in the stripe.

Raises
  • ValueError – Percentage is out of range.

  • ValueError – Thickness is out of range.

Returns

2D sinogram or 3D projection data with stripes

Return type

np.ndarray

tomophantom.artefacts.zingers(data: numpy.ndarray, percentage: float, modulus: int) numpy.ndarray[source]#
Adding zingers (zero single pixels or small 4 pixels clusters)

to sinograms or 6 voxels to 3D projection data.

Parameters
  • data (3D projection) – 2D sinogram or 3D projection data. The input data must be of the following shape: 2D sinogram (anglesDim, DetectorsHoriz),

  • data

  • percentage (float) – The amount of zingers to be added to the data.

  • modulus (int) – Modulus to control the amount of 4/6 pixel clusters to be added.

Raises
  • ValueError – Percentage is out of range.

  • ValueError – Modulus must be positive.

Returns

2D or 3D array with zingers.

Return type

np.ndarray