piscis.transforms
=================

.. py:module:: piscis.transforms


Classes
-------

.. autoapisummary::

   piscis.transforms.RandomAugment


Functions
---------

.. autoapisummary::

   piscis.transforms.batch_adjust
   piscis.transforms.adjust
   piscis.transforms.normalize
   piscis.transforms.standardize
   piscis.transforms.batch_voronoi_transform
   piscis.transforms.voronoi_transform


Module Contents
---------------

.. py:class:: RandomAugment(seed: int, output_size: Tuple[int, int], augment: bool = True)

   
   Transformer for random data augmentation.



   :Attributes:

       **rng** : np.random.Generator
           Random number generator used for generating random transformations.

       **output_size** : Optional[Tuple[int, int]]
           Output size.

       **flips0** : List[bool]
           List of booleans for flipping along axis 0.

       **flips1** : List[bool]
           List of booleans for flipping along axis 1.

       **scales** : List[float]
           List of image scales.

       **dxys** : List[Tuple[float, float]]
           List of image translation vectors.

       **thetas** : List[float]
           List of image rotation angles.

       **affines** : List[np.ndarray]
           List of affine transformation matrices.

       **intensity_shifts** : List[float]
           List of image intensity shift values.

       **intensity_scales** : List[float]
           List of image intensity scale factors.













   ..
       !! processed by numpydoc !!

   .. py:attribute:: rng


   .. py:attribute:: output_size


   .. py:attribute:: augment
      :value: True



   .. py:method:: apply(image: numpy.ndarray, coords: numpy.ndarray, filter_coords: bool = True, min_scale_factor: float = 0.75, max_scale_factor: float = 1.25, max_intensity_shift: float = 0.1, max_intensity_scale_factor: float = 5) -> Tuple[numpy.ndarray, numpy.ndarray]

      
      Apply random transformations to an image and its corresponding coordinates.


      :Parameters:

          **images** : np.ndarray
              Images to transform.

          **coords** : np.ndarray
              Coordinates to transform.

          **filter_coords** : bool, optional
              Whether to filter coordinates outside the transformed image. Default is True.

          **min_scale_factor** : float, optional
              Minimum scale factor. Default is 0.75.

          **max_scale_factor** : float, optional
              Maximum scale factor. Default is 1.25.

          **max_intensity_shift** : float, optional
              Maximum intensity shift. Intensity shifts are sampled from a uniform distribution with support on the
              interval [-`max_intensity_shift`, `max_intensity_shift`]. Default is 0.1.

          **max_intensity_scale_factor** : float, optional
              Maximum intensity scale factor. Intensity scale factors are sampled from a log-uniform distribution with
              support on the interval [1 / `max_intensity_scale_factor`, `max_intensity_scale_factor`]. Default is 5.



      :Returns:

          **image** : np.ndarray
              Transformed image.

          **coords** : np.ndarray
              Transformed coordinates.











      ..
          !! processed by numpydoc !!


.. py:function:: batch_adjust(images: Sequence[numpy.ndarray], adjustment: Optional[str], **kwargs: Any) -> Sequence[numpy.ndarray]

   
   Batch adjust images.


   :Parameters:

       **images** : Sequence[np.ndarray]
           Images to adjust.

       **adjustment** : Optional[str]
           Adjustment type. Supported types are 'normalize' and 'standardize'.

       **\*\*kwargs** : Any
           Keyword arguments for the adjustment function.



   :Returns:

       **adjusted_images** : Sequence[np.ndarray]
           Adjusted images.











   ..
       !! processed by numpydoc !!

.. py:function:: adjust(image: numpy.ndarray, adjustment: Optional[str], **kwargs: Any) -> numpy.ndarray

   
   Adjust an image.


   :Parameters:

       **image** : np.ndarray
           Image to adjust.

       **adjustment** : Optional[str]
           Adjustment type. Supported types are 'normalize' and 'standardize'.

       **\*\*kwargs** : Any
           Keyword arguments for the adjustment function.



   :Returns:

       **adjusted_image** : np.ndarray
           Adjusted image.




   :Raises:

       ValueError
           If the `adjustment` type is not supported.







   ..
       !! processed by numpydoc !!

