ResizeWithAspectRatio<T>
Models & Types · AiDotNet.Augmentation.Image
Resizes an image to fit within target dimensions while preserving the aspect ratio, then pads to reach the exact target size.
Inheritance: AugmentationBase<T, ImageTensor<T>> → ImageAugmenterBase<T> → ResizeWithAspectRatio<T>
For Beginners
If you have a wide 400x200 image and want 300x300 output, this first shrinks it to 300x150 (keeping proportions), then adds 75 pixels of padding top and bottom to reach 300x300. The image looks correct, just with borders.
How It Works
This combines resizing and padding in one step. First, the image is scaled so that it fits within the target dimensions without exceeding them. Then, padding is added to reach the exact target size. This ensures no distortion while producing a fixed-size output.
When to use:
- When model requires fixed input size but aspect ratio matters
- Object detection where distorted proportions would hurt accuracy
- YOLO-style preprocessing (letterbox resizing)
Constructors
| Constructor | Summary |
|---|---|
ResizeWithAspectRatio(int targetHeight, int targetWidth, InterpolationMode interpolation, PaddingMode padMode, double fillValue, double probability) |
Creates a new ResizeWithAspectRatio augmentation. |
ResizeWithAspectRatio(int targetSize, InterpolationMode interpolation, PaddingMode padMode, double fillValue, double probability) |
Creates a square ResizeWithAspectRatio augmentation. |
Properties
| Property | Summary |
|---|---|
InterpolationMode Interpolation { get; } |
Gets the interpolation mode used for resizing. |
PaddingMode PadMode { get; } |
Gets the padding mode for the fill areas. |
double FillValue { get; } |
Gets the fill value for constant padding. |
int TargetHeight { get; } |
Gets the target height. |
int TargetWidth { get; } |
Gets the target width. |
Methods
| Method | Summary |
|---|---|
IDictionary<string, object> GetParameters() |