corrct.testing

Provide utility functions for testing.

Created on Thu Jun 4 12:28:21 2020

@author: Nicola VIGANÒ, Computational Imaging group, CWI, The Netherlands, and ESRF - The European Synchrotron, Grenoble, France

Module Contents

Functions

roundup_to_pow2

Round first argument to the power of 2 indicated by second argument.

download_phantom

Download the phantom generation module from Nicolas Barbey’s repository on github.

create_phantom_nuclei3d

Create a 3D phantom of cell nuclei.

phantom_assign_concentration

Build an XRF phantom.

phantom_assign_concentration_multi

Build an XRF phantom.

add_noise

Add noise to an image (sinogram).

create_sino

Compute the sinogram from a given phantom.

create_sino_transmission

Compute the sinogram from a given phantom.

compute_error_power

Compute the expected volume signal power, and computed volume error power.

Data

NDArrayFloat

API

corrct.testing.NDArrayFloat

None

corrct.testing.roundup_to_pow2(x: Union[int, float, corrct.testing.NDArrayFloat], p: int, dtype: numpy.typing.DTypeLike = int) Union[int, float, corrct.testing.NDArrayFloat][source]

Round first argument to the power of 2 indicated by second argument.

Parameters

x : int | float | NDArrayFloat Number to round up. p : int Power of 2. dtype : DTypeLike, optional data type of the output. The default is int.

Returns

int | float | NDArrayFloat Rounding up of input.

corrct.testing.download_phantom()[source]

Download the phantom generation module from Nicolas Barbey’s repository on github.

corrct.testing.create_phantom_nuclei3d(FoV_size: Union[int, None] = 100, dtype: numpy.typing.DTypeLike = np.float32) tuple[corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat][source]

Create a 3D phantom of cell nuclei.

Parameters

FoV_size : int | None Size of the field-of-view in pixels, per edge, by default None dtype : DTypeLike, optional The dtype of the produced data, by default np.float32

Returns

tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat] The nuclei 3D phantom, the background, and the pixel sizes along each axis

corrct.testing.phantom_assign_concentration(ph_or: corrct.testing.NDArrayFloat, element: str = 'Ca', em_line: str = 'KA', in_energy_keV: float = 20.0, voxel_size_um: float = 0.5) tuple[corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat][source]

Build an XRF phantom.

The created phantom has been used in:

  • N. Viganò and V. A. Solé, “Physically corrected forward operators for induced emission tomography: a simulation study,” Meas. Sci. Technol., no. Advanced X-Ray Tomography, pp. 1–26, Nov. 2017.

Parameters

ph_or : NDArrayFloat The phases phantom map. element : str, optional Element symbol. The default is “Ca”. em_line : str, optional Emission line. The default is “KA” (corresponding to K-alpha). in_energy_keV : float, optional Incoming beam energy in keV. The default is 20.0.

Returns

vol_fluo_yield : NDArrayFloat Voxel-wise fluorescence yields. vol_att_in : NDArrayFloat Voxel-wise attenuation at the incoming beam energy. vol_att_out : NDArrayFloat Voxel-wise attenuation at the emitted energy.

corrct.testing.phantom_assign_concentration_multi(ph_or: corrct.testing.NDArrayFloat, elements: collections.abc.Sequence[str] = ('Ca', 'Fe'), em_lines: Union[str, collections.abc.Sequence[str]] = 'KA', in_energy_keV: float = 20.0, detectors_pos_rad: Optional[float] = None) tuple[list[corrct.testing.NDArrayFloat], corrct.testing.NDArrayFloat, list[corrct.testing.NDArrayFloat]][source]

Build an XRF phantom.

The created phantom has been used in:

  • N. Viganò and V. A. Solé, “Physically corrected forward operators for induced emission tomography: a simulation study,” Meas. Sci. Technol., no. Advanced X-Ray Tomography, pp. 1–26, Nov. 2017.

Parameters

ph_or : NDArrayFloat The phases phantom map. elements : Sequence[str], optional Element symbols. The default is [“Ca”, “Fe”]. em_lines : str | Sequence[str], optional Emission lines. The default is “KA” (corresponding to K-alpha). in_energy_keV : float, optional Incoming beam energy in keV. The default is 20.0. detectors_pos_rad : float | tuple | list | NDArrayFloat, optional Detector(s) positions in radians, with respect to incoming beam. If None, Compton is not produced. The default is None.

Returns

vol_yield : List[NDArrayFloat] Voxel-wise fluorescence and Compton yields. vol_att_in : NDArrayFloat Voxel-wise attenuation at the incoming beam energy. vol_att_out : List[NDArrayFloat] Voxel-wise attenuation at the emitted energy.

corrct.testing.add_noise(img_clean: numpy.typing.NDArray, num_photons: Union[int, float], add_poisson: bool = False, readout_noise_std: Optional[float] = None, background_avg: Optional[float] = None, background_std: Optional[float] = None, detection_efficiency: float = 1.0, dtype: numpy.typing.DTypeLike = np.float32) tuple[numpy.typing.NDArray, numpy.typing.NDArray, float][source]

