CenterCropOrPad<T>

Models & Types · AiDotNet.Augmentation.Image

Crops or pads an image to reach the target size, centering the content.

Inheritance: AugmentationBase<T, ImageTensor<T>> → ImageAugmenterBase<T> → CenterCropOrPad<T>

For Beginners

This is a “smart resize” that doesn’t stretch your image. If the image is too big, it cuts away the edges. If too small, it adds borders. Either way, the original content stays centered in the output.

How It Works

CenterCropOrPad handles both cases: if the image is larger than the target, it center crops; if smaller, it center pads with the specified fill value. This ensures a fixed output size regardless of input dimensions.

When to use:

  • When input images vary in size and you need fixed dimensions
  • When you want to avoid any scaling/interpolation artifacts
  • Evaluation/inference preprocessing

Constructors

Constructor Summary
CenterCropOrPad(int targetHeight, int targetWidth, double fillValue, double probability) Creates a new CenterCropOrPad augmentation.
CenterCropOrPad(int targetSize, double fillValue, double probability) Creates a square CenterCropOrPad.

Properties

Property Summary
double FillValue { get; } Gets the fill value for padding (when image is smaller than target).
int TargetHeight { get; } Gets the target height.
int TargetWidth { get; } Gets the target width.

Methods

Method Summary
IDictionary<string, object> GetParameters()