nanopyx.methods.channel_registration
1from .estimator import ChannelRegistrationEstimator 2from .corrector import ChannelRegistrationCorrector 3from ...core.utils.timeit import timeit 4 5 6def estimate_channel_registration( 7 image_array, 8 ref_channel, 9 max_shift, 10 blocks_per_axis, 11 min_similarity, 12 save_translation_masks=True, 13 translation_mask_save_path=None, 14 apply=True, 15): 16 """ 17 Function used to estimate shift between different color channels and align them of an image based on cross correlation. 18 :param image_array:numpy array with shape (n_channels, y, x); image to be corrected 19 :param ref_channel: int; channel index to be used as reference 20 :param max_shift: int; maximum shift accepted for correction, in pixels. 21 :param blocks_per_axis: int; number of blocks to divide the image in both x and y dimensions 22 :param min_similarity: float; minimum value of similarity to accept a shift as a correction 23 subpixel precision, max simply takes the maximum of the cross correlation map 24 :param save_translation_masks: bool, defaults to True; whether to save translation masks as a tif or not 25 :param translation_mask_save_path: str; path where to save translation masks 26 :param apply: bool; whether to apply the correction if True or only estimate if False 27 :return: if apply==True, returns corrected image with shape (c, y, x) 28 """ 29 estimator = ChannelRegistrationEstimator() 30 aligned_image = estimator.estimate( 31 image_array, 32 ref_channel, 33 max_shift, 34 blocks_per_axis, 35 min_similarity, 36 save_translation_masks=save_translation_masks, 37 translation_mask_save_path=translation_mask_save_path, 38 apply=apply, 39 ) 40 41 if aligned_image is not None: 42 return aligned_image 43 else: 44 pass 45 46 47def apply_channel_registration(image_array, translation_masks=None): 48 """ 49 Function used to align different color channels of an image based on cross correlation. 50 :param image_array: numpy array with shape (n_channels, y, x); image to be registered 51 :param translation_masks: numpy array of translation masks 52 :return: returns corrected image with shape (c, y, x) 53 """ 54 corrector = ChannelRegistrationCorrector() 55 aligned_image = corrector.align_channels(image_array, translation_masks=translation_masks) 56 57 return aligned_image
def
estimate_channel_registration( image_array, ref_channel, max_shift, blocks_per_axis, min_similarity, save_translation_masks=True, translation_mask_save_path=None, apply=True):
7def estimate_channel_registration( 8 image_array, 9 ref_channel, 10 max_shift, 11 blocks_per_axis, 12 min_similarity, 13 save_translation_masks=True, 14 translation_mask_save_path=None, 15 apply=True, 16): 17 """ 18 Function used to estimate shift between different color channels and align them of an image based on cross correlation. 19 :param image_array:numpy array with shape (n_channels, y, x); image to be corrected 20 :param ref_channel: int; channel index to be used as reference 21 :param max_shift: int; maximum shift accepted for correction, in pixels. 22 :param blocks_per_axis: int; number of blocks to divide the image in both x and y dimensions 23 :param min_similarity: float; minimum value of similarity to accept a shift as a correction 24 subpixel precision, max simply takes the maximum of the cross correlation map 25 :param save_translation_masks: bool, defaults to True; whether to save translation masks as a tif or not 26 :param translation_mask_save_path: str; path where to save translation masks 27 :param apply: bool; whether to apply the correction if True or only estimate if False 28 :return: if apply==True, returns corrected image with shape (c, y, x) 29 """ 30 estimator = ChannelRegistrationEstimator() 31 aligned_image = estimator.estimate( 32 image_array, 33 ref_channel, 34 max_shift, 35 blocks_per_axis, 36 min_similarity, 37 save_translation_masks=save_translation_masks, 38 translation_mask_save_path=translation_mask_save_path, 39 apply=apply, 40 ) 41 42 if aligned_image is not None: 43 return aligned_image 44 else: 45 pass
Function used to estimate shift between different color channels and align them of an image based on cross correlation.
Parameters
- image_array: numpy array with shape (n_channels, y, x); image to be corrected
- ref_channel: int; channel index to be used as reference
- max_shift: int; maximum shift accepted for correction, in pixels.
- blocks_per_axis: int; number of blocks to divide the image in both x and y dimensions
- min_similarity: float; minimum value of similarity to accept a shift as a correction subpixel precision, max simply takes the maximum of the cross correlation map
- save_translation_masks: bool, defaults to True; whether to save translation masks as a tif or not
- translation_mask_save_path: str; path where to save translation masks
- apply: bool; whether to apply the correction if True or only estimate if False
Returns
if apply==True, returns corrected image with shape (c, y, x)
def
apply_channel_registration(image_array, translation_masks=None):
48def apply_channel_registration(image_array, translation_masks=None): 49 """ 50 Function used to align different color channels of an image based on cross correlation. 51 :param image_array: numpy array with shape (n_channels, y, x); image to be registered 52 :param translation_masks: numpy array of translation masks 53 :return: returns corrected image with shape (c, y, x) 54 """ 55 corrector = ChannelRegistrationCorrector() 56 aligned_image = corrector.align_channels(image_array, translation_masks=translation_masks) 57 58 return aligned_image
Function used to align different color channels of an image based on cross correlation.
Parameters
- image_array: numpy array with shape (n_channels, y, x); image to be registered
- translation_masks: numpy array of translation masks
Returns
returns corrected image with shape (c, y, x)