File talk:CIE CRI TCS SPDs.svg

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search

Source[edit]

% get CRI_TCS from the Korean institute linked in the CRI article (as of 2008)
TCS=textread('CRI_TCS.csv', '', 'delimiter', ',', 'emptyvalue', NaN);

[X,Y,Z]=tristimulus(TCS(:,2:end),TCS(:,1));
M=max([X Y Z]);
srgb=applycform(cat(3,X/M,Y/M,Z/M),makecform('xyz2srgb'));
set(gcf,'DefaultAxesColorOrder',reshape(srgb,15,3));

% the first column contains the wavelengths (in nm)
plot(repmat(TCS(:,1),[1 8]), TCS(:,2:9));
legend(strcat([repmat('TCS',[8 1]) ('0'+(1:8))']))
axis([360 830 0 .8]);

Tristimulus[edit]

function [X,Y,Z]=tristimulus(SPD,L)

[LAMBDA, XFCN, YFCN, ZFCN]=colorMatchFcn('1931_full');
SPDnew=interp1(L,SPD,LAMBDA,'spline'); % upsample SPD

% trapezoidal integration, as discussed in appendix 2 of Schanda's book

if isvector(SPD)
    X=trapz(SPDnew.*XFCN);
    Y=trapz(SPDnew.*YFCN);
    Z=trapz(SPDnew.*ZFCN);
else
    X=trapz(SPDnew.*repmat(XFCN',1,size(SPD,2)));
    Y=trapz(SPDnew.*repmat(YFCN',1,size(SPD,2)));
    Z=trapz(SPDnew.*repmat(ZFCN',1,size(SPD,2)));
end