[英]Converting Lab Values to RGB values in opencv
I am trying to convert the Lab values to its corresponding RGB values.I don't want to convert Lab image to RGB image but some values of L a and b.The function cvCvtColor only works for images.Can anybody tell me how to do this. 我试图将Lab值转换为相应的RGB值。我不想将Lab图像转换为RGB图像,而是将L a和b的某些值转换。函数cvCvtColor仅适用于图像。任何人都可以告诉我该怎么做这个。
Thanks; 谢谢;
Code : 代码:
CvMat* rgb = cvCreateMat(centres->rows,centres->cols,centres->type);
cvCvtColor(centres,rgb,CV_Lab2BGR);
I don't know how to do it in OpenCV, but if something else is alright I've implemented it in C . 我不知道如何在OpenCV中做到这一点,但如果其他的东西没问题,我已经在C中实现了它 。 See function color_Lab_to_LinearRGB
and color_LinearRGB_to_RGB
. 请参阅函数color_Lab_to_LinearRGB
和color_LinearRGB_to_RGB
。
Here's the code: 这是代码:
double L, a, b;
double X, Y, Z;
double R, G, B;
// Lab -> normalized XYZ (X,Y,Z are all in 0...1)
Y = L * (1.0/116.0) + 16.0/116.0;
X = a * (1.0/500.0) + Y;
Z = b * (-1.0/200.0) + Y;
X = X > 6.0/29.0 ? X * X * X : X * (108.0/841.0) - 432.0/24389.0;
Y = L > 8.0 ? Y * Y * Y : L * (27.0/24389.0);
Z = Z > 6.0/29.0 ? Z * Z * Z : Z * (108.0/841.0) - 432.0/24389.0;
// normalized XYZ -> linear sRGB (in 0...1)
R = X * (1219569.0/395920.0) + Y * (-608687.0/395920.0) + Z * (-107481.0/197960.0);
G = X * (-80960619.0/87888100.0) + Y * (82435961.0/43944050.0) + Z * (3976797.0/87888100.0);
B = X * (93813.0/1774030.0) + Y * (-180961.0/887015.0) + Z * (107481.0/93370.0);
// linear sRGB -> gamma-compressed sRGB (in 0...1)
R = R > 0.0031308 ? pow(R, 1.0 / 2.4) * 1.055 - 0.055 : R * 12.92;
G = G > 0.0031308 ? pow(G, 1.0 / 2.4) * 1.055 - 0.055 : G * 12.92;
B = B > 0.0031308 ? pow(B, 1.0 / 2.4) * 1.055 - 0.055 : B * 12.92;
I think the only way to do what you want is: 我认为做你想做的事的唯一方法是:
cvCvtColor
around that. 创建一个虚拟图像,其中包含您想要转换的少量Lab值(比如1乘n乘3,其中n是要转换的值的数量),并使用cvCvtColor
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.