.. py:function:: normalize(image: numpy.ndarray, lower: float = 0, upper: float = 100, epsilon: float = 1e-07) -> numpy.ndarray

   
   Normalize an image to the range [0, 1] based on the specified percentiles.


   :Parameters:

       **image** : np.ndarray
           Image to normalize.

       **lower** : float, optional
           Lower percentile. Default is 0.

       **upper** : float, optional
           Upper percentile. Default is 100.

       **epsilon** : float, optional
           Small constant for numerical stability. Default is 1e-7.



   :Returns:

       **normalized_image** : np.ndarray
           Normalized image.











   ..
       !! processed by numpydoc !!

.. py:function:: standardize(image: numpy.ndarray, epsilon: float = 1e-07) -> numpy.ndarray

   
   Standardize an image to zero mean and unit variance.


   :Parameters:

       **image** : np.ndarray
           Image to standardize.

       **epsilon** : float, optional
           Small constant for numerical stability. Default is 1e-7.



   :Returns:

       **standardized_image** : np.ndarray
           Standardized image.











   ..
       !! processed by numpydoc !!

.. py:function:: batch_voronoi_transform(coords: Sequence[numpy.ndarray], output_size: Tuple[int, int] = (256, 256), dilation_iterations: int = 1, device: Optional[str] = None) -> Tuple[torch.Tensor, torch.Tensor]

   
   Batch Voronoi transform.


   :Parameters:

       **coords** : Sequence[np.ndarray]
           List of coordinates.

       **output_size** : Tuple[int, int], optional
           Output size. Default is (256, 256).

       **dilation_iterations** : int, optional
           Number of iterations to dilate ground truth labels. Default is 1.

       **device** : Optional[str], optional
           Desired device of returned tensors. Default is None.



   :Returns:

       **labels** : torch.Tensor
           Tensor where each pixel is a boolean for whether it contains a point in `coords`.

       **deltas** : torch.Tensor
           Tensor where each pixel is a vector to the nearest point in `coords`.











   ..
       !! processed by numpydoc !!

.. py:function:: voronoi_transform(coords: numpy.ndarray, output_size: Tuple[int, int] = (256, 256), dilation_iterations: int = 1, device: Optional[str] = None, index_map: Optional[torch.Tensor] = None) -> Tuple[torch.Tensor, torch.Tensor]

   
   Transform a list of coordinates to generate ground truth binary labels and displacement vectors from each pixel
   to the nearest point via a Voronoi tessellation. Adapted from DeepCell Spots.


   :Parameters:

       **coords** : np.ndarray
           List of coordinates.

       **output_size** : Tuple[int, int], optional
           Output size. Default is (256, 256).

       **dilation_iterations** : int, optional
           Number of iterations to dilate ground truth labels. Default is 1.

       **device** : Optional[str], optional
           Desired device of returned tensors. Default is None.

       **index_map** : Optional[torch.Tensor], optional
           Precomputed index map. Will be generated internally if `index_map` is None. Default is None.



   :Returns:

       **labels** : torch.Tensor
           Tensor where each pixel is a boolean for whether it contains a point in `coords`.

       **deltas** : torch.Tensor
           Tensor where each pixel is a vector to the nearest point in `coords`.









   .. rubric:: References

   .. [R24833becb1da-1] Laubscher, Emily, et al. "vanvalenlab/deepcell-spots: Deep Learning Library for Spot Detection." GitHub,
          https://github.com/vanvalenlab/deepcell-spots.

   .. only:: latex

      [R24833becb1da-1]_


   ..
       !! processed by numpydoc !!

