0
0
Computer Visionml~5 mins

Why augmentation multiplies training data in Computer Vision

Choose your learning style9 modes available
Introduction
Augmentation creates new versions of images by changing them slightly. This helps the model learn better by seeing more varied examples without needing more real pictures.
When you have a small number of images but want to train a strong model.
When you want your model to recognize objects from different angles or lighting.
When you want to reduce overfitting by making the training data more diverse.
When collecting new images is expensive or time-consuming.
When you want to improve model performance on real-world variations.
Syntax
Computer Vision
augmented_image = augmentation_function(original_image)

# Example augmentations:
# rotated_image = rotate(original_image, angle)
# flipped_image = flip(original_image, direction)
# bright_image = change_brightness(original_image, factor)
Augmentation functions take an image and return a changed version of it.
You can apply multiple augmentations to create many new images.
Examples
Rotate the image by 15 degrees to create a new training example.
Computer Vision
rotated_image = rotate(original_image, 15)
Flip the image horizontally to simulate a mirror image.
Computer Vision
flipped_image = flip(original_image, 'horizontal')
Increase brightness by 20% to simulate different lighting.
Computer Vision
bright_image = change_brightness(original_image, 1.2)
Create four rotated versions of the image at different angles.
Computer Vision
augmented_images = [rotate(img, angle) for angle in [0, 90, 180, 270]]
Sample Model
This code creates one simple image and makes two new images by rotating and flipping it. It shows how augmentation multiplies the training data.
Computer Vision
import numpy as np
import cv2

# Create a simple black square image
original_image = np.zeros((100, 100, 3), dtype=np.uint8)
cv2.rectangle(original_image, (30, 30), (70, 70), (255, 255, 255), -1)

# Define augmentation functions
def rotate(image, angle):
    center = (image.shape[1] // 2, image.shape[0] // 2)
    matrix = cv2.getRotationMatrix2D(center, angle, 1.0)
    rotated = cv2.warpAffine(image, matrix, (image.shape[1], image.shape[0]))
    return rotated

def flip(image, direction):
    if direction == 'horizontal':
        return cv2.flip(image, 1)
    elif direction == 'vertical':
        return cv2.flip(image, 0)
    else:
        return image

# Apply augmentations
rotated_90 = rotate(original_image, 90)
flipped_h = flip(original_image, 'horizontal')

# Count total images
original_count = 1
augmented_count = 2

print(f"Original images: {original_count}")
print(f"Augmented images: {augmented_count}")
print(f"Total training images: {original_count + augmented_count}")
OutputSuccess
Important Notes
Augmentation does not create new real data but new views of existing data.
Too much augmentation can confuse the model if changes are unrealistic.
Common augmentations include rotation, flipping, scaling, and color changes.
Summary
Augmentation helps models learn better by showing more varied images.
It multiplies training data by creating new versions of existing images.
This technique is useful when real data is limited or costly to get.