function [DE,RT,hm,Dt,Rot]=CIEDE2000(LABREF,LAB,K)
% DE2000 calculates colour difference between a reference and
sample
% using CIEDE2000 colour difference (as defined in Luo, Cui and
Rigg (2000))
%
% Input data can be single values or multiple values arranged in
columns
% LABREF can be a single value while LAB is a column
%
% Colour Engineering
Toolbox
% author: ?Phil
Green
% version: 1.1
% date: 17-01-2001
% modified: Zheng Yuanlin,
2010-08-23 %
% set the values of parametric weighting factors
KL,KC,KH
if nargin>2
if
length(K)>2
kL=K(1);kC=K(2);kH=K(3);
end
else
kL=1;kC=1;kH=1;
end
%___________________________________________________________________
L=LABREF(:,1);
a=LABREF(:,2);
b=LABREF(:,3);
C=(a.^2+b.^2).^0.5;
Ls=LAB(:,1);
as=LAB(:,2);
bs=LAB(:,3);
Cs=(as.^2+bs.^2).^0.5;
%find G and recompute a', C' and h'
Cm=(C+Cs)/2;
G=0.5*(1-(Cm.^7./(Cm.^7+25^7)).^0.5); %
a轴调整因子
a=(1+G).*a;
as=(1+G).*as;
C=(a.^2+b.^2).^0.5;
h=hue_angle(a,b);
Cs=(as.^2+bs.^2).^0.5;
hs=hue_angle(as,bs);
zcidx = (C.*Cs == 0);
%% find the mean chroma and hue for each reference/sample
pair
Cm=(C+Cs)/2; % 彩度平均值
%% 色相角平均值
% hm=hmean_GS(h,hs,C,Cs);
hm=(h+hs)/2;
hm=hm-360*(abs(h-hs)>360);
hm=hm+(hm<0)*360;
hm(zcidx)=h(zcidx)+hs(zcidx);
%% 色相角差
% Dh=angle_diff_GS(h,hs,C,Cs); Dh=hs-h;
Dh = Dh - 2*180* (Dh > 180 );
Dh = Dh + 2*180* (Dh < (-180) );
Dh(zcidx)=0;
%%
rad=pi/180;
DL=(L-Ls); %
亮度差
DC=Cs-C; % 彩度差
DH=2*((C.*Cs).^0.5).*sin(rad*(Dh)/2); % 色相差
% calculate T
T=1-0.17*cos(rad*(hm-30))+0.24*cos(rad*2*hm)+0.32*cos(rad*(3*hm+6))-0.2*cos(rad*(4*hm-63));
%权重因子 SL, SC, SH
SL=1+(0.015.*((L+Ls)./2-50).^2)./(20+((L+Ls)./2-50).^2).^0.5;
SC=1+0.045.*Cm;
SH=1+0.015.*Cm.*T;
Dt=30*exp(-(((hm-275)/25).^2));
RC=2.*((Cm.^7)./(Cm.^7+25.^7)).^.5;
RT=-sin(2*rad*Dt).*RC;
Rot=RT.*(DC./(SC.*kC)).*(DH./(SH.*kH)); % 调整项
DE=((DL./(SL.*kL)).^2+(DC./(SC.*kC)).^2+(DH./(SH.*kH)).^2+Rot).^0.5;
return