actk.utils package

Submodules

actk.utils.dataset_utils module

actk.utils.dataset_utils.check_required_fields(dataset: Union[str, pathlib.Path, pandas.core.frame.DataFrame, dask.dataframe.core.DataFrame], required_fields: List[str]) → Optional[actk.exceptions.MissingDataError][source]

actk.utils.image_utils module

actk.utils.image_utils.crop_raw_channels_with_segmentation(image: numpy.ndarray, channels: List[str]) → numpy.ndarray[source]

Crop imaging data in raw channels using a provided selected full field of with a target cell in the segmentation channels.

Parameters
  • image (np.ndarray) – The 4D, CYXZ, image numpy ndarray output from select_and_adjust_segmentation_ceiling.

  • channels (List[str]) – The channel names for the provided image. The channels output from get_normed_image_array.

Returns

cropped – A 4D numpy ndarray with CYXZ dimensions in the same order as provided. The raw DNA channel has been cropped using the nucleus segmentation. All other raw channels have been cropped using the membrane segmentation.

Return type

np.ndarray

Notes

The original version of this function can be found at: https://aicsbitbucket.corp.alleninstitute.org/projects/MODEL/repos/image_processing_pipeline/browse/aics_single_cell_pipeline/utils.py#114

actk.utils.image_utils.get_features_from_image(image: numpy.ndarray) → Dict[source]

Generate all segmentation, DNA, membrane, and structure features from the provided image.

Parameters

image (np.ndarray) – The 4D, CYXZ, image numpy ndarray output from crop_raw_channels_with_segmentation.

Returns

features – A single dictionary filled with features.

Return type

Dict

Notes

The original version of this function can be found at: https://aicsbitbucket.corp.alleninstitute.org/projects/MODEL/repos/image_processing_pipeline/browse/aics_single_cell_pipeline/features.py#8

The docstring for the original version of this function was incorrect. It stated that it took in a CXYZ image but it took in a CYXZ. This can be seen from line #17 where a transpose to CZYX is done with img.transpose(0, 3, 1, 2). A transpose of (0, 3, 1, 2) on a CXYZ image would result in a CZXY not CZYX. Additionally, simply following the original processing chain shows that the original function is simply handed the output from the original version of the function crop_raw_channels_with_segmentation (crop_cell_nuc) which results in a CYXZ.

actk.utils.image_utils.get_normed_image_array(raw_image: Union[str, pathlib.Path, bytes, io.BufferedIOBase, numpy.ndarray, dask.array.core.Array], nucleus_seg_image: Union[str, pathlib.Path, bytes, io.BufferedIOBase, numpy.ndarray, dask.array.core.Array], membrane_seg_image: Union[str, pathlib.Path, bytes, io.BufferedIOBase, numpy.ndarray, dask.array.core.Array], dna_channel_index: int, membrane_channel_index: int, structure_channel_index: int, brightfield_channel_index: int, nucleus_seg_channel_index: int, membrane_seg_channel_index: int, current_pixel_sizes: Optional[Tuple[float]] = None, desired_pixel_sizes: Optional[Tuple[float]] = None) → Tuple[numpy.ndarray, List[str], Tuple[float]][source]

Provided the original raw image, and a nucleus and membrane segmentation, construct a standardized, ordered, and normalized array of the images.

Parameters
  • raw_image (types.ImageLike) – A filepath to the raw imaging data. The image should be 4D and include channels for DNA, Membrane, Structure, and Transmitted Light.

  • nucleus_seg_image (types.ImageLike) – A filepath to the nucleus segmentation for the provided raw image.

  • membrane_seg_image (types.ImageLike) – A filepath to the membrane segmentation for the provided raw image.

  • dna_channel_index (int) – The index in channel dimension in the raw image that stores DNA data.

  • membrane_channel_index (int) – The index in the channel dimension in the raw image that stores membrane data.

  • structure_channel_index (int) – The index in the channel dimension in the raw image that stores structure data.

  • brightfield_channel_index (int) – The index in the channel dimension in the raw image that stores the brightfield data.

  • nucleus_seg_channel_index (int) – The index in the channel dimension in the nucleus segmentation image that stores the segmentation.

  • membrane_seg_channel_index (int) – The index in the channel dimension in the membrane segmentation image that stores the segmentation.

  • current_pixel_sizes (Optioal[Tuple[float]]) – The current physical pixel sizes as a tuple of the raw image. Default: None (aicsimageio.AICSImage.get_physical_pixel_size on the raw image)

  • desired_pixel_sizes (Optional[Tuple[float]]) – The desired physical pixel sizes as a tuple to scale all images to. Default: None (scale all images to current_pixel_sizes if different)

Returns

  • normed (np.ndarray) – The normalized images stacked into a single CYXZ numpy ndarray.

  • channels (List[str]) – The standardized channel names for the returned array.

  • pixel_sizes (Tuple[float]) – The physical pixel sizes of the returned image in XYZ order.

Notes

The original version of this function can be found at: https://aicsbitbucket.corp.alleninstitute.org/projects/MODEL/repos/image_processing_pipeline/browse/aics_single_cell_pipeline/utils.py#9

actk.utils.image_utils.prepare_image_for_feature_extraction(image: numpy.ndarray) → Tuple[numpy.ndarray, numpy.ndarray, List[List[float]], numpy.ndarray][source]

Prep an image and return any parameters required for feature extraction.

Parameters

image (np.ndarray) – The 4D, CYXZ, image numpy ndarray output from crop_raw_channels_with_segmentation.

Returns

  • prepped_image (np.ndarray) – The prepared image after cell rigid registration and binarizing the segmentations.

  • center_of_mass (np.ndarray) – The index of the center of mass of the membrane segmentation for the provided image.

  • angle (List[List[float]]) – The major angle of the membrane segmentation for the provided image.

  • flipdim (np.ndarry) – Boolean array informing if the dimensions of the image should be flipped.

Notes

The original version of this function can be found at: https://aicsbitbucket.corp.alleninstitute.org/projects/MODEL/repos/image_processing_pipeline/browse/aics_single_cell_pipeline/alignment_tools.py#5

The docstring for the original version of this function was incorrect. It stated that it took in a CXYZ image but it took in a CYXZ. See get_features_from_image for reasoning.

actk.utils.image_utils.select_and_adjust_segmentation_ceiling(image: numpy.ndarray, cell_index: int, cell_ceiling_adjustment: int = 0) → numpy.ndarray[source]

Select and adjust the cell shape “ceiling” for a specific cell in the provided image.

Parameters
  • image (np.ndarray) – The 4D, CYXZ, image numpy ndarray output from get_normed_image_array.

  • cell_index (int) – The integer index for the target cell.

  • cell_ceiling_adjustment (int) – The adjust to use for raising the cell shape ceiling. If <= 0, this will be ignored and cell data will be selected but not adjusted. Default: 0

Returns

adjusted – The image with the membrane segmentation adjusted for ceiling shape correction.

Return type

np.ndarray

Notes

The original version of this function can be found at: https://aicsbitbucket.corp.alleninstitute.org/projects/MODEL/repos/image_processing_pipeline/browse/aics_single_cell_pipeline/utils.py#83

Module contents

Utilities package for actk.