transforms
99 memberslucid.utils.transformslucid.utils.transforms — image transform library.
An Albumentations-compatible transform library (matching class names +
constructor signatures) built tensor-native on Lucid (no numpy / PIL,
per H4). Transforms consume / produce lucid.Tensor images
(C, H, W) or (B, C, H, W); image decoding (file → tensor)
lives outside this package.
Two entry points:
- Class transforms —
Composea list ofTransformobjects. Each is applied with probabilitypand moves every typed target (Image/Mask/BoundingBoxes/Keypoints) consistently. - Functional — stateless ops under
lucid.utils.transforms.functional.
Presets (ImageClassification) bundle a task's canonical
inference pipeline; pretrained weights ship preprocessing this way.
>>> import lucid
>>> import lucid.utils.transforms as T
>>> tf = T.Compose([
... T.SmallestMaxSize(256),
... T.CenterCrop(224, 224),
... T.Normalize(mean=(0.485, 0.456, 0.406), std=(0.229, 0.224, 0.225)),
... ])
>>> image = lucid.rand(3, 300, 400) # (C, H, W)
>>> y = tf(image)
>>> y.shape
(3, 224, 224)
Classes
BboxParamsBounding-box handling policy for Compose (Albumentations-style).
Compose4 methodsChain transforms into one callable (works on tensors or samples).
GeometricTransformSpatial transform — must move masks, boxes, and keypoints.
PhotometricTransformColour / intensity transform — non-image targets pass through.
Transform3 methodsAbstract base for a transform parameterized by its sample-params P.
BoundingBoxesWraps (N, 4) bounding boxes with a format + canvas size.
ImageWraps a pixel image tensor (C, H, W) or (B, C, H, W).
KeypointsWraps (N, D) keypoints (D >= 2; first two columns x, y).
MaskWraps a segmentation / label mask, resampled with nearest mode.
CenterCrop3 methodsCrop a centred height x width window (Albumentations CenterCrop).
HorizontalFlip3 methodsFlip left-right with probability p (Albumentations HorizontalFlip).
LongestMaxSize2 methodsScale so the longer side equals max_size (Albumentations LongestMaxSize).
ResizeShortestEdge3 methodsReference detection resize: shortest side to min_size, capped.
RandomCrop3 methodsCrop a random height x width window (Albumentations RandomCrop).
RandomResizedCrop3 methodsCrop a random area/aspect region then resize to height x width.
Resize3 methodsResize to an exact height x width (Albumentations Resize).
SmallestMaxSize2 methodsScale so the shorter side equals max_size (Albumentations SmallestMaxSize).
VerticalFlip3 methodsFlip top-bottom with probability p (Albumentations VerticalFlip).
Blur3 methodsBox (mean) blur with a random odd kernel size (Albumentations Blur).
Defocus3 methodsDisk-kernel (out-of-focus) blur (Albumentations Defocus).
Downscale3 methodsDownscale then upscale to lose high-frequency detail (Albumentations Downscale).
GaussianBlur3 methodsGaussian blur with random kernel size and sigma (Albumentations GaussianBlur).
GaussNoise3 methodsAdditive Gaussian noise (Albumentations GaussNoise).
ISONoise3 methodsCamera-sensor-like noise (Albumentations ISONoise, approximate).
MedianBlur3 methodsMedian filter with a random odd kernel (Albumentations MedianBlur).
MotionBlur3 methodsDirectional (linear streak) motion blur (Albumentations MotionBlur).
MultiplicativeNoise3 methodsMultiply pixel values by random noise (Albumentations MultiplicativeNoise).
ZoomBlur3 methodsRadial zoom blur via averaged centre-zoomed copies (Albumentations ZoomBlur).
OneOf4 methodsApply exactly one child, sampled by child-p weight (Albumentations OneOf).
OneOrOther4 methodsApply first with probability p else second (Albumentations OneOrOther).
ReplayCompose5 methodsCompose that records applied params for deterministic replay.
Sequential4 methodsApply all children in order, gated by p (Albumentations Sequential).
SomeOf4 methodsApply n randomly-chosen children (Albumentations SomeOf).
BBoxSafeRandomCrop4 methodsRandom crop guaranteed to contain every bounding box (Albumentations BBoxSafeRandomCrop).
Lambda3 methodsApply user callables per target type (Albumentations Lambda).
MaskDropout4 methodsDrop random mask label regions from image + mask (Albumentations MaskDropout).
RandomCropNearBBox4 methodsCrop a window around the first bounding box (Albumentations RandomCropNearBBox).
RandomSizedBBoxSafeCrop4 methodsBox-safe crop then resize to a fixed output size (Albumentations RandomSizedBBoxSafeCrop).
CLAHE3 methodsContrast-limited adaptive histogram equalization (Albumentations CLAHE).
ChannelDropout3 methodsReplace random channels with a constant fill value (Albumentations ChannelDropout).
ChannelShuffle3 methodsRandomly permute the RGB channel order (Albumentations ChannelShuffle).
Emboss3 methodsEmboss an image via a 3x3 directional gradient kernel (Albumentations Emboss).
Equalize3 methodsPer-channel histogram equalization (Albumentations Equalize).
FancyPCA3 methodsAlexNet-style PCA colour augmentation (Krizhevsky 2012, Albumentations FancyPCA).
HueSaturationValue3 methodsRandom hue / saturation / value shift (Albumentations HueSaturationValue).
InvertImg3 methodsInvert pixel intensities via 1 - img (Albumentations InvertImg).
PixelDropout3 methodsRandomly set individual pixels to a fill value (Albumentations PixelDropout).
Posterize3 methodsReduce bits per channel (Albumentations Posterize).
RandomBrightness3 methodsRandomly perturb brightness only (Albumentations RandomBrightness).
RandomBrightnessContrast3 methodsRandomly perturb brightness and contrast jointly (Albumentations RandomBrightnessContrast).
RandomContrast3 methodsRandomly perturb contrast only (Albumentations RandomContrast).
RandomGamma3 methodsRandom gamma correction (Albumentations RandomGamma).
RandomToneCurve3 methodsApply a random S-shaped tone curve around midtones (Albumentations RandomToneCurve).
RGBShift3 methodsAdd per-channel additive shifts to an RGB image (Albumentations RGBShift).
RingingOvershoot3 methodsSimulate ringing / overshoot artefacts via a high-pass kernel (Albumentations RingingOvershoot).
Sharpen3 methodsSharpen an image via a 3x3 unsharp kernel blend (Albumentations Sharpen).
Solarize3 methodsInvert pixel intensities above a threshold (Albumentations Solarize).
ToGray3 methodsConvert an RGB image to grayscale while keeping 3 channels (Albumentations ToGray).
ToSepia3 methodsApply the canonical sepia-tone colour matrix (Albumentations ToSepia).
UnsharpMask3 methodsUnsharp-mask sharpen via img + alpha*(img - blur) (Albumentations UnsharpMask).
XYMasking3 methodsMask random horizontal and vertical bands of the image (Albumentations XYMasking).
Crop3 methodsCrop a fixed region [x_min, y_min, x_max, y_max) (Albumentations Crop).
CropAndPad3 methodsCrop (negative) or pad (positive) every side by px pixels.
PadIfNeeded3 methodsPad to at least min_height x min_width (Albumentations PadIfNeeded).
RandomSizedCrop3 methodsRandom-size crop then resize (Albumentations RandomSizedCrop).
ElasticTransform3 methodsElastic deformation (Simard 2003; Albumentations ElasticTransform).
GridDistortion3 methodsGrid distortion (Albumentations GridDistortion).
GridElasticDeform3 methodsGrid-based elastic deformation (Albumentations GridElasticDeform).
OpticalDistortion3 methodsRadial (barrel / pincushion) distortion (Albumentations OpticalDistortion).
AutoAugment3 methodsAutoAugment (Cubuk et al., 2019 — arXiv:1805.09501).
RandAugment3 methodsRandAugment (Cubuk et al., 2020 — arXiv:1909.13719).
TrivialAugmentWide3 methodsTrivial Augment Wide (Müller & Hutter, 2021 — arXiv:2103.10158).
CoarseDropout3 methodsDrop several random rectangles (Albumentations CoarseDropout).
GridDropout3 methodsDrop a regular grid of squares (Albumentations GridDropout).
RandomErasing3 methodsErase a random rectangular region of the image (Zhong et al., 2017).
Interpolation1 methodsResampling mode for resize-style transforms.
ColorJitter3 methodsRandomly jitter brightness/contrast/saturation/hue.
FromFloat3 methodsScale a [0, 1] image back up by max_value (Albumentations FromFloat).
Normalize3 methodsNormalize an image (Albumentations Normalize).
ToFloat3 methodsScale an integer-range image to [0, 1] (Albumentations ToFloat).
AutoTransformsPreset2 methodsResolver mirroring Hugging Face's AutoImageProcessor.
Detection4 methodsObject-detection preset — coordinates ride with the image.
ImageClassification1 methodsStandard ImageNet classification inference preset.
ImageClassificationAugment1 methodsStandard ImageNet classification training preset (augmentation).
VideoClassification1 methodsInference preset for a decoded video clip.
Pose1 methodsKeypoint / pose-estimation preset.
Segmentation1 methodsSemantic-segmentation preset — image + mask share geometry.
TransformsPreset5 methodsAbstract base for task-specific preprocessing presets.
Affine3 methodsGeneral affine: scale / translate / rotate / shear (Albumentations Affine).
D43 methodsRandom element of the dihedral group D4 (Albumentations D4).
Flip3 methodsFlip around a random axis (Albumentations Flip).
Perspective3 methodsRandom four-point perspective warp (Albumentations Perspective).
RandomGridShuffle3 methodsSplit into a grid and shuffle the cells (Albumentations RandomGridShuffle).
RandomRotate903 methodsRotate by a random multiple of 90° (Albumentations RandomRotate90).
RandomScale3 methodsResize by a random factor, aspect preserved (Albumentations RandomScale).
Rotate3 methodsRotate by a random angle in [-limit, limit] (Albumentations Rotate).
SafeRotate2 methodsRotate by a random angle, expanding the canvas to keep all content (Albumentations SafeRotate).
ShiftScaleRotate3 methodsRandom shift + scale + rotation (Albumentations ShiftScaleRotate).
Transpose3 methodsSwap the H and W axes with probability p (Albumentations Transpose).