我要算每一個顏色與對應灰階的色溫值 但是記憶體不足(要24G以上才算的完 有可能更多)
無法算完 請問有其他寫法嗎?
1.只算我想要的色溫的x,y範圍 (可以給定一個誤差是可以接受的)
但我不知道怎從色溫反推x,y
因為目標光的RGB有可能是不同灰階相加而得 所以R G B的灰階數不一定相等
R的x,y,Y G的x,y,Y B的x,y,Y
轉換成各自的XYZ後 RX+GX+BX=WX
RY+GY+BY=WY
RZ+GZ+BZ=WZ
再得到新的x,y,Y才有辦法算出色溫
所以用某個色溫反推 我推不回去...
2.能夠把值算完但不會撐爆記憶體 全部算完再取出我要的色溫 看用哪幾組RGB(xyY)
(我目前只會這個 但是記憶體爆了 而且算超久 所以不能用)
希望能有改進的發法
data是我量測的資料
W0_x=data(:,2);
W0_y=data(:,3);
W0_Y=data(:,4);
R0_x=data(:,10);
R0_y=data(:,11);
G0_x=data(:,13);
G0_y=data(:,14);
B0_x=data(:,16);
B0_y=data(:,17);
_
for i=1:256
a1(i)=(R0_x(i)-W0_x(i))/(R0_y(i));
b1(i)=(G0_x(i)-W0_x(i))/(G0_y(i));
c1(i)=(B0_x(i)-W0_x(i))/(B0_y(i));
a2(i)=(R0_y(i)-W0_y(i))/(R0_y(i));
b2(i)=(G0_y(i)-W0_y(i))/(G0_y(i));
c2(i)=(B0_y(i)-W0_y(i))/(B0_y(i));
end
RY=b1.*c2-c1.*b2;
GY=c1.*a2-c2.*a1;
BY=a1.*b2-b1.*a2;
for i=1:256
RY01(i)=RY(i)/(RY(i)+GY(i)+BY(i))*W0_Y(i);
GY01(i)=GY(i)/(RY(i)+GY(i)+BY(i))*W0_Y(i);
BY01(i)=BY(i)/(RY(i)+GY(i)+BY(i))*W0_Y(i);
end
new_R=RY01;
new_G=GY01;
new_B=BY01;
new_W=new_R+new_G+new_B;
%calculate xyY to XYZ 1
%Red
R_x=data(:,10);
R_y=data(:,11);
R_Y=new_R;
t1=0:4:1020;
t1 = t1';
t=0:1:1020;
t=t';
R_x=pchip(t1,R_x,t);
R_y=pchip(t1,R_y,t);
R_Y=pchip(t1,R_Y,t);
for i=1:1021
R_X(i)=(R_x(i)*R_Y(i))/(R_y(i));
R_Z(i)=(1-R_x(i)-R_y(i))*(R_Y(i))/(R_y(i));
end
%Green
G_x=data(:,13);
G_y=data(:,14);
G_Y=new_G;
G_x=pchip(t1,G_x,t);
G_y=pchip(t1,G_y,t);
G_Y=pchip(t1,G_Y,t);
for i=1:1021
G_X(i)=(G_x(i)*G_Y(i))/(G_y(i));
G_Z(i)=(1-G_x(i)-G_y(i))*(G_Y(i))/(G_y(i));
end
%Blue
B_x=data(:,16);
B_y=data(:,17);
B_Y=new_B;
B_x=pchip(t1,B_x,t);
B_y=pchip(t1,B_y,t);
B_Y=pchip(t1,B_Y,t);
for i=1:1021
B_X(i)=(B_x(i)*B_Y(i))/(B_y(i));
B_Z(i)=(1-B_x(i)-B_y(i))*(B_Y(i))/(B_y(i));
end
%calculate xyY to XYZ 2
new_X=R_X+G_X+B_X;
new_Y=R_Y+G_Y+B_Y;
new_Z=R_Z+G_Z+B_Z;
%calculate XYZ to new xyz (for CCT)
for i=1:1021
for j=1:1021
for k=1:1021
new0_x(i,j,k)=(new_X(i))/(new_X(i)+new_Y(j)+new_Z(k));
new0_y(i,j,k)=(new_Y(j))/(new_X(i)+new_Y(j)+new_Z(k));
end
end
end
%color temperature
xe=0.3366;
ye=0.1735;
A0=-949.86315;
A1=6253.80338;
t1=0.92159;
A2=28.70599;
t2=0.20039;
A3=0.00004;
t3=0.07125;
cct0001=zeros(1021,1021,1021,4);
for i = 1 : 1021
for j = 1 : 1021
for k = 1 : 1021
n = (new0_x(i,j,k)-xe)/(new0_y(i,j,k)-ye);
ccolor_temperature(i,j,k,4)=
A0+A1*exp(-n/t1)+A2*exp(-n/t2)+A3*exp(-n/t3);
end
end
end
這我想來想去想不出所以然...