Skip to content
module

transforms

99 members
lucid.utils.transforms

lucid.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 — Compose a list of Transform objects. Each is applied with probability p and 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

dataBboxParams

Bounding-box handling policy for Compose (Albumentations-style).

classCompose4 methods

Chain transforms into one callable (works on tensors or samples).

abstractGeometricTransform

Spatial transform — must move masks, boxes, and keypoints.

abstractPhotometricTransform

Colour / intensity transform — non-image targets pass through.

abstractTransform3 methods

Abstract base for a transform parameterized by its sample-params P.

dataBoundingBoxes

Wraps (N, 4) bounding boxes with a format + canvas size.

dataImage

Wraps a pixel image tensor (C, H, W) or (B, C, H, W).

dataKeypoints

Wraps (N, D) keypoints (D >= 2; first two columns x, y).

dataMask

Wraps a segmentation / label mask, resampled with nearest mode.

classCenterCrop3 methods

Crop a centred height x width window (Albumentations CenterCrop).

classHorizontalFlip3 methods

Flip left-right with probability p (Albumentations HorizontalFlip).

classLongestMaxSize2 methods

Scale so the longer side equals max_size (Albumentations LongestMaxSize).

classResizeShortestEdge3 methods

Reference detection resize: shortest side to min_size, capped.

classRandomCrop3 methods

Crop a random height x width window (Albumentations RandomCrop).

classRandomResizedCrop3 methods

Crop a random area/aspect region then resize to height x width.

classResize3 methods

Resize to an exact height x width (Albumentations Resize).

classSmallestMaxSize2 methods

Scale so the shorter side equals max_size (Albumentations SmallestMaxSize).

classVerticalFlip3 methods

Flip top-bottom with probability p (Albumentations VerticalFlip).

classBlur3 methods

Box (mean) blur with a random odd kernel size (Albumentations Blur).

classDefocus3 methods

Disk-kernel (out-of-focus) blur (Albumentations Defocus).

classDownscale3 methods

Downscale then upscale to lose high-frequency detail (Albumentations Downscale).

classGaussianBlur3 methods

Gaussian blur with random kernel size and sigma (Albumentations GaussianBlur).

classGaussNoise3 methods

Additive Gaussian noise (Albumentations GaussNoise).

classISONoise3 methods

Camera-sensor-like noise (Albumentations ISONoise, approximate).

classMedianBlur3 methods

Median filter with a random odd kernel (Albumentations MedianBlur).

classMotionBlur3 methods

Directional (linear streak) motion blur (Albumentations MotionBlur).

classMultiplicativeNoise3 methods

Multiply pixel values by random noise (Albumentations MultiplicativeNoise).

classZoomBlur3 methods

Radial zoom blur via averaged centre-zoomed copies (Albumentations ZoomBlur).

classOneOf4 methods

Apply exactly one child, sampled by child-p weight (Albumentations OneOf).

classOneOrOther4 methods

Apply first with probability p else second (Albumentations OneOrOther).

classReplayCompose5 methods

Compose that records applied params for deterministic replay.

classSequential4 methods

Apply all children in order, gated by p (Albumentations Sequential).

classSomeOf4 methods

Apply n randomly-chosen children (Albumentations SomeOf).

classBBoxSafeRandomCrop4 methods

Random crop guaranteed to contain every bounding box (Albumentations BBoxSafeRandomCrop).

classLambda3 methods

Apply user callables per target type (Albumentations Lambda).

classMaskDropout4 methods

Drop random mask label regions from image + mask (Albumentations MaskDropout).

classRandomCropNearBBox4 methods

Crop a window around the first bounding box (Albumentations RandomCropNearBBox).

classRandomSizedBBoxSafeCrop4 methods

Box-safe crop then resize to a fixed output size (Albumentations RandomSizedBBoxSafeCrop).

classCLAHE3 methods

Contrast-limited adaptive histogram equalization (Albumentations CLAHE).

classChannelDropout3 methods

Replace random channels with a constant fill value (Albumentations ChannelDropout).

classChannelShuffle3 methods

Randomly permute the RGB channel order (Albumentations ChannelShuffle).

classEmboss3 methods

Emboss an image via a 3x3 directional gradient kernel (Albumentations Emboss).

classEqualize3 methods

Per-channel histogram equalization (Albumentations Equalize).

classFancyPCA3 methods

AlexNet-style PCA colour augmentation (Krizhevsky 2012, Albumentations FancyPCA).

classHueSaturationValue3 methods

Random hue / saturation / value shift (Albumentations HueSaturationValue).

classInvertImg3 methods

Invert pixel intensities via 1 - img (Albumentations InvertImg).

classPixelDropout3 methods

Randomly set individual pixels to a fill value (Albumentations PixelDropout).

classPosterize3 methods

Reduce bits per channel (Albumentations Posterize).

classRandomBrightness3 methods

Randomly perturb brightness only (Albumentations RandomBrightness).

