Table of Contents

Class Scale<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Scales an image by a random factor within a specified range.

public class Scale<T> : SpatialAugmentationBase<T, ImageTensor<T>>, ISpatialAugmentation<T, ImageTensor<T>>, IAugmentation<T, ImageTensor<T>>

Type Parameters

T

The numeric type for calculations.

Inheritance
Scale<T>
Implements
Inherited Members

Remarks

Scale randomly resizes the image by a factor sampled from the specified range. This simulates viewing objects from different distances, helping the model become robust to scale variations.

For Beginners: Think of this like zooming in or out on your camera. The same object photographed from closer or farther appears at different sizes. This augmentation teaches your model to recognize objects regardless of their size.

When to use:

  • Object detection where objects appear at various sizes
  • Image classification with variable-sized subjects
  • When training data lacks size diversity

Constructors

Scale(double, double, double, InterpolationMode, BorderMode, T?)

Creates a new scale augmentation.

public Scale(double minScale = 0.8, double maxScale = 1.2, double probability = 0.5, InterpolationMode interpolation = InterpolationMode.Bilinear, BorderMode borderMode = BorderMode.Reflect, T? borderValue = default)

Parameters

minScale double

The minimum scale factor. Values less than 1.0 zoom out, greater than 1.0 zoom in. Industry standard default is 0.8 (80% of original size).

maxScale double

The maximum scale factor. Industry standard default is 1.2 (120% of original size).

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.

interpolation InterpolationMode

The interpolation mode for sampling pixels. Industry standard default is Bilinear for smooth results.

borderMode BorderMode

How to fill pixels that fall outside the original image bounds. Industry standard default is Reflect.

borderValue T

The constant value to use when borderMode is Constant.

Properties

BorderMode

Gets the border mode when pixels fall outside the original image bounds.

public BorderMode BorderMode { get; }

Property Value

BorderMode

BorderValue

Gets the constant value used when BorderMode is Constant.

public T BorderValue { get; }

Property Value

T

Interpolation

Gets the interpolation mode for pixel sampling.

public InterpolationMode Interpolation { get; }

Property Value

InterpolationMode

MaxScale

Gets the maximum scale factor.

public double MaxScale { get; }

Property Value

double

MinScale

Gets the minimum scale factor.

public double MinScale { get; }

Property Value

double

Methods

ApplyWithTransformParams(ImageTensor<T>, AugmentationContext<T>)

Applies the scale transformation and returns transform parameters.

protected override (ImageTensor<T> data, IDictionary<string, object> parameters) ApplyWithTransformParams(ImageTensor<T> data, AugmentationContext<T> context)

Parameters

data ImageTensor<T>
context AugmentationContext<T>

Returns

(ImageTensor<T> data, IDictionary<string, object> parameters)

GetParameters()

Gets the parameters of this augmentation.

public override IDictionary<string, object> GetParameters()

Returns

IDictionary<string, object>

A dictionary of parameter names to values.

TransformBoundingBox(BoundingBox<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a bounding box after scaling.

protected override BoundingBox<T> TransformBoundingBox(BoundingBox<T> box, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

box BoundingBox<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

BoundingBox<T>

TransformKeypoint(Keypoint<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a keypoint after scaling.

protected override Keypoint<T> TransformKeypoint(Keypoint<T> keypoint, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

keypoint Keypoint<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

Keypoint<T>

TransformMask(SegmentationMask<T>, IDictionary<string, object>, AugmentationContext<T>)

Transforms a segmentation mask after scaling.

protected override SegmentationMask<T> TransformMask(SegmentationMask<T> mask, IDictionary<string, object> transformParams, AugmentationContext<T> context)

Parameters

mask SegmentationMask<T>
transformParams IDictionary<string, object>
context AugmentationContext<T>

Returns

SegmentationMask<T>