7.4.1. algotom.post.postprocessing

Module of methods in the postprocessing stage:

  • Get statistical information of reconstructed images or a dataset.

  • Downsample 2D, 3D array, or a dataset.

  • Rescale 2D, 3D array or a dataset to 8-bit or 16-bit data-type.

  • Reslice 3D array or a dataset (hdf/nxs file or tif images).

  • Removing ring artifacts in a reconstructed image by transform back and forth between the polar coordinates and the Cartesian coordinates.

Functions:

get_statistical_information(mat[, ...])

Get statistical information of an image.

get_statistical_information_dataset(input_)

Get statical information of a dataset.

downsample(mat, cell_size[, method])

Downsample an image.

downsample_dataset(input_, output, cell_size)

Downsample a dataset.

rescale(mat[, nbit, minmax])

Rescale a 32-bit array to 16-bit/8-bit data.

rescale_dataset(input_, output[, nbit, ...])

Rescale a dataset to 8-bit or 16-bit data-type.

reslice_dataset(input_, output[, axis, ...])

Reslice a 3d dataset.

remove_ring_based_fft(mat[, u, n, v, sort])

Remove ring artifacts in the reconstructed image by combining the polar transform and the fft-based method.

remove_ring_based_wavelet_fft(mat[, level, ...])

Remove ring artifacts in a reconstructed image by combining the polar transform and the wavelet-fft-based method (Ref.

algotom.post.postprocessing.get_statistical_information(mat, percentile=(0, 100), denoise=False)[source]

Get statistical information of an image.

Parameters
  • mat (array_like) – 2D array. Projection image, sinogram image, or reconstructed image.

  • percentile (tuple of floats) – Tuple of (min_percentile, max_percentile) to compute. Must be between 0 and 100 inclusive.

  • denoise (bool, optional) – Enable/disable denoising before extracting statistical information.

Returns

  • gmin (float) – The minimum value of the data array.

  • gmax (float) – The maximum value of the data array.

  • min_percent (float) – The first computed percentile of the data array.

  • max_percent (tuple of floats) – The last computed percentile of the data array.

  • mean (float) – The mean of the data array.

  • median (float) – The median of the data array.

  • variance (float) – The variance of the data array.

algotom.post.postprocessing.get_statistical_information_dataset(input_, percentile=(0, 100), skip=5, denoise=False, key_path=None, crop=(0, 0, 0, 0, 0, 0))[source]

Get statical information of a dataset. This can be a folder of tif files, a hdf file, or a 3D array.

Parameters
  • input_ (str, hdf file, or array_like) – It can be a folder path to tif files, a hdf file, or a 3D array.

  • percentile (tuple of floats) – Tuple of (min_percentile, max_percentile) to compute. Must be between 0 and 100 inclusive.

  • skip (int) – Skipping step of reading input.

  • denoise (bool, optional) – Enable/disable denoising before extracting statistical information.

  • key_path (str, optional) – Key path to the dataset if input is a hdf file.

  • crop (tuple of int, optional) – Crop 3D data from the edges, i.e. crop = (crop_depth1, crop_depth2, crop_height1, crop_height2, crop_width1, crop_width2).

Returns

  • gmin (float) – The global minimum value of the data array.

  • gmax (float) – The global maximum value of the data array.

  • min_percent (float) – The global min of the first computed percentile of the data array.

  • max_percent (tuple of floats) – The global min of the last computed percentile of the data array.

  • mean (float) – The mean of the data array.

  • median (float) – The median of the data array.

  • variance (float) – The mean of the variance of the data array.

algotom.post.postprocessing.downsample(mat, cell_size, method='mean')[source]

Downsample an image.

Parameters
  • mat (array_like) – 2D array.

  • cell_size (int or tuple of int) – Window size along axes used for grouping pixels.

  • method ({“mean”, “median”, “max”, “min”}) – Downsampling method.

Returns

array_like – Downsampled image.

algotom.post.postprocessing.rescale(mat, nbit=16, minmax=None)[source]

Rescale a 32-bit array to 16-bit/8-bit data.

Parameters
  • mat (array_like)

  • nbit ({8,16}) – Rescaled data-type: 8-bit or 16-bit.

  • minmax (tuple of float, or None) – Minimum and maximum values used for rescaling.

Returns

array_like – Rescaled array.

algotom.post.postprocessing.downsample_dataset(input_, output, cell_size, method='mean', key_path=None, rescaling=False, nbit=16, minmax=None, skip=None, crop=(0, 0, 0, 0, 0, 0))[source]

Downsample a dataset. Input can be a folder of tif files, a hdf file, or a 3D array.

Parameters
  • input_ (str, array_like) – It can be a folder path to tif files, a hdf file, or a 3D array.

  • output (str, None) – It can be a folder path, a hdf file path, or None (memory consuming).

  • cell_size (int or tuple of int) – Window size along axes used for grouping pixels.

  • method ({“mean”, “median”, “max”, “min”}) – Downsampling method.

  • key_path (str, optional) – Key path to the dataset if the input is a hdf file.

  • rescaling (bool) – Rescale dataset if True.

  • nbit ({8,16}) – If rescaling is True, select data-type: 8-bit or 16-bit.

  • minmax (tuple of float, or None) – Minimum and maximum values used for rescaling if True.

  • skip (int or None) – Skipping step of images used for getting statistical information if rescaling is True and input is 32-bit data.

  • crop (tuple of int, optional) – Crop 3D data from the edges, i.e. crop = (crop_depth1, crop_depth2, crop_height1, crop_height2, crop_width1, crop_width2).

Returns

array_like or None – If output is None, returning a 3D array.

algotom.post.postprocessing.rescale_dataset(input_, output, nbit=16, minmax=None, skip=None, key_path=None, crop=(0, 0, 0, 0, 0, 0))[source]

Rescale a dataset to 8-bit or 16-bit data-type. The dataset can be a folder of tif files, a hdf file, or a 3D array.

Parameters
  • input_ (str, array_like) – It can be a folder path to tif files, a hdf file, or 3D array.

  • output (str, None) – It can be a folder path, a hdf file path, or None (memory consuming).

  • nbit ({8,16,32}) – Select rescaled data-type: 8-bit/16-bit. 32 is for cropping data only.

  • minmax (tuple of float, or None) – Minimum and maximum values used for rescaling. They are calculated if None is given.

  • skip (int or None) – Skipping step of images used for getting statistical information.

  • key_path (str, optional) – Key path to the dataset if the input is a hdf file.

  • crop (tuple of int, optional) – Crop 3D data from the edges, i.e. crop = (crop_depth1, crop_depth2, crop_height1, crop_height2, crop_width1, crop_width2).

Returns

array_like or None – If output is None, returning an 3D array.

algotom.post.postprocessing.reslice_dataset(input_, output, axis=1, key_path=None, rescaling=False, nbit=16, minmax=None, skip=None, rotate=0.0, chunk=16, mode='constant', crop=(0, 0, 0, 0, 0, 0), ncore=None, show_progress=True)[source]

Reslice a 3d dataset. Input can be a folder of tif files or a hdf file.

Parameters
  • input_ (str, array_like) – It can be a folder path to tif files or a hdf file.

  • output (str) – It can be a folder path (for generated tif-files) or a hdf file-path.

  • axis ({1,2}) – Slicing axis. This axis becomes the 0-axis of the output.

  • key_path (str, optional) – Key path to the dataset if the input is a hdf file.

  • rescaling (bool) – Rescale dataset if True.

  • nbit ({8,16}) – If rescaling is True, select data-type: 8-bit or 16-bit.

  • minmax (tuple of float, or None) – Minimum and maximum values used for rescaling if True.

  • skip (int or None) – Skipping step of images used for getting statistical information if rescaling is True and input is 32-bit data.

  • rotate (float) – Rotate image (degree). Positive direction is counterclockwise.

  • chunk (int) – Number of images to be loaded/saved in one go to reduce IO overhead.

  • mode ({‘reflect’, ‘grid-mirror’, ‘constant’, ‘grid-constant’, ‘nearest’, ‘mirror’, ‘grid-wrap’, ‘wrap’}) – Select how the input array is extended beyond its boundaries.

  • crop (tuple of int, optional) – Crop 3D data from the edges, i.e. crop = (crop_depth1, crop_depth2, crop_height1, crop_height2, crop_width1, crop_width2). Cropping is done before reslicing.

  • ncore (int or None) – Number of cpu-cores. Automatically selected if None.

  • show_progress (bool) – Show the progress of reslicing data if True.

Returns

array_like or None – If output is None, returning a 3D array.

algotom.post.postprocessing.remove_ring_based_fft(mat, u=20, n=8, v=1, sort=False)[source]

Remove ring artifacts in the reconstructed image by combining the polar transform and the fft-based method.

Parameters
  • mat (array_like) – Square array. Reconstructed image

  • u (int) – Cutoff frequency.

  • n (int) – Filter order.

  • v (int) – Number of rows (* 2) to be applied the filter.

  • sort (bool, optional) – Apply sorting (Ref. [2]) if True.

Returns

array_like – Ring-removed image.

References

[1] : https://doi.org/10.1063/1.1149043

[2] : https://doi.org/10.1364/OE.26.028396

algotom.post.postprocessing.remove_ring_based_wavelet_fft(mat, level=5, size=1, wavelet_name='db9', sort=False)[source]

Remove ring artifacts in a reconstructed image by combining the polar transform and the wavelet-fft-based method (Ref. [1]).

Parameters
  • mat (array_like) – Square array. Reconstructed image

  • level (int) – Wavelet decomposition level.

  • size (int) – Damping parameter. Larger is stronger.

  • wavelet_name (str) – Name of a wavelet. Search pywavelets API for a full list.

  • sort (bool, optional) – Apply sorting (Ref. [2]) if True.

Returns

array_like – Ring-removed image.

References

[1] : https://doi.org/10.1364/OE.17.008567

[2] : https://doi.org/10.1364/OE.26.028396