Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on.You've got this!
Flipping Images
Flipping creates mirror images. It is simple, fast, and one of the most common data augmentation techniques used to increase training data diversity.
6 min•By Priygop Team•Updated 2026
Flipping with cv2.flip()
Flipping with cv2.flip()
import cv2
image = cv2.imread("photo.jpg")
# Flip codes:
# 1 = horizontal flip (left-right mirror)
# 0 = vertical flip (upside down)
# -1 = both horizontal and vertical
horizontal = cv2.flip(image, 1) # Mirror left-right
vertical = cv2.flip(image, 0) # Flip upside down
both = cv2.flip(image, -1) # Rotate 180 degrees
cv2.imwrite("flip_horizontal.jpg", horizontal)
cv2.imwrite("flip_vertical.jpg", vertical)
cv2.imwrite("flip_both.jpg", both)
print("Flip operations complete")
# Data augmentation example:
# Flipping effectively doubles your training data
def augment_image(image):
"""Create augmented versions of an image."""
augmented = [image]
augmented.append(cv2.flip(image, 1)) # Horizontal flip
augmented.append(cv2.flip(image, 0)) # Vertical flip
return augmented
augmented_set = augment_image(image)
print(f"Original: 1 image → Augmented: {len(augmented_set)} images")Diagram
Loading diagram…
Machine Learning follows a structured pipeline from data to deployment