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:
|
Correct a non-uniform background of an image using the median filter. |
|
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 value based on Algorithm 4 in Ref. |
|
Binarize an image. |
|
Get size of binary dots given the option. |
|
Check if the size of a dot is in a range. |
|
Select dots having a certain size. |
|
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.
- algotom.util.calibration.normalize_background_based_fft(mat, sigma=5, pad=None, mode='reflect')[source]
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.
pad (int) – Padding for the Fourier transform.
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. [1].
- 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. [1] 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. [1]).
- 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. [2] 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