当前位置:文档之家› matlab实现RGB转换成LUV

matlab实现RGB转换成LUV

function LUV = rgb2luv( Image )
%RGB转换成LUV
%输入为RGB的图像,输出为LUV图像,原理见https://www.doczj.com/doc/a610474333.html,/view/7f47ee116edb6f1aff001f7d.html
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 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);
XYZ(:,:,1) = T(1)*R + T(4)*G + T(7)*B; % X
XYZ(:,:,2) = T(2)*R + T(5)*G + T(8)*B; % Y
XYZ(:,:,3) = T(3)*R + T(6)*G + T(9)*B; % Z
return;

function fY = f(Y)
fY = real(Y.^(1/3));
i = (Y < 0.008856);
fY(i) = Y(i)*(841/108) + (4/29);
return;






相关主题
相关文档 最新文档