Skip to content

Instantly share code, notes, and snippets.

@dgobbi
Created February 28, 2018 20:22
Show Gist options
  • Save dgobbi/5bdd6c60d50d1533943685202da3c5e8 to your computer and use it in GitHub Desktop.
Save dgobbi/5bdd6c60d50d1533943685202da3c5e8 to your computer and use it in GitHub Desktop.
import numpy
Kb = 0.114
Kr = 0.299
full = numpy.array([
[1.0, 0.0, 2.0*(1.0-Kr) ],
[1.0, -2.0*Kb*(1.0-Kb)/(1.0-Kr-Kb), -2.0*Kr*(1.0-Kr)/(1.0-Kr-Kb) ],
[1.0, 2.0*(1.0-Kb), 0.0 ]
])
print("YBR_FULL to RGB")
print(full)
print("RGB to YBR_FULL")
print(numpy.linalg.inv(full))
partial = numpy.array(full)
partial[:,0] *= 255.0/219.0;
partial[:,1] *= 255.0/224.0;
partial[:,2] *= 255.0/224.0;
print("YBR_PARTIAL to RGB")
print(partial)
print("RGB to YBR_PARTIAL")
print(numpy.linalg.inv(partial))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment