camera_alignment_core package#

Subpackages#

Submodules#

camera_alignment_core.align module#

class camera_alignment_core.align.Align(optical_control: Union[str, Path], magnification: Magnification, out_dir: Union[str, Path], reference_channel_index: Optional[int] = None, shift_channel_index: Optional[int] = None, alignment_transform: Optional[AlignmentTransform] = None)#

Bases: object

High-level API for core camera alignment functionality.

Example

>>> align = Align(
>>>     optical_control="/some/path/to/an/argolight-field-of-rings.czi",
>>>     magnification=Magnification(20),
>>>     out_dir="/tmp/whereever",
>>> )
>>> aligned_scenes = align.align_image("/some/path/to/an/image.czi", channels_to_shift=[0, 2])
>>> aligned_optical_control = align.align_optical_control(channels_to_shift=[0, 2])
>>> alignment_matrix = align.alignment_transform.matrix
>>> alignment_info = align.alignment_transform.info
align_image(image: Union[str, Path], channels_to_shift: List[int], scenes: List[int] = [], timepoints: List[int] = [], crop_output: bool = True, interpolation: int = 0) List[AlignedImage]#

Align channels within image using similarity transform generated from the optical control image passed to this instance at construction. Scenes within image will be saved to their own image files once aligned.

Parameters:
  • image (Union[str, Path]) – Microscopy image that requires alignment. Passed as-is to aicsimageio.AICSImage constructor.

  • channels_to_shift (List[int]) – Index positions of channels within image that should be shifted. N.b.: indices start at 0. E.g.: Specify [0, 2] to apply the alignment transform to channels at index positions 0 and 2 within image.

Keyword Arguments:
  • scenes (Optional[List[int]]) – Which scene or scenes within image to align. If not specified, will align all scenes within image. Specify as list of 0-index scene indices within image.

  • timepoints (Optional[List[int]]) – Which timepoint or timepoints within image to perform the alignment. If not specified, will align all timepoints within image. Specify as list of 0-index timepoint indices within image.

  • crop_output (Optional[bool]) – Optional flag for toggling whether to crop aligned image according to standard dimensions for the magnification at which the image was acquired. Defaults to True, which means, “yes, crop the image.”

  • interpolation (Optional[int]) – Interpolation order to use when applying the alignment transform. Default is 0.

Returns:

A list of namedtuples, each of which describes a scene within image that was aligned.

Return type:

List[AlignedImage]

align_optical_control(channels_to_shift: List[int], crop_output: bool = True) Path#

Align the optical control image using the similarity matrix generated from the optical control itself. Useful as a reference for judging the quality of the alignment.

Parameters:

channels_to_shift (List[int]) – Index positions of channels within image that should be shifted. N.b.: indices start at 0. E.g.: Specify [0, 2] to apply the alignment transform to channels at index positions 0 and 2 within image.

Keyword Arguments:

crop_output (Optional[bool]) – Optional flag for toggling whether to crop aligned image according to standard dimensions for the magnification at which the image was acquired. Defaults to True, which means, “yes, crop the image.”

Return type:

pathlib.Path

Notes

This method will output the aligned optical control image to a file as a side-effect, returning the pathlib.Path to the file.

property alignment_transform: AlignmentTransform#

Get the similarity matrix and camera_alignment_core.utils.AlignmentInfo used to perform camera alignment.

class camera_alignment_core.align.AlignedImage(scene, path)#

Bases: NamedTuple

path: Path#

Alias for field number 1

scene: int#

Alias for field number 0

class camera_alignment_core.align.AlignmentTransform(matrix, info)#

Bases: NamedTuple

info: AlignmentInfo#

Alias for field number 1

matrix: ndarray[Any, dtype[float16]]#

Alias for field number 0

camera_alignment_core.alignment_core module#

camera_alignment_core.alignment_core.align_image(image: ndarray[Any, dtype[uint16]], alignment_matrix: ndarray[Any, dtype[float16]], channels_to_shift: List[int], interpolation: int = 0) ndarray[Any, dtype[uint16]]#

Align a CZYX image using alignment_matrix. Will only apply the alignment_matrix to image slices within the channels specified in channels_to_shift.

Parameters:
  • image (numpy.typing.NDArray[numpy.uint16]) – Must be a 4 dimensional image in following dimensional order: ‘CZYX’

  • alignment_matrix (numpy.typing.NDArray[numpy.float16]) – 3x3 matrix that can be used by skimage.transform.warp to transform a single z-slice of an image.

  • channels_to_shift (List[int]) – Index positions of channels within image that should be shifted. N.b.: indices start at 0. E.g.: Specify [0, 2] to apply the alignment transform to channels at index positions 0 and 2 within image.

  • interpolation (int) – Interpolation order to use when applying the alignment transform. Default is 0.

