pystack3d.registration_transformation module
Functions related to the registration transformation processing
- pystack3d.registration_transformation.init_args(params, shape)
Initialize arguments related to the current processing (‘registration_transformation’)
- Parameters:
params (dict) – Dictionary related to the current process. See the related documentation for more details.
shape (tuple of 3 int) – Shape of the stack to process
- pystack3d.registration_transformation.registration_transformation(fnames=None, inds_partition=None, queue_incr=None, nb_blocks=None, pre_calculated_tmats=None, constant_drift=None, box_size_averaging=None, subpixel=True, mode='constant', cropping=False, output_dirname=None)
Function dedicated to transformation matrices application for the image registration
- Parameters:
fnames (list of pathlib.Path, optional) – List of ‘.tif’ filenames to process
inds_partition (list of ints, optional) – List of indexes to be considered by the global var SHARED_ARRAY when working in multiprocessing
queue_incr (multiprocessing.Queue, optional) – Queue passed to the function to interact with the progress bar
nb_blocks (tuple of 2 ints (p, q), optional) – Number of patches (sub-images) to consider in each axis to perform the registrations. If None, consider the whole image
pre_calculated_tmats (numpy.ndarray((nslices * nb_blocks, 3, 3)), optional) – Transformations matrices previously calculated
constant_drift (tuple of 2 floats, optional) – Constant translation values (transl_x, transl_y) to remove at each slice in the transformation matrices
box_size_averaging (int, optional) – Box size associated to the running-averaged transformation matrices to remove at each slice
subpixel (bool, optional) – Activation keyword to enable subpixel translation
mode ({'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional) – For extrapolation, points outside the boundaries of the input are filled according to the given mode that is related to numpy.pad. If ‘constant’ (Default mode), cval value is automatically set to np.nan.
output_dirname (str, optional) – Directory pathname for process results saving
- pystack3d.registration_transformation.plot(output_dirname)
Plot the specific data related to the current process
- pystack3d.registration_transformation.img_transformation(img, tmats, nb_blocks=None, mode='constant', cval=nan, order=None)
Apply affine or piecewise affine transformation to operate the image registration according to ‘nb_blocks’
- Parameters:
img (numpy.ndarray((m,n))) – Image considered as ‘moving’ image
tmats (numpy.ndarray((p*q, 3*3))) – Transformation matrix calculated in all patches
nb_blocks (tuple of 2 ints (p, q), optional) – Number of patches (sub-images) to consider in each axis to perform the registrations. If None, consider the whole image
mode (str, optional) – Padding mode among {‘constant’, ‘edge’, ‘symmetric’, ‘reflect’, ‘wrap’}. Points outside the boundaries of the input are filled according to the given mode. Modes match the behaviour of numpy.pad.
cval (float, optional) – Used in conjunction with mode ‘constant’, the value outside the image boundaries.
order (int, optional) – Order associated to the interpolation in the warp function
- Returns:
img_reg (numpy.ndarray((m,n))) – Resulting registered image
tform (PiecewiseAffineTransform object) – Transformation applied for the image registration
- pystack3d.registration_transformation.constant_drift_removal(tmats, drift, is_cumulative=True)
Remove a constant drift in the (cumulative) transformation matrices
- Parameters:
tmats (numpy.ndarray((nslices * nb_blocks, 3, 3))) – Transformations matrices calculated during the registration processing
drift (sequence of 2 floats) – Constant translation values (transl_x, transl_y) to remove at each slice
is_cumulative (bool, optional) – Key to consider ‘tmats’ as cumulative transformation matrices
- Returns:
tmats_new – Transformations matrices with the constant drift removed
- Return type:
numpy.ndarray((nslices * nb_blocks, 3, 3))
- pystack3d.registration_transformation.running_avg_removal(tmats, box_size=20)
Remove a running average in the transformation matrices
- Parameters:
tmats (numpy.ndarray((nslices * nb_blocks, 3, 3))) – Transformations matrices calculated during the registration processing
box_size (int, optional) – Size of the window for the running average
- Returns:
tmats_new – Transformations matrices with the running average removed
- Return type:
numpy.ndarray((nslices * nb_blocks, 3, 3))
- pystack3d.registration_transformation.inner_rectangle(shape, tmats_cumul, nb_blocks=None)
Calculate indices related to the maximum inner rectangle resulting of the successive ‘tmats_cumul’ affine transformations.
- Parameters:
shape (tuple of 2 ints (m, n)) – Shape of the images/slices
tmats_cumul (numpy.ndarray((nslices * p * q, 3, 3))) – Cumulative tansformations matrices previously calculated during registration flow steps
nb_blocks (tuple of 2 ints (p, q), optional) – Number of patches (sub-images) used during the registration processing
- Returns:
(imin, imax, jmin, jmax) (tuple of 4 ints) – Indices associated to the largest rectangle resulting from tmats_cumul
img_reg (numpy.ndarray((m, n))) – Image resulting from the tmats_cumul application. Area with 0 values correspond to the region affected by the registration
- pystack3d.registration_transformation.find_max_inner_rectangle(arr, value=0)
Returns coordinates of the largest rectangle containing the ‘value’. From : https://stackoverflow.com/questions/2478447
- Parameters:
arr (numpy.ndarray((m, n), dtype=int)) – 2D array to work with
value (int, optional) – Reference value associated to the area of the largest rectangle
- Returns:
imin, imax, jmin, jmax – indices associated to the largest rectangle
- Return type:
ints