derotation.simulate.line_scanning_microscope#

This module contains the Rotator class, which is used to simulate the acquisition of a rotated image stack as if for each line acquired, the sample was rotated at a given angle in a given center and plane of rotation.

Classes

Rotator(angles, image_stack[, ...])

The Rotator aims to imitate the scanning pattern of a multi-photon microscope while the speciment is rotating.

class derotation.simulate.line_scanning_microscope.Rotator(angles, image_stack, center_offset=(0, 0), rotation_plane_angle=0, rotation_plane_orientation=0, blank_pixel_val=None)[source]#

The Rotator aims to imitate the scanning pattern of a multi-photon microscope while the speciment is rotating. Currently, it approximates the acquisition of a given line as if it was instantaneous, happening while the sample was rotated at a given angle.

It is also possible to simulate the acquisition of a movie from a rotation plane that differs from the scanning plane. To achieve this, provide the rotation_plane_angle and if you want the orientation as well.

The purpose of the Rotator object is to imitate the acquisition of rotated samples in order to validate the derotation algorithms and in the future, build a forward model of the transformation.

Parameters:
  • angles (np.ndarray) – An array of angles in degrees, representing the rotation of the sample at the time of acquisition. The length of the array should be equal to the number of lines per frame multiplied by the number of frames.

  • image_stack (np.ndarray) – The image stack represents the acquired images, as if there was no rotation. The shape of the image stack should be (num_frames, num_lines_per_frame, num_pixels_per_line). In case you want to rotate a single frame, provide an (1, num_lines_per_frame, num_pixels_per_line) image stack.

  • center (Tuple[int, int], optional) – The center of rotation. If None, the center is going to be the center of the image, by default None

  • rotation_plane_angle (float, optional) – The z angle of the rotation plane in degrees in relation to the scanning plane. If 0, the rotation plane is the same as the scanning plane, by default None.

  • rotation_plane_orientation (float, optional) – The angle of the rotation plane in the x-y plane in degrees, transposed into the rotation plane. If 0, the rotation plane is the same as the scanning plane, by default None.

  • blank_pixel_val (Optional[float], optional) – The value to fill the blank pixels with. If None, it is going to be the minimum value of the image stack, by default None.

Raises:
  • AssertionError (1) – If the number of angles is not equal to the number of lines per frame multiplied by the number of frames

  • AssertionError (2) – If rotation_plane_orientation is provided, but rotation_plane_angle is not provided.

Methods

calculate_pixel_shift()

Calculate the pixel shift and the new image size based on the rotation plane angle.

create_homography_matrices()

Create the homography matrices to simulate the acquisition of a rotated sample from a different plane than the scanning plane.

get_blank_pixels_value()

Get a default value to fill the edges of the rotated image.

homography_rotation_to_scanning_plane(image)

Apply the homography to the image to simulate the acquisition of a rotated sample from a different plane than the scanning plane.

rotate_by_line()

Simulate the acquisition of a rotated image stack as if for each line acquired, the sample was rotated at a given angle in a given center and plane of rotation.

rotate_sample(image, angle[, center])

Rotate the entire image by a given angle.

create_homography_matrices()[source]#

Create the homography matrices to simulate the acquisition of a rotated sample from a different plane than the scanning plane.

The homography matrix is used to transform the image from the scanning plane to the rotation plane and vice-versa.

The homography matrix is defined as: H = [[1, 0, 0], [0, cos(theta), 0], [0, 0, 1]] where theta is the rotation plane angle in degrees.

Currently, we are using only the inverse homography matrix to transform the image from the rotation plane to the scanning plane.

Return type:

None

calculate_pixel_shift()[source]#

Calculate the pixel shift and the new image size based on the rotation plane angle.

Return type:

None

rotate_by_line()[source]#

Simulate the acquisition of a rotated image stack as if for each line acquired, the sample was rotated at a given angle in a given center and plane of rotation.

Each frame is rotated n_lines_per_frame times, where n_lines_per_frame is the number of lines per frame in the image stack.

Returns:

The rotated image stack of the same shape as the input image stack, i.e. (num_frames, num_lines_per_frame, num_pixels_per_line).

Return type:

np.ndarray

homography_rotation_to_scanning_plane(image)[source]#

Apply the homography to the image to simulate the acquisition of a rotated sample from a different plane than the scanning plane.

Parameters:

image (np.ndarray) – The image to apply the homography.

Returns:

The transformed image.

Return type:

np.ndarray

rotate_sample(image, angle, center=None)[source]#

Rotate the entire image by a given angle. Uses affine transformation with no interpolation.

Parameters:
  • image (np.ndarray) – The image to rotate.

  • angle (float) – The angle in degrees to rotate the image in degrees. If positive, rotates clockwise. If negative, rotates counterclockwise.

  • blank_pixel (float) – The value to fill the blank pixels with.

Returns:

The rotated image.

Return type:

np.ndarray

get_blank_pixels_value()[source]#

Get a default value to fill the edges of the rotated image. This is necessary because we are using affine transformation with no interpolation, so we need to fill the blank pixels with some value.

As for now, it returns the minimum value of the image stack.

Returns:

The minimum value of the image stack.

Return type:

float