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

我根据//blog.csdn.net/kit_147/article/details/5485470(我无权发链接所以把前面的http:删掉了)中原理编写了RGB到LUV的matlab代码,但是最后算出的值不对,RGB=(255,255,255),算出来的L=64,正确应该是100才对呀,请大侠帮忙看看!!!!

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
    评论

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

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值