derotation.derotate_by_line#
This module contains the function derotate_an_image_array_line_by_line
,
which derotates an image stack line by line using the provided rotation
angles. This is the core function of the derotation pipeline.
In addition to the main function, this module also contains the
apply_homography
function, which applies a homography to the image stack
to transform it to the plane of rotation. This is used in the derotation
pipeline to correct for a mismatch between the plane of rotation and the
imaging plane.
Functions
|
Applies a homography to the image stack to transform it to the plane of rotation. |
|
Rotates the image stack line by line, using the rotation angles provided. |
- derotation.derotate_by_line.derotate_an_image_array_line_by_line(image_stack, rot_deg_line, blank_pixels_value=0, center=None, plotting_hook_line_addition=None, plotting_hook_image_completed=None, use_homography=False, rotation_plane_angle=0, rotation_plane_orientation=0)[source]#
Rotates the image stack line by line, using the rotation angles provided.
- Description of the algorithm:
takes one line from the image stack
creates a new image with only that line
rotates the line by the given angle without interpolation
substitutes the line in the new image
adds the new image to the derotated image stack
- Edge cases and how they are handled:
the rotation starts in the middle of the image -> the previous lines are copied from the first frame
the rotation ends in the middle of the image -> the remaining lines are copied from the last frame
- Center of rotation:
if not provided, the center of the image is used
- Homography:
if use_homography is True, the image stack is first transformed to the plane of rotation, then derotated. See apply_homography for more details.
- Parameters:
image_stack (np.ndarray) – The image stack to be derotated.
rot_deg_line (np.ndarray) – The rotation angles by line.
center (tuple, optional) – The center of rotation (x, y). If not provided, defaults to the center of the image.
blank_pixels_value (float, optional) – The value to be used for blank pixels. Defaults to 0.
plotting_hook_line_addition (callable, optional) – A function that will be called after each line is added to the derotated image stack.
plotting_hook_image_completed (callable, optional) – A function that will be called after each image is completed.
use_homography (bool, optional) – Whether to use homography to transform the image stack to the plane of rotation. Defaults to
False
.rotation_plane_angle (int, optional) – The angle of the plane of rotation. Required if use_homography is
True
.rotation_plane_orientation (int, optional) – The orientation of the plane of rotation. Required if
use_homography
isTrue
.
- Returns:
The derotated image stack.
- Return type:
np.ndarray
- derotation.derotate_by_line.apply_homography(rotation_plane_angle, rotation_plane_orientation, image_stack, center, blank_pixels_value)[source]#
Applies a homography to the image stack to transform it to the plane of rotation. The homography is applied in three steps: 1. Rotate the image stack according to the orientation of the plane of rotation. 2. Shear the image stack to the plane of rotation. 3. Rotate the image stack back to the original orientation. Rotation plane angle and orientation are calculated from an external source, by fitting an ellipse. The ellipse can have a different orientation than the plane of rotation, so these three steps are necessary.
- Parameters:
rotation_plane_angle (int) – The angle of the plane of rotation in respect to the imaging plane.
rotation_plane_orientation (int) – The orientation of the plane of rotation, as calculated from the ellipse fitting.
image_stack (np.ndarray) – The image stack to be transformed.
center (np.ndarray) – The center of rotation.
blank_pixels_value (float) – The value to be used for blank pixels.
- Returns:
The transformed image stack.
- Return type:
np.ndarray