nanopyx.methods.drift_alignment

 1from .corrector import DriftCorrector
 2from .estimator import DriftEstimator
 3from ...core.utils.timeit import timeit
 4
 5
 6def estimate_drift_alignment(image_array, save_as_npy=True, save_drift_table_path=None, roi=None, **kwargs):
 7    """
 8    Function use to estimate the drift in a microscopy image.
 9    :param image_array: numpy array  with shape (z, y, x)
10    :param save_as_npy (optional): bool, whether to save as npy (if true) or csv (if false)
11    :param save_drift_table_path (optional): str, path to save drift table
12    :param roi (optional): in case of use should have shape (x0, y0, x1, y1)
13    :param kwargs: additional keyword arguments
14    :return: aligned image as numpy array
15    """
16    estimator = DriftEstimator()
17    corrected_img = estimator.estimate(image_array, roi=roi, **kwargs)
18    print(save_drift_table_path)
19    estimator.save_drift_table(save_as_npy=save_as_npy, path=save_drift_table_path)
20    if corrected_img is not None:
21        return corrected_img
22    else:
23        pass
24
25
26def apply_drift_alignment(image_array, path=None, drift_table=None):
27    """
28    Function used to correct the drift in a microscopy image given a previously calculated drift table.
29    :param image_array: numpy array  with shape (z, y, x); image to be corrected
30    :param path (optional): str; path to previously saved
31    :param drift_table (optional): estimator table object; object containing previously calculated drift table
32    :return: aligned image as numpy array
33    """
34    corrector = DriftCorrector()
35    if drift_table is None:
36        corrector.load_estimator_table(path=path)
37    else:
38        corrector.estimator_table = drift_table
39    corrected_img = corrector.apply_correction(image_array)
40    return corrected_img
def estimate_drift_alignment( image_array, save_as_npy=True, save_drift_table_path=None, roi=None, **kwargs):
 7def estimate_drift_alignment(image_array, save_as_npy=True, save_drift_table_path=None, roi=None, **kwargs):
 8    """
 9    Function use to estimate the drift in a microscopy image.
10    :param image_array: numpy array  with shape (z, y, x)
11    :param save_as_npy (optional): bool, whether to save as npy (if true) or csv (if false)
12    :param save_drift_table_path (optional): str, path to save drift table
13    :param roi (optional): in case of use should have shape (x0, y0, x1, y1)
14    :param kwargs: additional keyword arguments
15    :return: aligned image as numpy array
16    """
17    estimator = DriftEstimator()
18    corrected_img = estimator.estimate(image_array, roi=roi, **kwargs)
19    print(save_drift_table_path)
20    estimator.save_drift_table(save_as_npy=save_as_npy, path=save_drift_table_path)
21    if corrected_img is not None:
22        return corrected_img
23    else:
24        pass

Function use to estimate the drift in a microscopy image.

Parameters
  • image_array: numpy array with shape (z, y, x)
  • save_as_npy (optional): bool, whether to save as npy (if true) or csv (if false)
  • save_drift_table_path (optional): str, path to save drift table
  • roi (optional): in case of use should have shape (x0, y0, x1, y1)
  • kwargs: additional keyword arguments
Returns

aligned image as numpy array

def apply_drift_alignment(image_array, path=None, drift_table=None):
27def apply_drift_alignment(image_array, path=None, drift_table=None):
28    """
29    Function used to correct the drift in a microscopy image given a previously calculated drift table.
30    :param image_array: numpy array  with shape (z, y, x); image to be corrected
31    :param path (optional): str; path to previously saved
32    :param drift_table (optional): estimator table object; object containing previously calculated drift table
33    :return: aligned image as numpy array
34    """
35    corrector = DriftCorrector()
36    if drift_table is None:
37        corrector.load_estimator_table(path=path)
38    else:
39        corrector.estimator_table = drift_table
40    corrected_img = corrector.apply_correction(image_array)
41    return corrected_img

Function used to correct the drift in a microscopy image given a previously calculated drift table.

Parameters
  • image_array: numpy array with shape (z, y, x); image to be corrected
  • path (optional): str; path to previously saved
  • drift_table (optional): estimator table object; object containing previously calculated drift table
Returns

aligned image as numpy array