classRandomBrightnessContrast3 methods

Randomly perturb brightness and contrast jointly (Albumentations RandomBrightnessContrast).

classRandomContrast3 methods

Randomly perturb contrast only (Albumentations RandomContrast).

classRandomGamma3 methods

Random gamma correction (Albumentations RandomGamma).

classRandomToneCurve3 methods

Apply a random S-shaped tone curve around midtones (Albumentations RandomToneCurve).

classRGBShift3 methods

Add per-channel additive shifts to an RGB image (Albumentations RGBShift).

classRingingOvershoot3 methods

Simulate ringing / overshoot artefacts via a high-pass kernel (Albumentations RingingOvershoot).

classSharpen3 methods

Sharpen an image via a 3x3 unsharp kernel blend (Albumentations Sharpen).

classSolarize3 methods

Invert pixel intensities above a threshold (Albumentations Solarize).

classToGray3 methods

Convert an RGB image to grayscale while keeping 3 channels (Albumentations ToGray).

classToSepia3 methods

Apply the canonical sepia-tone colour matrix (Albumentations ToSepia).

classUnsharpMask3 methods

Unsharp-mask sharpen via img + alpha*(img - blur) (Albumentations UnsharpMask).

classXYMasking3 methods

Mask random horizontal and vertical bands of the image (Albumentations XYMasking).

classCrop3 methods

Crop a fixed region [x_min, y_min, x_max, y_max) (Albumentations Crop).

classCropAndPad3 methods

Crop (negative) or pad (positive) every side by px pixels.

classPadIfNeeded3 methods

Pad to at least min_height x min_width (Albumentations PadIfNeeded).

classRandomSizedCrop3 methods

Random-size crop then resize (Albumentations RandomSizedCrop).

classElasticTransform3 methods

Elastic deformation (Simard 2003; Albumentations ElasticTransform).

classGridDistortion3 methods

Grid distortion (Albumentations GridDistortion).

classGridElasticDeform3 methods

Grid-based elastic deformation (Albumentations GridElasticDeform).

classOpticalDistortion3 methods

Radial (barrel / pincushion) distortion (Albumentations OpticalDistortion).

classAutoAugment3 methods

AutoAugment (Cubuk et al., 2019 — arXiv:1805.09501).

classRandAugment3 methods

RandAugment (Cubuk et al., 2020 — arXiv:1909.13719).

classTrivialAugmentWide3 methods

Trivial Augment Wide (Müller & Hutter, 2021 — arXiv:2103.10158).

classCoarseDropout3 methods

Drop several random rectangles (Albumentations CoarseDropout).

classGridDropout3 methods

Drop a regular grid of squares (Albumentations GridDropout).

classRandomErasing3 methods

Erase a random rectangular region of the image (Zhong et al., 2017).

classInterpolation1 methods

Resampling mode for resize-style transforms.

classColorJitter3 methods

Randomly jitter brightness/contrast/saturation/hue.

classFromFloat3 methods

Scale a [0, 1] image back up by max_value (Albumentations FromFloat).

classNormalize3 methods

Normalize an image (Albumentations Normalize).

classToFloat3 methods

Scale an integer-range image to [0, 1] (Albumentations ToFloat).

classAutoTransformsPreset2 methods

Resolver mirroring Hugging Face's AutoImageProcessor.

classDetection4 methods

Object-detection preset — coordinates ride with the image.

classImageClassification1 methods

Standard ImageNet classification inference preset.

classImageClassificationAugment1 methods

Standard ImageNet classification training preset (augmentation).

classVideoClassification1 methods

Inference preset for a decoded video clip.

classPose1 methods

Keypoint / pose-estimation preset.

classSegmentation1 methods

Semantic-segmentation preset — image + mask share geometry.

abstractTransformsPreset5 methods

Abstract base for task-specific preprocessing presets.

classAffine3 methods

General affine: scale / translate / rotate / shear (Albumentations Affine).

classD43 methods

Random element of the dihedral group D4 (Albumentations D4).

classFlip3 methods

Flip around a random axis (Albumentations Flip).

classPerspective3 methods

Random four-point perspective warp (Albumentations Perspective).

classRandomGridShuffle3 methods

Split into a grid and shuffle the cells (Albumentations RandomGridShuffle).

classRandomRotate903 methods

Rotate by a random multiple of 90° (Albumentations RandomRotate90).

classRandomScale3 methods

Resize by a random factor, aspect preserved (Albumentations RandomScale).

classRotate3 methods

Rotate by a random angle in [-limit, limit] (Albumentations Rotate).

classSafeRotate2 methods

Rotate by a random angle, expanding the canvas to keep all content (Albumentations SafeRotate).

classShiftScaleRotate3 methods

Random shift + scale + rotation (Albumentations ShiftScaleRotate).

classTranspose3 methods

Swap the H and W axes with probability p (Albumentations Transpose).