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
TThe numeric type for calculations.
- Inheritance
-
AugmentationBase<T, ImageTensor<T>>Scale<T>
- Implements
-
ISpatialAugmentation<T, ImageTensor<T>>IAugmentation<T, ImageTensor<T>>
- 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
minScaledoubleThe 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).
maxScaledoubleThe maximum scale factor. Industry standard default is 1.2 (120% of original size).
probabilitydoubleThe probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5.
interpolationInterpolationModeThe interpolation mode for sampling pixels. Industry standard default is Bilinear for smooth results.
borderModeBorderModeHow to fill pixels that fall outside the original image bounds. Industry standard default is Reflect.
borderValueTThe 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
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
MaxScale
Gets the maximum scale factor.
public double MaxScale { get; }
Property Value
MinScale
Gets the minimum scale factor.
public double MinScale { get; }
Property Value
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
dataImageTensor<T>contextAugmentationContext<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
boxBoundingBox<T>transformParamsIDictionary<string, object>contextAugmentationContext<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
keypointKeypoint<T>transformParamsIDictionary<string, object>contextAugmentationContext<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
maskSegmentationMask<T>transformParamsIDictionary<string, object>contextAugmentationContext<T>