torchsky.transforms¶
Stability: core. Names on this page follow the deprecation policy in contributing.
Display stretches, normalisation, cropping, and augmentation transforms.
Guides: encoders
This reference is generated from the package source. Names are grouped by
the module that defines them; import every name from the public
namespace torchsky.transforms unless the group text says otherwise.
Top-level namespace¶
Display stretches, normalisation, cropping, and augmentation transforms.
Every transform is a callable object that maps one tensor to one tensor and keeps the last two axes spatial for the geometric transforms. Stretches are monotone display mappings on non-negative data; normalisations are affine and dtype-preserving.
AsinhStretch ¶
AsinhStretch(a: float = 0.1, Q: float = 8.0)
CenterCrop ¶
CenterCrop(size: _Size)
Compose ¶
Compose(transforms: Sequence[Any])
Apply transforms left to right.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transforms
|
Sequence[Any]
|
Ordered callables, each accepting the previous tensor. |
required |
Examples:
>>> import torch
>>> from torchsky.transforms import Compose
>>> Compose([lambda value: value + 1])(torch.tensor(1)).item()
2
GaussianNoise ¶
GaussianNoise(std: float = 0.01, snr_based: bool = False)
Additive Gaussian noise, either absolute or scaled to the signal.
snr_based=True sets the noise standard deviation to
signal_std / std, so std is then a signal-to-noise ratio.
LogStretch ¶
LogStretch(a: float = 1000.0)
MinMaxScale ¶
MinMaxScale(min_val: float = 0.0, max_val: float = 1.0)
Normalize ¶
Normalize(
mean: float | None = None, std: float | None = None
)
PerturbByError ¶
PerturbByError(scale: float = 1.0)
PoissonNoise ¶
PoissonNoise(lam: float = 1.0)
PowerStretch ¶
PowerStretch(gamma: float = 0.5)
RandomCrop ¶
RandomCrop(size: _Size)
RandomFlip ¶
RandomFlip(
horizontal: bool = True,
vertical: bool = True,
p: float = 0.5,
)
RandomRotation ¶
RandomRotation(interpolation: str = 'bilinear')
Rotate the trailing two axes by a uniformly random angle.
rotate ¶
rotate(tensor: Tensor, degrees: float) -> Tensor
Rotate the trailing two axes by degrees about the image centre.
The rotation is rigid in pixel space. affine_grid works in
coordinates normalised per axis to [-1, 1], so for a non-square image
the pixel-space rotation R becomes diag(2/W, 2/H) R diag(W/2, H/2)
there; using R directly would shear and stretch the image.
RobustScale ¶
RobustScale(center: bool = True, scale: bool = True)
ToDevice ¶
ToDevice(device: str | device)
ZScale ¶
ZScale(contrast: float = 0.25, max_reject: float = 0.5)
create_display_transform ¶
create_display_transform(
stretch: str = "asinh", **kwargs: Any
) -> Compose
Build a one-step display Compose for a named stretch.
create_inference_transform ¶
create_inference_transform(
normalize: bool = True,
) -> Compose
Optional zscale only, keeping the input shape.