startcol

% Especificacion de los primarios del sistema del monitor en XYZ
% y matriz de cambio de base XYZ->RGBmon
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Coordenadas cromaticas y luminancia (unidades tricromaticas) de los
% primarios (Medidas experimentales)

tP1=[0.59 0.37 24.05];
tP2=[0.27 0.62 79.44];
tP3=[0.15 0.09 17];

% Valores triestimulo de los primarios

TP1=coor2tri(tP1,Yw);
TP2=coor2tri(tP2,Yw);
TP3=coor2tri(tP3,Yw);

% Matriz de cambio al sistema RGB del monitor y nuevas constantes 

[M12,Yw2]=chngmtx([TP1;TP2;TP3],Yw,1);
[T_l2,Yw2,M2x]=newconst(M12,T_l,Yw,Msx);
[tm2,a2,g2]=loadmon(M2x);

% Medida experimental de los valores triestimulo de unos colores
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Luminancias de igualacion

YC1=[8.84 18.36 1.37];
YC2=[2.66 12.09 1.58];
YC3=[8.23 17.80 2.59];

YC1_05=[5.01 10.08 1.05];
YC2C3=[10.36 28.22 3.27];

% Valores triestimulo en la base RGBmon

TC1=YC1./Yw2;
TC2=YC2./Yw2;
TC3=YC3./Yw2;

TC1_05=YC1_05./Yw2;
TC2C3=YC2C3./Yw2;

% FIGURA 1

figure,colorspc([TC1;TC1_05;1 1 1],1,T_l2,Yw2,'showvectors',1,'symb','.','sizes(3)',5,'showtriang',{3,tm2},'linecolors(7:8,:)',[0 0 0;0 0 0],'show_numb',1,'lim_axis',[0 1 0 1 0 1],'show_box',0),title('Proporcionalidad')
hold on,colorspc([0.5*TC1],1,T_l2,Yw2,'showvectors',1,'symb','.','sizes(3)',5,'showtriang',{3,tm2},'linecolors(7:8,:)',[1 0 0;0 0 0],'lim_axis',[0 1 0 1 0 1],'show_box',2)

  % FIGURA 4a
figure,colordgm([TC1;TC1_05;1 1 1],1,T_l2,Yw2,'symb','.','sizes(3)',8,'show_numb',1,'linecolors(7,:)',[0 0 0]),title('Proporcionalidad')
hold on,colordgm([0.5*TC1],1,T_l2,Yw2,'symb','.','sizes(3)',8,'show_numb',0,'linecolors(7,:)',[1 0 0]),

% FIGURA 2

figure,colorspc([TC2;TC3;TC2C3;1 1 1],1,T_l2,Yw2,'showvectors',1,'symb','.','sizes(3)',5,'showtriang',{3,tm2},'linecolors(7:8,:)',[0 0 0;0 0 0],'show_numb',1,'lim_axis',[0 1 0 1 0 1],'show_box',0),title('Suma')
hold on,colorspc([TC2+TC3],1,T_l2,Yw2,'showvectors',1,'symb','.','sizes(3)',5,'showtriang',{3,tm2},'linecolors(7:8,:)',[1 0 0;0 0 0],'lim_axis',[0 1 0 1 0 1],'show_box',2)

  % FIGURA 4b
figure,colordgm([TC2;TC3;TC2C3;1 1 1],1,T_l2,Yw2,'symb','.','sizes(3)',8,'show_numb',1,'linecolors(7,:)',[0 0 0]),title('Suma')
hold on,colordgm([TC2+TC3],1,T_l2,Yw2,'symb','.','sizes(3)',8,'show_numb',0,'linecolors(7,:)',[1 0 0]),

% Nuevas funciones de igualacion FIGURA 3

   % En realidad ya lo habiamos calculado con newconst.m: T_l2
     figure,plot(T_l2(:,1),T_l2(:,2),'r-',T_l2(:,1),T_l2(:,3),'g-',T_l2(:,1),T_l2(:,4),'b-'),title('Func. Igual. Color RGBmon')
   
   % Pero si nos empeñamos en hacerlo como dice en la practica:
     F=(M12*T_l(:,2:4)')';
     figure,plot(T_l2(:,1),F(:,1),'r-',T_l2(:,1),F(:,2),'g-',T_l2(:,1),F(:,3),'b-'),title('Func. Igual. Color RGBmon')
     
     
% VALORES TRIESTIMULO DE UNA MUESTRA MUNSELL ILUMINADA CON D65

reflec=loadrefl;

figure,plot(reflec(:,1),reflec(:,2)),xlabel('\lambda (nm)'),title('Reflectancia')

% Queremos un iluminante de 100cd/m2
esp=loadillu(100,1,10,T_l2,Yw);

figure,plot(esp(:,1),esp(:,2)),xlabel('\lambda (nm)'),title('Radiancia del iluminante (W/m2*str)')

% Hagamos el calculo en RGBmon
[Trgb,RRrgb]=spec2tri(T_l2,10,reflec,esp,100,Yw2);

figure,plot(RRrgb(:,1),RRrgb(:,2)),xlabel('\lambda (nm)'),title('Radiancia reflejada (W/m2*str) -calculo en RGB-')

% O en XYZ
[Txyz,RRxyz]=spec2tri(T_l,10,reflec,esp,100,Yw);

figure,plot(RRxyz(:,1),RRxyz(:,2)),xlabel('\lambda (nm)'),title('Radiancia reflejada (W/m2*str) -calculo en XYZ-')

Trgbmon=(M12*Txyz')';