piscis.transforms#

Classes#

RandomAugment

Transformer for random data augmentation.

Functions#

batch_adjust(→ Sequence[numpy.ndarray])

Batch adjust images.

adjust(→ numpy.ndarray)

Adjust an image.

normalize(→ numpy.ndarray)

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

standardize(→ numpy.ndarray)

Standardize an image to zero mean and unit variance.

batch_voronoi_transform(, dilation_iterations, device, ...)

Batch Voronoi transform.

voronoi_transform(, dilation_iterations, device, ...)

Transform a list of coordinates to generate ground truth binary labels and displacement vectors from each pixel

Module Contents#

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

Transformer for random data augmentation.

Attributes:
rngnp.random.Generator

Random number generator used for generating random transformations.

output_sizeOptional[Tuple[int, int]]

Output size.

flips0List[bool]

List of booleans for flipping along axis 0.

flips1List[bool]

List of booleans for flipping along axis 1.

scalesList[float]

List of image scales.

dxysList[Tuple[float, float]]

List of image translation vectors.

thetasList[float]

List of image rotation angles.

affinesList[np.ndarray]

List of affine transformation matrices.

intensity_shiftsList[float]

List of image intensity shift values.

intensity_scalesList[float]

List of image intensity scale factors.

rng#
output_size#
augment = True#
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:
imagesnp.ndarray

Images to transform.

coordsnp.ndarray

Coordinates to transform.

filter_coordsbool, optional

Whether to filter coordinates outside the transformed image. Default is True.

min_scale_factorfloat, optional

Minimum scale factor. Default is 0.75.

max_scale_factorfloat, optional

Maximum scale factor. Default is 1.25.

max_intensity_shiftfloat, 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_factorfloat, 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:
imagenp.ndarray

Transformed image.

coordsnp.ndarray

Transformed coordinates.

piscis.transforms.batch_adjust(images: Sequence[numpy.ndarray], adjustment: str | None, **kwargs: Any) Sequence[numpy.ndarray]#

Batch adjust images.

Parameters:
imagesSequence[np.ndarray]

Images to adjust.

adjustmentOptional[str]

Adjustment type. Supported types are ‘normalize’ and ‘standardize’.

**kwargsAny

Keyword arguments for the adjustment function.

Returns:
adjusted_imagesSequence[np.ndarray]

Adjusted images.

piscis.transforms.adjust(image: numpy.ndarray, adjustment: str | None, **kwargs: Any) numpy.ndarray#

Adjust an image.

Parameters:
imagenp.ndarray

Image to adjust.

adjustmentOptional[str]

Adjustment type. Supported types are ‘normalize’ and ‘standardize’.

**kwargsAny

Keyword arguments for the adjustment function.

Returns:
adjusted_imagenp.ndarray

Adjusted image.

Raises:
ValueError

If the adjustment type is not supported.

piscis.transforms.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:
imagenp.ndarray

Image to normalize.

lowerfloat, optional

Lower percentile. Default is 0.

upperfloat, optional

Upper percentile. Default is 100.

epsilonfloat, optional

Small constant for numerical stability. Default is 1e-7.

Returns:
normalized_imagenp.ndarray

Normalized image.

piscis.transforms.standardize(image: numpy.ndarray, epsilon: float = 1e-07) numpy.ndarray#

Standardize an image to zero mean and unit variance.

Parameters:
imagenp.ndarray

Image to standardize.

epsilonfloat, optional

Small constant for numerical stability. Default is 1e-7.

Returns:
standardized_imagenp.ndarray

Standardized image.

piscis.transforms.batch_voronoi_transform(coords: Sequence[numpy.ndarray], output_size: Tuple[int, int] = (256, 256), dilation_iterations: int = 1, device: str | None = None) Tuple[torch.Tensor, torch.Tensor]#

Batch Voronoi transform.

Parameters:
coordsSequence[np.ndarray]

List of coordinates.

output_sizeTuple[int, int], optional

Output size. Default is (256, 256).

dilation_iterationsint, optional

Number of iterations to dilate ground truth labels. Default is 1.

deviceOptional[str], optional

Desired device of returned tensors. Default is None.

Returns:
labelstorch.Tensor

Tensor where each pixel is a boolean for whether it contains a point in coords.

deltastorch.Tensor

Tensor where each pixel is a vector to the nearest point in coords.

piscis.transforms.voronoi_transform(coords: numpy.ndarray, output_size: Tuple[int, int] = (256, 256), dilation_iterations: int = 1, device: str | None = None, index_map: torch.Tensor | None = 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:
coordsnp.ndarray

List of coordinates.

output_sizeTuple[int, int], optional

Output size. Default is (256, 256).

dilation_iterationsint, optional

Number of iterations to dilate ground truth labels. Default is 1.

deviceOptional[str], optional

Desired device of returned tensors. Default is None.

index_mapOptional[torch.Tensor], optional

Precomputed index map. Will be generated internally if index_map is None. Default is None.

Returns:
labelstorch.Tensor

Tensor where each pixel is a boolean for whether it contains a point in coords.

deltastorch.Tensor

Tensor where each pixel is a vector to the nearest point in coords.

References

[1]

Laubscher, Emily, et al. “vanvalenlab/deepcell-spots: Deep Learning Library for Spot Detection.” GitHub, vanvalenlab/deepcell-spots.