How these scripts are tested
Every one of the 36 combinations is generated by the same code that runs on this page, executed by the site build with real Pillow, OpenCV, NumPy and PyTorch, and must print the known colour of one pixel of the sample photo: RGB (79, 55, 11), or (11, 55, 79) in OpenCV's BGR order. A swapped channel or a transposed axis fails the build.
The three bugs these conversions prevent
- Blue faces. OpenCV's
imreadreturns BGR.Image.fromarray(cv2_img)withoutcv2.cvtColor(..., cv2.COLOR_BGR2RGB)swaps red and blue. See Pillow and OpenCV. - Black or noisy images. Float arrays in 0–1 must be scaled and cast to
uint8;fromarrayon float64 raises Cannot handle this data type. - Sideways or scrambled tensors. PyTorch wants (C, H, W); NumPy and Pillow give (H, W, C). Use
permute, neverreshape.