[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ff-cvs] libvob/vob/color spaces.py
From: |
Janne V. Kujala |
Subject: |
[ff-cvs] libvob/vob/color spaces.py |
Date: |
Thu, 04 Sep 2003 08:47:05 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Branch:
Changes by: Janne V. Kujala <address@hidden> 03/09/04 08:47:04
Modified files:
vob/color : spaces.py
Log message:
use gamma correction with CIE XYZ conversions
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/vob/color/spaces.py.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
Patches:
Index: libvob/vob/color/spaces.py
diff -u libvob/vob/color/spaces.py:1.2 libvob/vob/color/spaces.py:1.3
--- libvob/vob/color/spaces.py:1.2 Mon Sep 1 10:03:36 2003
+++ libvob/vob/color/spaces.py Thu Sep 4 08:47:04 2003
@@ -25,10 +25,23 @@
import math
+# Gamma correction used with the perceptual non-linearity in
+# CIE XYZ and YtoL and LtoY conversion functions.
+#
+gamma = 2.2
+#
+# The uncorrected display gamma of PC's is typically 2.2, i.e.,
+# RGB values map to physical intensities with an exponent of 2.2.
+# So, gamma correction of 2.2 here should result in linear
+# intensity. (The CIE L* / Y computation assumes linear intensity).
+
def RGBtoXYZ(v):
mat = [[ 0.412453, 0.35758 , 0.180423],
[ 0.212671, 0.71516 , 0.072169],
[ 0.019334, 0.119193, 0.950227]];
+
+ v = ( v[0]**gamma, v[1]**gamma, v[2]**gamma )
+
return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
@@ -37,23 +50,41 @@
mat = [[ 3.240479,-1.53715 ,-0.498535],
[-0.969256, 1.875991, 0.041556],
[ 0.055648,-0.204043, 1.057311]];
- return [ mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2],
- mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2],
- mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2] ]
+ v = [ (mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2]),
+ (mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2]),
+ (mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2]) ]
+ return ( v[0]**(1/gamma), v[1]**(1/gamma), v[2]**(1/gamma) )
def RGBtoLAB(RGB):
XYZ = RGBtoXYZ(RGB)
XYZn = RGBtoXYZ([1,1,1])
- return [ -16 + 116 * pow(XYZ[1] / XYZn[1], 1./3),
- 500 * (pow(XYZ[0] / XYZn[0], 1./3.) - pow(XYZ[1] / XYZn[1],
1./3.)),
- 200 * (pow(XYZ[1] / XYZn[1], 1./3.) - pow(XYZ[2] / XYZn[2],
1./3.)) ]
+ X = XYZ[0] / XYZn[0]
+ Y = XYZ[1] / XYZn[1]
+ Z = XYZ[2] / XYZn[2]
+
+ if Y <= (216./24389):
+ L = Y * (24389./27)
+ else:
+ L = 116 * pow(Y, 1./3) - 16
+
+ return [ L,
+ 500 * (pow(X, 1./3.) - pow(Y, 1./3.)),
+ 200 * (pow(Y, 1./3.) - pow(Z, 1./3.)) ]
def LABtoRGB(LAB):
+ L = LAB[0]
+ if L <= 8:
+ Y3 = pow(L * (27./24389), 1/3.0)
+ else:
+ Y3 = (L + 16.0) / 116
+
XYZn = RGBtoXYZ([1,1,1])
- XYZ = [ XYZn[0] * pow((LAB[0] + 16.0) / 116 + LAB[1] / 500.0, 3),
- XYZn[1] * pow((LAB[0] + 16.0) / 116, 3),
- XYZn[2] * pow((LAB[0] + 16.0) / 116 - LAB[2] / 200.0, 3) ]
+ XYZ = [ XYZn[0] * pow(Y3 + LAB[1] / 500.0, 3),
+ XYZn[1] * pow(Y3, 3),
+ XYZn[2] * pow(Y3 - LAB[2] / 200.0, 3) ]
+
+
return XYZtoRGB(XYZ);
def LABhue(RGB):
@@ -154,16 +185,6 @@
Wb = 0.072169
#Wr,Wg,Wb = 0.3, 0.59, 0.11
-
-# Gamma correction used with the perceptual non-linearity in YtoL and LtoY
-# conversion functions.
-#
-gamma = 2.2
-#
-# The uncorrected display gamma of PC's is typically 2.2, i.e.,
-# RGB values map to physical intensities with an exponent of 2.2.
-# So, gamma correction of 2.2 here should result in linear
-# intensity. (The CIE L* computation assumes linear intensity).
def YSTtoRGB(v):
n = 1.0 / (Wr+Wg+Wb)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [ff-cvs] libvob/vob/color spaces.py,
Janne V. Kujala <=