pystackreg API reference¶
-
class
pystackreg.
StackReg
(transformation)[source]¶ Python implementation of the ImageJ/Fiji StackReg plugin ( http://bigwww.epfl.ch/thevenaz/stackreg/ )
-
get_matrix
()[source]¶ Get the current transformation matrix
Return type: ndarray(3,3) or ndarray(4,4) for bilinear transformation Returns: The transformation matrix
-
get_points
()[source]¶ Returns the pairs of corresponding points from which the transformation matrix can be calculated.
Return type: (ndarray, ndarray) Returns: (Point coordinates of reference image, Point coordinates of image to be aligned)
-
is_registered
()[source]¶ Indicates whether register() was already called and a transformation matrix was calculated
Return type: bool Returns: True if a transformation matrix was already calculated
-
register
(ref, mov)[source]¶ Registers an image to a reference image: Only the transformation matrix will be calculated, the image will not be transformed (use transform() or register_transform() ).
Parameters: - ref (array_like (Ni..., Nj...)) – Reference image (static)
- mov (array_like (Ni..., Nj...)) – The image that should be aligned to the reference image
Return type: ndarray(3,3)
Returns: 2D transformation matrix
-
register_stack
(img, reference='previous', n_frames=1, axis=0, moving_average=1, verbose=False, progress_callback=None)[source]¶ Register a stack of images (movie). Note that this function will not transform the image but only calculate the transformation matrices. For tranformation use transform_stack() after this function or use register_transform_stack() for a single call.
Parameters: - img (array_like(Ni..., Nj..., Nk...)) – The 3D stack of images that should be aligned
- reference (string, one of ['previous', 'first', 'mean']) –
- ‘previous’: Aligns each frame (image) to its previous frame in the stack
- ’first:’ Aligns each frame (image) to the first frame in the stack - if n_frames is > 1, then each frame is aligned to the mean of the first n_frames of the stack
- ’mean’: Aligns each frame (image) to the average of all images in the stack
- n_frames (int, optional) – If reference is ‘first’, then this parameter specifies the number of frames from the beginning of the stack that should be averaged to yield the reference image.
- axis (int, optional) – The axis of the time dimension
- moving_average (int, optional) – If moving_average is greater than 1, a moving average of the stack is first created (using a subset size of moving_average) before registration
- verbose (bool, optional) – Specifies whether a progressbar should be shown using tqdm.
- progress_callback (function, optional) – A function that is called after every iteration. This function should accept the keyword arguments current_iteration:int and end_iteration:int.
Return type: ndarray(img.shape[axis], 3, 3)
Returns: The transformation matrix for each image in the stack
-
register_transform
(ref, mov)[source]¶ Register and transform an image to a reference image.
Parameters: - ref (ref: array_like (Ni..., Nj...)) – Reference image (static)
- mov (array_like (Ni..., Nj...)) – The image that should be aligned to the reference image
Return type: ndarray (Ni…, Nj…)
Returns: Transformed image - will be of the same shape as the input image (cropping may occur)
-
register_transform_stack
(img, reference='previous', n_frames=1, axis=0, moving_average=1, verbose=False, progress_callback=None)[source]¶ Register and transform stack of images (movie).
Parameters: - img (array_like(Ni..., Nj..., Nk...)) – The 3D stack of images that should be aligned
- reference (string, one of ['previous', 'first', 'mean']) –
- ‘previous’: Aligns each frame (image) to its previous frame in the stack
- ’first:’ Aligns each frame (image) to the first frame in the stack - if n_frames is > 1, then each frame is aligned to the mean of the first n_frames of the stack
- ’mean’: Aligns each frame (image) to the average of all images in the stack
- n_frames (int, optional) – If reference is ‘first’, then this parameter specifies the number of frames from the beginning of the stack that should be averaged to yield the reference image.
- axis (int, optional) – The axis of the time dimension
- moving_average (int, optional) – If moving_average is greater than 1, a moving average of the stack is first created (using a subset size of moving_average) before registration
- verbose (bool, optional) – Specifies whether a progressbar should be shown using tqdm.
- progress_callback (function, optional) – A function that is called after every iteration. This function should accept the keyword arguments current_iteration:int and end_iteration:int.
Return type: ndarray(Ni…, Nj…, Nk…)
Returns: The transformed stack
-
set_matrix
(mat)[source]¶ Sets the current transformation matrix
Parameters: mat (ndarray(3,3) or ndarray(4,4) for bilinear transformation) – The transformation matrix
-
transform
(mov, tmat=None)[source]¶ Transform an image according to a previous registration.
Either a transformation matrix has to be explicitly supplied or register() has to be called before calling transform().
Parameters: - mov (array_like (Ni..., Nj...)) – The image that will be transformed
- tmat (ndarray(3,3), optional) – The transformation matrix
Return type: ndarray (Ni…, Nj…)
Returns: Transformed image - will be of the same shape as the input image (cropping may occur)
-
transform_stack
(img, axis=0, tmats=None)[source]¶ Transform a stack after registration.
Parameters: - img (array_like(Ni..., Nj..., Nk...)) – The 3D stack of images that should be aligned
- axis (int, optional) – The axis of the time dimension
- tmats (ndarray(img.shape[axis], 3, 3), optional) – The transformation matrix for each image in the stack
Return type: ndarray(Ni…, Nj…, Nk…)
Returns: The transformed stack
-