1

I'm completely baffled by the chromaticity diagram calculation in matlab.

It is found here code found here.

The xyz to srgb conversion is standard.. though it seems to be missing an illuminant adaptation.

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

What makes no sense to me is the xyY to xyz conversion. It's seen below and steps through the visible spectrum. I haven't been able to find any other implementations like this one.. which seems unique to the patch function in 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);
Union find
  • 7,759
  • 13
  • 60
  • 111
  • The CIE 1931 plot must be a simulation. We don't suppose to see such wide gamut, on the PC monitor (the patch is created in sRGB color space, so we are limited to the colors inside the "triangle" of sRGB). Note that `xyz2rgb` function exists since MATLAB 2014b. – Rotem Jun 23 '19 at 12:25
  • I understand that but what are the sin and cos functions?? @Rotem – Union find Jun 23 '19 at 14:31
  • the sin and cos are used to scale out the values on the out-of-gamut chromacities. Probably they approximate the curves into a new parametric curve. As I wrote you in the other question. Forget about getting colours on chromacity diagrams: it will just confuse people and IT IS WRONG. If you want to do properly, select 16x16x16 RGB values, calculate they X,Y,Z and then x,y. Now you can plot in x,y diagram a RGB colour (and in the correct place). Your computer cannot display violet, do not make people thinking that colour with low x,y is violet (it is not). – Giacomo Catenazzi Jun 25 '19 at 13:34

0 Answers0