# matlab rgb转luv,RGB到LUV的转换，最后的L值不对

1.RGB到XYZ

function XYZ = rgb2xyz( Image )

% Convert RGB to XYZ

T = (1/0.17697)*[0.49, 0.31, 0.20; 0.17697, 0.81240, 0.01063; 0.00, 0.01, 0.99];

R = Image(:,:,1);

G = Image(:,:,2);

B = Image(:,:,3);

X = T(1)*R + T(4)*G + T(7)*B;

X = double(X);

Y = T(2)*R + T(5)*G + T(8)*B;

Y = double(Y);

Z = T(3)*R + T(6)*G + T(9)*B;

Z = double(Z);

XYZ(:,:,1) = X./(X+Y+Z);  % X

XYZ(:,:,2) = Y./(X+Y+Z);  % Y

XYZ(:,:,3) = Z./(X+Y+Z); % Z

end

2.XYZ到RGB

function LUV = rgb2luv( Image )

%RGB转换成LUV

%输入为RGB的图像，输出为LUV图像，原理见

Image = double(Image);

WhitePoint = [0.950456,1,1.088754];

WhitePointU = (4*WhitePoint(1))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); %Un'

WhitePointV = (9*WhitePoint(2))./(WhitePoint(1) + 15*WhitePoint(2) + 3*WhitePoint(3)); %Vn'

XYZ = rgb2xyz(Image); % Convert to XYZ

U = (4*XYZ(:,:,1))./(XYZ(:,:,1) + 15*XYZ(:,:,2) + 3*XYZ(:,:,3));

V = (9*XYZ(:,:,2))./(XYZ(:,:,1) + 15*XYZ(:,:,2) + 3*XYZ(:,:,3));

Y = XYZ(:,:,2)/WhitePoint(2);   %Y/Yn

L = 116*f(Y) - 16;

LUV(:,:,1) = L;                        % L*

LUV(:,:,2) = 13*L.*(U - WhitePointU);  % u*

LUV(:,:,3) = 13*L.*(V - WhitePointV);  % v*

return;

function fY = f(Y)

fY = real(Y.^(1/3));

i = (Y < 0.008856);

fY(i) = Y(i)*(841/108) + (4/29);

return;

• 0
点赞
• 0
收藏
• 0
评论
11-25
07-07 6990
04-25 1266
12-28 4264
09-21
06-25 5889
03-19 4715
12-03 2万+
08-16 836
11-07 1700
06-10 3730
08-16 7069
05-05 2023

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

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