我对matlab中的色度图计算完全感到困惑。
xyz 到 srgb 的转换是标准的。虽然它似乎缺少光源适应。
function [rgb] = xyz2srgb(xyz)
M = [ 3.2406 -1.5372 -0.4986; -0.9689 1.8758 0.0415; 0.0557 -0.2040 1.0570 ];
[rows cols ] = size(xyz);
rgb = M*xyz;
for c = 1:cols
for ch = 1:3
if rgb(ch,c) <= 0.0031308
rgb(ch,c) = 12.92*rgb(ch,c);
else
rgb(ch,c) = 1.055*(rgb(ch,c)^(1.0/2.4)) - 0.055;
end
% clip RGB
if rgb(ch,c) < 0
rgb(ch,c) = 0;
elseif rgb(ch,c) > 1
rgb(ch,c) = 1;
end
end
end
end
对我来说没有意义的是 xyY 到 xyz 的转换。它在下面看到并逐步穿过可见光谱。我还没有找到像这样的任何其他实现.. 这似乎是 matlab 中的 patch 函数所独有的:
w2 = mod(w,N)+1;
a1 = atan2(y(w)-e,x(w)-e); % start angle
a2 = atan2(y(w2)-e,x(w2)-e); % end angle
r1 = ((x(w)-e) ˆ 2 + (y(w)- e) ˆ 2) ˆ 0.5;% start radius
r2 = ((x(w2)-e) ˆ 2 + (y(w2)-e) ˆ 2) ˆ 0.5; % end radius
for c = 1:steps % colourfulness
% patch polygon
xyz(1,1) = e+r1*cos(a1)*c/steps;
xyz(1,2) = e+r1*sin(a1)*c/steps;
xyz(1,3) = 1 - xyz(1,1) - xyz(1,2);
xyz(2,1) = e+r1*cos(a1)*(c-1)/steps;
xyz(2,2) = e+r1*sin(a1)*(c-1)/steps;
xyz(2,3) = 1 - xyz(2,1) - xyz(2,2);
xyz(3,1) = e+r2*cos(a2)*(c-1)/steps;
xyz(3,2) = e+r2*sin(a2)*(c-1)/steps;
xyz(3,3) = 1 - xyz(3,1) - xyz(3,2);
xyz(4,1) = e+r2*cos(a2)*c/steps;
xyz(4,2) = e+r2*sin(a2)*c/steps;
xyz(4,3) = 1 - xyz(4,1) - xyz(4,2);