Add noise to an image (sinogram).

Parameters

img_clean : NDArray The clean input image. num_photons : Union[int, float] Number of photons corresponding to the value 1.0 in the image. add_poisson : bool, optional Whether to add Poisson noise, by default False. readout_noise_std : Optional[float], optional Standard deviation of the readout noise, by default None. background_avg : Optional[float], optional Average value of the background, by default None. background_std : Optional[float], optional Standard deviation of the background, by default None. detection_efficiency : float, optional Efficiency of the detection (e.g. detector solid angle, inclination, etc), by default 1.0. dtype : DTypeLike, optional Data type of the volumes, by default np.float32.

Returns

Tuple[NDArray, NDArray, float] The noised and clean images (scaled by the photons and efficiency), and the background.

corrct.testing.create_sino(ph: corrct.testing.NDArrayFloat, num_angles: int, start_angle_deg: float = 0.0, end_angle_deg: float = 180.0, dwell_time_s: float = 1.0, photon_flux: float = 1000000000.0, detectors_pos_rad: Union[float, collections.abc.Sequence[float], corrct.testing.NDArrayFloat] = np.pi / 2, vol_att_in: Optional[corrct.testing.NDArrayFloat] = None, vol_att_out: Optional[corrct.testing.NDArrayFloat] = None, psf: Optional[corrct.testing.NDArrayFloat] = None, background_avg: Optional[float] = None, background_std: Optional[float] = None, add_poisson: bool = False, readout_noise_std: Optional[float] = None, dtype: numpy.typing.DTypeLike = np.float32) tuple[corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, float][source]

Compute the sinogram from a given phantom.

Parameters

ph : NDArrayFloat The phantom volume, with the expected average photon production per voxel per impinging photon. num_angles : int The number of angles. start_angle_deg : float, optional Initial scan angle in degrees. The default is 0. end_angle_deg : float, optional Final scan angle in degrees. The default is 180. dwell_time_s : float, optional The acquisition time per sinogram point. The default is 1. photon_flux : float, optional The impinging photon flux per unit time (second). The default is 1e9. detectors_pos_rad : float | Sequence[float] | NDArrayFloat, optional Detector(s) positions in radians, with respect to incoming beam. The default is (np.pi / 2). vol_att_in : NDArrayFloat, optional Attenuation volume for the incoming beam. The default is None. vol_att_out : NDArrayFloat, optional Attenuation volume for the outgoing beam. The default is None. psf : NDArrayFloat, optional Point spread function or probing beam profile. The default is None. background_avg : float, optional Background average value. The default is None. background_std : float, optional Background standard deviation. The default is None. add_poisson : bool, optional Switch to turn on Poisson noise. The default is False. readout_noise_std : float, optional Read-out noise standard deviation. The default is None. dtype : numpy.dtype, optional Output datatype. The default is np.float32.

Returns

Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat, float] The sinogram (detector readings), the angular positions, and the expected average phton production per voxel.

corrct.testing.create_sino_transmission(ph: corrct.testing.NDArrayFloat, num_angles: int, start_angle_deg: float = 0, end_angle_deg: float = 180, dwell_time_s: float = 1, photon_flux: float = 1000000000.0, psf: Optional[corrct.testing.NDArrayFloat] = None, add_poisson: bool = False, readout_noise_std: Optional[float] = None, dtype: numpy.typing.DTypeLike = np.float32) tuple[corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat, corrct.testing.NDArrayFloat][source]

Compute the sinogram from a given phantom.

Parameters

ph : NDArrayFloat The phantom volume, with the expected average photon production per voxel per impinging photon. num_angles : int The number of angles. start_angle_deg : float, optional Initial scan angle in degrees. The default is 0. end_angle_deg : float, optional Final scan angle in degrees. The default is 180. dwell_time_s : float, optional The acquisition time per sinogram point. The default is 1. photon_flux : float, optional The impinging photon flux per unit time (second). The default is 1e9. psf : NDArrayFloat, optional Point spread function or probing beam profile. The default is None. add_poisson : bool, optional Switch to turn on Poisson noise. The default is False. readout_noise_std : float, optional Read-out noise standard deviation. The default is None. dtype : numpy.dtype, optional Output datatype. The default is np.float32.

Returns

Tuple[NDArrayFloat, NDArrayFloat, NDArrayFloat, NDArrayFloat, float] The sinogram (detector readings), the flat-field, and the angular positions.

corrct.testing.compute_error_power(expected_vol: corrct.testing.NDArrayFloat, computed_vol: corrct.testing.NDArrayFloat) tuple[float, float][source]

Compute the expected volume signal power, and computed volume error power.

Parameters

expected_vol : NDArrayFloat The expected volume. computed_vol : NDArrayFloat The computed volume.

Returns

Tuple[float, float] The expected volume signal power, and the computed volume.