Skip to content

Instantly share code, notes, and snippets.

@bombless
Created December 14, 2012 16:10
Show Gist options
  • Save bombless/4286560 to your computer and use it in GitHub Desktop.
Save bombless/4286560 to your computer and use it in GitHub Desktop.
Python YUV2RGB & RGB2YUV
def RGB2YUV(input):
(R, G, B) = input
Y = int(0.299 * R + 0.587 * G + 0.114 * B)
U = int(-0.147 * R + -0.289 * G + 0.436 * B)
V = int(0.615 * R + -0.515 * G + -0.100 * B)
return (Y, U, V)
def YUV2RGB(input):
(Y, U, V) = input
R = int(Y + 1.14 * V)
G = int(Y - 0.39 * U - 0.58 * V)
B = int(Y + 2.03 * U)
return (R, G, B)
print YUV2RGB((73,186,154))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment