Skip to content

Instantly share code, notes, and snippets.

@celoyd
Last active July 27, 2016 07:48
Show Gist options
  • Save celoyd/210b7b3501389fcb6836e4d81c8838ef to your computer and use it in GitHub Desktop.
Save celoyd/210b7b3501389fcb6836e4d81c8838ef to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# simple visualization of the Cb/Cr plane of an image
from skimage import io
import numpy as np
from sys import argv
src = io.imread(argv[1])
print src.shape
R, G, B = src[:,:,0], src[:,:,1], src[:,:,2]
Y = (0.299 * R) + (0.587 * G) + (0.114 * B)
Cb = (-0.169 * R) - (0.331 * G) + (0.499 * B) + 128
Cr = (0.499 * R) - (0.418 * G) - (0.0813 * B) + 128
# traditional vectorscope orientation:
Cr = 256 - Cr
dst = np.zeros((256, 256), dtype=np.uint16)
for x in range(src.shape[0]):
for y in range(src.shape[1]):
dst[int(Cr[x, y]), int(Cb[x, y])] += 1
io.imsave(argv[2], dst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment