Table of Contents

Class HorizontalFlip<T>

Namespace
AiDotNet.Augmentation.Image
Assembly
AiDotNet.dll

Flips an image horizontally (left-right mirror).

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

Type Parameters

T

The numeric type for calculations.

Inheritance
HorizontalFlip<T>
Implements
Inherited Members

Remarks

Horizontal flipping mirrors the image along its vertical center axis, swapping the left and right sides. This is one of the most commonly used augmentations because many objects look the same when flipped horizontally (e.g., cars, animals, faces in frontal view).

For Beginners: Think of this like looking in a mirror. The left side of the image becomes the right side, and vice versa. This is useful when training image classifiers because a cat is still a cat whether it's facing left or right.

When to use:

  • Image classification where horizontal orientation doesn't matter
  • Object detection (boxes will be flipped automatically)
  • Pose estimation (keypoints will be swapped correctly)

When NOT to use:

  • Text recognition (text would become unreadable when mirrored)
  • Reading direction matters (left-to-right vs right-to-left)
  • Asymmetric objects where orientation is meaningful (e.g., traffic signs with arrows)

Constructors

HorizontalFlip(double)

Creates a new horizontal flip augmentation.

public HorizontalFlip(double probability = 0.5)

Parameters

probability double

The probability of applying this augmentation (0.0 to 1.0). Industry standard default is 0.5 (50% chance of flipping each image).

Remarks

For Beginners: A probability of 0.5 means each image has a 50-50 chance of being flipped. This creates good variety in your training data.

Methods

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

Applies the horizontal flip 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 horizontal flip.

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 horizontal flip.

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>

Remarks

Handles both normalized coordinates (0.0-1.0) and absolute pixel coordinates.

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

Transforms a segmentation mask after horizontal flip.

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>