cyto_dl.image.transforms.multiscale_cropper module#

class cyto_dl.image.transforms.multiscale_cropper.RandomMultiScaleCropd(keys: Sequence[str], patch_shape: Sequence[int], scales_dict: Dict, patch_per_image: int = 1, selection_fn: Callable | None = None, max_attempts: int = 100, allow_missing_keys: bool = False)[source]#

Bases: RandomizableTransform

Monai-style transform that generates random slices at integer multiple scales.

This can be useful for training superresolution models.

Parameters:
  • keys (Sequence[str]) – list of names dictionary keys to apply transform to

  • x_key (str) – name of key that is passed into network. Its corresponding scale must be 1

  • patch_shape (Sequence[int]) – patch size to sample at resolution 1. Can have len 2 or 3

  • patch_per_image (int= 1) – Number of patches to sample per image

  • scales_dict (Dict) – Dictionary mapping scales key names to their resize factors. For example, {raw:1, seg: [1.0, 0.5, 0.5]} would take samples from raw of size patch_shape and samples from seg at patch_shape/[1.0,0.5, 0.5]

  • selection_fn (Callable=None) – Function that takes in an image and returns True or False. Used to decide whether a sampled image should be kept or discarded.

  • max_attempts (int=100) – max attempts to try sampling patches from an image before quitting

generate_slices(image_dict: Dict) Dict[source]#

Generate dictionary of slices at all scales starting at random point.