Skip to content
AI360Xpert
Beta

Image Flipping

Flipping mirrors an image across an axis with no resampling, the cheapest augmentation for doubling orientation coverage in training data.

A horizontal flip reverses the column order of every row, mirroring the image left to right with no resampling.
A horizontal flip reverses the column order of every row, mirroring the image left to right with no resampling.

Why Does This Exist?

A cat facing left and the same cat facing right are the same cat, but a model trained only on left-facing cats may disagree. Flipping mirrors images across an axis, doubling orientation coverage at almost zero cost: no interpolation, no new pixels, no size change. It is the first augmentation in nearly every vision recipe, applied with 50 percent probability during training.

Unlike rotation, flipping is exact and lossless. The catch is semantic: some things stop being themselves when mirrored. This page covers the flip codes, the label bookkeeping, and when mirroring is wrong.

Think of It Like This

Holding a photo up to a mirror

Hold a print up to a mirror and left trades places with right while up stays up: that is a horizontal flip. Flip the print top to bottom instead and the sky lands under the ground. The mirror never blurs ink or changes the paper size; it only reorders positions.

The analogy stops at meaning. A mirror cannot tell text from texture, so it happily renders every word backwards. Your pipeline has to know which content survives mirroring and which does not.

How It Actually Works

Flip codes

cv2.flip(img, flipCode) mirrors along an axis: code 1 flips horizontally (left-right, around the vertical axis), code 0 flips vertically (up-down), and code -1 flips both, which equals a 180-degree turn. Concretely, the 2 by 3 block [[1,2,3],[4,5,6]][[1, 2, 3], [4, 5, 6]] flipped horizontally becomes [[3,2,1],[6,5,4]][[3, 2, 1], [6, 5, 4]]: each row reverses, rows stay in order. Because output pixels land exactly on grid positions, values are copied, never interpolated.

Labels mirror too

A box corner at xx in a width-WW image moves to W−1−xW - 1 - x after a horizontal flip; keypoint left-right pairs (eyes, hands) must additionally swap identities. Forgetting the swap trains a model that calls left eyes right. Masks and boxes flip with the same one-line transform as the image, so do it in the same function.

When not to flip

Horizontal flips are safe for natural scenes, animals, vehicles and most medical slices, but wrong for text and OCR (mirrored letters are different letters), digits like 6 versus 9 under vertical flips, and any task where direction carries the label, such as left-versus-right organ classification or arrow-sign recognition. Vertical flips are also unphysical for horizon-bound scenes: upside-down skies teach the model a world that never appears at test time.

Code

import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]], dtype=np.uint8)print(np.fliplr(a).tolist())  # same as cv2.flip(a, 1)# -> [[3, 2, 1], [6, 5, 4]]

Watch Out For

Mirrored text and directional labels

Flipping is label-preserving only when direction is irrelevant. The symptom is an OCR model that reads backwards or a classifier that confuses left and right indicators. Gate horizontal flips on content without text or chirality, and skip vertical flips for outdoor scenes.

Unswapped symmetric keypoints

After a horizontal flip, the left eye lands where the right eye was, but its index still says "left". The symptom is a pose model with crossed predictions on mirrored inputs. Swap symmetric keypoint pairs (and their visibility flags) as part of the flip.

The Quick Version

  • Flip codes: 1 horizontal, 0 vertical, -1 both; all exact, with no resampling.
  • Horizontal flips suit most natural images; vertical flips break horizon scenes.
  • Box xx becomes W−1−xW - 1 - x; symmetric keypoints must swap identities.
  • Never flip text, digits with chirality, or direction-labeled content.
  • Apply at 50 percent probability during training, never at validation.