Demo entry 6363479

rgb2luv

   

Submitted by anonymous on May 13, 2017 at 18:03
Language: Matlab. Code size: 660 Bytes.

function LUV = rgb2luv(pic)
pic=imread('pic1.jpg');
pic=double(pic);
f=(1/0.17697)*[0.49,0.31,0.2;0.17697,0.81240,0.01063;0,0.01,0.99];
R=pic(:,:,1);
G=pic(:,:,2);
B=pic(:,:,3);
XYZ(:,:,1)=f(1)*R+f(4)*G+f(7)*B;
XYZ(:,:,2)=f(2)*R+f(5)*G+f(8)*B;
XYZ(:,:,3)=f(3)*R+f(6)*G+f(9)*B;
w=[0.950456,1,1.088754];
U1=(4*w(1))./(w(1)+15*w(2)+3*w(3));
V1=(9*w(1))./(w(1)+15*w(2)+3*w(3));
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)/w(2);
if(Y>0.0089)
    L=116*(Y.^(1/3))-16;
else
    L=903.3*Y;
end;
LUV(:,:,1)=L;
LUV(:,:,2)=13*L.*(U-U1);
LUV(:,:,3)=13*L.*(V-V1);

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).