How to plot colors on CIE 1931 Color Space in Matlab?

15.2k views Asked by At

I'm trying to plot few color values (co-ordinates) on the already plotted CIE 1931 color space. I've derived the XYZ color values which I want to plot, denoted as [X, Y, Z]-

[50, 57, 10] [36, 43, 15] [28, 36, 8] [25, 32, 14]

I using this function which plots the entire CIE color space - http://www.mathworks.com/matlabcentral/fileexchange/40640-computational-colour-science-using-matlab-2e/content//cieplot.m

 cieplot();
 hold on
 x=[0.42 0.58]
 y=[0.48 0.45];
 scatter(x,y);
 hold off

I've used the below two formulas for calculating the x and y values used in the above code to plot 2 colors as an example and it generates the figure/graph shown. One of the 2 colors goes outside the desired color spectrum. I'm confused as to how to plot z coordinate which can be calculated as z=1-x-y on the shown CIE color space, so that all the colors fit within the spectrum.

Formula to calculate x

Formula to calculate y

Generated Plot/Figure

1

There are 1 answers

1
Sarthak Singhal On BEST ANSWER

As pointed out by horchler, the mistake was in my color conversion (RGB to XYZ to xyY) which I had done external to MATLAB. On correcting the error, the following code produced the desired result.

cieplot();
hold on
x=[0.42 0.38 0.388 0.352 0.344 0.281]
y=[0.48 0.45 0.5 0.45 0.452 0.352];
scatter(x,y,10,'filled');
i=1;
a=[1 2 3 4 5 6];
strValues = strtrim(cellstr(num2str(a(:),'(%d)')));
text(x,y,strValues,'VerticalAlignment','bottom');
hold off

The graph shows the six colors plotted in CIE 1931 color space as per their x and y values. The resultant graph