rgb2lab代码转换
来源:互联网 发布:高思网络课程 编辑:程序博客网 时间:2024/05/19 00:10
另外一个例子,来自:http://users.rsise.anu.edu.au/~luke/cvcourse_files/labs/RGB2Lab.m
function [L,a,b] = RGB2Lab1(R,G,B)
% function [L, a, b] = RGB2Lab(R, G, B)
% RGB2Lab takes matrices corresponding to Red, Green, and Blue, and
% transforms them into CIELab. This transform is based on ITU-R
% Recommendation BT.709 using the D65 white point reference.
% The error in transforming RGB -> Lab -> RGB is approximately
% 10^-5. RGB values can be either between 0 and 1 or between 0 and 255.
% By Mark Ruzon from C code by Yossi Rubner, 23 September 1997.
% Updated for MATLAB 5 28 January 1998.
if (nargin == 1)
B = double(R(:,:,3));
G = double(R(:,:,2));
R = double(R(:,:,1));
end
if ((max(max(R)) > 1.0) | (max(max(G)) > 1.0) | (max(max(B)) > 1.0))
R = R/255;
G = G/255;
B = B/255;
end
[M, N] = size(R);
s = M*N;
% Set a threshold
T = 0.008856;
RGB = [reshape(R,1,s); reshape(G,1,s); reshape(B,1,s)];
% RGB to XYZ
MAT = [0.412453 0.357580 0.180423;
0.212671 0.715160 0.072169;
0.019334 0.119193 0.950227];
XYZ = MAT * RGB;
X = XYZ(1,:) / 0.950456;
Y = XYZ(2,:);
Z = XYZ(3,:) / 1.088754;
XT = X > T;
YT = Y > T;
ZT = Z > T;
fX = XT .* X.^(1/3) + (~XT) .* (7.787 .* X + 16/116);
% Compute L
Y3 = Y.^(1/3);
fY = YT .* Y3 + (~YT) .* (7.787 .* Y + 16/116);
L = YT .* (116 * Y3 - 16.0) + (~YT) .* (903.3 * Y);
fZ = ZT .* Z.^(1/3) + (~ZT) .* (7.787 .* Z + 16/116);
% Compute a and b
a = 500 * (fX - fY);
b = 200 * (fY - fZ);
L = reshape(L, M, N);
a = reshape(a, M, N);
b = reshape(b, M, N);
if ((nargout == 1) | (nargout == 0))
L = cat(3,L,a,b);
end
function [L,a,b] = RGB2Lab1(R,G,B)
% function [L, a, b] = RGB2Lab(R, G, B)
% RGB2Lab takes matrices corresponding to Red, Green, and Blue, and
% transforms them into CIELab. This transform is based on ITU-R
% Recommendation BT.709 using the D65 white point reference.
% The error in transforming RGB -> Lab -> RGB is approximately
% 10^-5. RGB values can be either between 0 and 1 or between 0 and 255.
% By Mark Ruzon from C code by Yossi Rubner, 23 September 1997.
% Updated for MATLAB 5 28 January 1998.
if (nargin == 1)
B = double(R(:,:,3));
G = double(R(:,:,2));
R = double(R(:,:,1));
end
if ((max(max(R)) > 1.0) | (max(max(G)) > 1.0) | (max(max(B)) > 1.0))
R = R/255;
G = G/255;
B = B/255;
end
[M, N] = size(R);
s = M*N;
% Set a threshold
T = 0.008856;
RGB = [reshape(R,1,s); reshape(G,1,s); reshape(B,1,s)];
% RGB to XYZ
MAT = [0.412453 0.357580 0.180423;
0.212671 0.715160 0.072169;
0.019334 0.119193 0.950227];
XYZ = MAT * RGB;
X = XYZ(1,:) / 0.950456;
Y = XYZ(2,:);
Z = XYZ(3,:) / 1.088754;
XT = X > T;
YT = Y > T;
ZT = Z > T;
fX = XT .* X.^(1/3) + (~XT) .* (7.787 .* X + 16/116);
% Compute L
Y3 = Y.^(1/3);
fY = YT .* Y3 + (~YT) .* (7.787 .* Y + 16/116);
L = YT .* (116 * Y3 - 16.0) + (~YT) .* (903.3 * Y);
fZ = ZT .* Z.^(1/3) + (~ZT) .* (7.787 .* Z + 16/116);
% Compute a and b
a = 500 * (fX - fY);
b = 200 * (fY - fZ);
L = reshape(L, M, N);
a = reshape(a, M, N);
b = reshape(b, M, N);
if ((nargout == 1) | (nargout == 0))
L = cat(3,L,a,b);
end
- rgb2lab代码转换
- rgb2lab代码转换
- OpenCV RGB2LAB执行效率测试
- 代码转换
- 代码转换
- 代码页转换&简繁体转换
- 转换html代码子程序
- Constants 城市代码转换
- TradeConstant行业代码转换
- 图片转换代码
- 半角全角转换代码
- .NET代码转换工具
- 简繁体转换代码
- UBB代码转换函数
- .net代码转换
- TXL 代码语言转换
- 四元数转换矩阵代码
- 大小写转换代码
- delphi中single型数据向byte数组转换
- ActiveMQ in Action(2)
- 【商务英语】邮件中的感谢
- ActiveMQ in Action(3)
- ActiveMQ in Action(4)
- rgb2lab代码转换
- 唉,字体搞得鬼?
- [趣闻]Google 员工架飞索去总部蹭饭
- ActiveMQ in Action(5)
- GridView支持分页的自动编号代码
- 小故事中的哲理
- 我喜爱的男星—曾江
- ActiveMQ in Action(6)
- DB2联合数据库