camera_alignment_core.alignment_core.crop(image: ndarray[Any, dtype[uint16]], magnification: Magnification, black_pixel_cutoff: int = 50) ndarray[Any, dtype[uint16]]#

Crops a CZYX image based on the magnification used to generate the image

camera_alignment_core.alignment_core.generate_alignment_matrix(optical_control_image: ndarray[Any, dtype[uint16]], reference_channel: int, shift_channel: int, magnification: int, px_size_xy: float) Tuple[ndarray[Any, dtype[float16]], AlignmentInfo]#

camera_alignment_core.constants module#

class camera_alignment_core.constants.CroppingDimension(x, y)#

Bases: NamedTuple

x: int#

Alias for field number 0

y: int#

Alias for field number 1

class camera_alignment_core.constants.Magnification(value)#

Bases: Enum

Supported magnification values.

ONE_HUNDRED = 100#
SIXTY_THREE = 63#
TWENTY = 20#
property cropping_dimension: CroppingDimension#

Module contents#

class camera_alignment_core.Align(optical_control: Union[str, Path], magnification: Magnification, out_dir: Union[str, Path], reference_channel_index: Optional[int] = None, shift_channel_index: Optional[int] = None, alignment_transform: Optional[AlignmentTransform] = None)#

Bases: object

High-level API for core camera alignment functionality.

Example

>>> align = Align(
>>>     optical_control="/some/path/to/an/argolight-field-of-rings.czi",
>>>     magnification=Magnification(20),
>>>     out_dir="/tmp/whereever",
>>> )
>>> aligned_scenes = align.align_image("/some/path/to/an/image.czi", channels_to_shift=[0, 2])
>>> aligned_optical_control = align.align_optical_control(channels_to_shift=[0, 2])
>>> alignment_matrix = align.alignment_transform.matrix
>>> alignment_info = align.alignment_transform.info
align_image(image: Union[str, Path], channels_to_shift: List[int], scenes: List[int] = [], timepoints: List[int] = [], crop_output: bool = True, interpolation: int = 0) List[AlignedImage]#

Align channels within image using similarity transform generated from the optical control image passed to this instance at construction. Scenes within image will be saved to their own image files once aligned.

Parameters:
  • image (Union[str, Path]) – Microscopy image that requires alignment. Passed as-is to aicsimageio.AICSImage constructor.

  • channels_to_shift (List[int]) – Index positions of channels within image that should be shifted. N.b.: indices start at 0. E.g.: Specify [0, 2] to apply the alignment transform to channels at index positions 0 and 2 within image.

Keyword Arguments:
  • scenes (Optional[List[int]]) – Which scene or scenes within image to align. If not specified, will align all scenes within image. Specify as list of 0-index scene indices within image.

  • timepoints (Optional[List[int]]) – Which timepoint or timepoints within image to perform the alignment. If not specified, will align all timepoints within image. Specify as list of 0-index timepoint indices within image.

  • crop_output (Optional[bool]) – Optional flag for toggling whether to crop aligned image according to standard dimensions for the magnification at which the image was acquired. Defaults to True, which means, “yes, crop the image.”

  • interpolation (Optional[int]) – Interpolation order to use when applying the alignment transform. Default is 0.

Returns:

A list of namedtuples, each of which describes a scene within image that was aligned.

Return type:

List[AlignedImage]

align_optical_control(channels_to_shift: List[int], crop_output: bool = True) Path#

Align the optical control image using the similarity matrix generated from the optical control itself. Useful as a reference for judging the quality of the alignment.

Parameters:

channels_to_shift (List[int]) – Index positions of channels within image that should be shifted. N.b.: indices start at 0. E.g.: Specify [0, 2] to apply the alignment transform to channels at index positions 0 and 2 within image.

Keyword Arguments:

crop_output (Optional[bool]) – Optional flag for toggling whether to crop aligned image according to standard dimensions for the magnification at which the image was acquired. Defaults to True, which means, “yes, crop the image.”

Return type:

pathlib.Path

Notes

This method will output the aligned optical control image to a file as a side-effect, returning the pathlib.Path to the file.

property alignment_transform: AlignmentTransform#

Get the similarity matrix and camera_alignment_core.utils.AlignmentInfo used to perform camera alignment.

class camera_alignment_core.Magnification(value)#

Bases: Enum

Supported magnification values.

ONE_HUNDRED = 100#
SIXTY_THREE = 63#
TWENTY = 20#
property cropping_dimension: CroppingDimension#
camera_alignment_core.get_module_version()#