Created
June 29, 2015 05:44
-
-
Save ColtonPhillips/3441a8dc3fbf1e7eff7e to your computer and use it in GitHub Desktop.
Converts rgb to ycbcr (YUV - Luminance + Chromanance)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://www.picturetopeople.org/p2p/picture_to_people_colors.p2p/color_converter?color_space=RGB&color_channel1=0&color_channel2=0&color_channel3=0 | |
#https://msdn.microsoft.com/en-us/library/ff635643.aspx | |
#rgb range - [0,255] | |
#y range - [0,255] | |
#cb,cr range - [-128,127] | |
import sys | |
import time | |
#r = int(sys.argv[1]) | |
#g = int(sys.argv[2]) | |
#b = int(sys.argv[3]) | |
#print ("RGB: ", r, g, b) | |
#y = 0.299 * r + 0.587 * g + 0.114 * b | |
#cb = -0.168935 * r + -0.331665 * g + 0.50059 * b | |
#cr = 0.499813 * r + -0.418531 * g + -0.081282 * b | |
#y = int(y) | |
#cb = int(cb) | |
#cr = int(cr) | |
#print ("YCbCr: ", y, cb, cr) | |
for i in range(0,256): | |
for j in range(0,256): | |
for k in range(0,256): | |
r = i | |
g = j | |
b = k | |
y = 0.299 * r + 0.587 * g + 0.114 * b | |
cb = -0.168935 * r + -0.331665 * g + 0.50059 * b | |
cr = 0.499813 * r + -0.418531 * g + -0.081282 * b | |
y = int(y) | |
cb = int(cb) | |
cr = int(cr) | |
print ("rgb=>", r, g, b," ycbcr=>", y, cb, cr) | |
time.sleep(0.5) | |
if (y < 0 or y > 255 or cb < -128 or cb > 127 or cr < -128 or cb > 127): | |
print ("FAIL! YCbCr: ", y, cb, cr) # doesn't fail tho | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment