# 7.5.1. `algotom.util.calibration`

Module of calibration methods:

• Correcting the non-uniform background of an image.

• Binarizing an image.

• Calculating the distance between two point-like objects segmented from two images. Useful for determining pixel-size in helical scans.

Functions:

 `normalize_background`(mat[, size]) Correct a non-uniform background of an image using the median filter. `normalize_background_based_fft`(mat[, sigma, ...]) Correct a non-uniform background of an image using a Fourier Gaussian filter. Invert the contrast of a 2D binary array to make sure that a dot is white. `calculate_threshold`(mat[, bgr]) Calculate threshold value based on Algorithm 4 in Ref. `binarize_image`(mat[, threshold, bgr, norm, ...]) Binarize an image. `get_dot_size`(mat[, size_opt]) Get size of binary dots given the option. `check_dot_size`(mat, min_size, max_size) Check if the size of a dot is in a range. `select_dot_based_size`(mat, dot_size[, ratio]) Select dots having a certain size. `calculate_distance`(mat1, mat2[, size_opt, ...]) Calculate the distance between two point-like objects segmented from two images.
algotom.util.calibration.normalize_background(mat, size=51)[source]

Correct a non-uniform background of an image using the median filter.

Parameters
• mat (array_like) – 2D array.

• size (int) – Size of the median filter.

Returns

array_like – 2D array. Corrected image.

Correct a non-uniform background of an image using a Fourier Gaussian filter.

Parameters
• mat (array_like) – 2D array.

• sigma (int) – Sigma of the Gaussian.

• mode (str, list of str, or tuple of str) – Padding method. One of options : ‘reflect’, ‘edge’, ‘constant’. Full list is at: https://numpy.org/doc/stable/reference/generated/numpy.pad.html

Returns

array_like – 2D array. Corrected image.

algotom.util.calibration.invert_dot_contrast(mat)[source]

Invert the contrast of a 2D binary array to make sure that a dot is white.

Parameters

mat (array_like) – 2D binary array.

Returns

array_like – 2D array.

algotom.util.calibration.calculate_threshold(mat, bgr='bright')[source]

Calculate threshold value based on Algorithm 4 in Ref. .

Parameters
• mat (array_like) – 2D array.

• bgr ({“bright”, “dark”}) – To indicate the brightness of the background against image features.

Returns

float – Threshold value.

References

algotom.util.calibration.binarize_image(mat, threshold=None, bgr='bright', norm=False, denoise=True, invert=True)[source]

Binarize an image.

Parameters
• mat (array_like) – 2D array.

• threshold (float, optional) – Threshold value for binarization. Automatically calculated using Algorithm 4 in Ref.  if None.

• bgr ({“bright”, “dark”}) – To indicate the brightness of the background against image features.

• norm (bool, optional) – Apply normalization if True.

• denoise (bool, optional) – Apply denoising if True.

• invert (bool, optional) – Invert the contrast if needed.

Returns

array_like – 2D binary array.

References

algotom.util.calibration.get_dot_size(mat, size_opt='max')[source]

Get size of binary dots given the option.

Parameters
• mat (array_like) – 2D binary array.

• size_opt ({“max”, “min”, “median”, “mean”}) – Select options.

Returns

dot_size (float) – Size of the dot.

algotom.util.calibration.check_dot_size(mat, min_size, max_size)[source]

Check if the size of a dot is in a range.

Parameters
• mat (array_like) – 2D array.

• min_size (float) – Minimum size.

• max_size (float) – Maximum size.

Returns

bool

algotom.util.calibration.select_dot_based_size(mat, dot_size, ratio=0.01)[source]

Select dots having a certain size.

Parameters
• mat (array_like) – 2D array.

• dot_size (float) – Size of the standard dot.

• ratio (float) – Used to calculate the acceptable range. [dot_size - ratio*dot_size; dot_size + ratio*dot_size]

Returns

array_like – 2D array. Selected dots.

algotom.util.calibration.calculate_distance(mat1, mat2, size_opt='max', threshold=None, bgr='bright', norm=False, denoise=True, invert=True)[source]

Calculate the distance between two point-like objects segmented from two images. Useful for measuring pixel-size in helical scans (Ref. ).

Parameters
• mat1 (array_like) – 2D array.

• mat2 (array_like) – 2D array.

• size_opt ({“max”, “min”, “median”, “mean”}) – Options to select binary objects based on their size.

• threshold (float, optional) – Threshold value for binarization. Automatically calculated using Algorithm 4 in Ref.  if None.

• bgr ({“bright”, “dark”}) – To indicate the brightness of the background against image features.

• norm (bool, optional) – Apply normalization if True.

• denoise (bool, optional) – Apply denoising if True.

• invert (bool, optional) – Invert the contrast if needed.

References