opencv raw转rgb,在OpenCV中转换Lab值到RGB值

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.

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. See function color_Lab_to_LinearRGB and 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;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值