我完全对Matlab中色度图的计算感到困惑。
找到了here代码found here。
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补丁功能所独有的:
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);