colormap for a matrix with 4 columns

Hi, I have a 3D plot with around 200 points and each has an associated vector (C1,C2,C3,C4) so matrix C = 200x4. I am looking to get a colormap to assign a unique color to each point in a plot based on their four Ci values (i.e. to get a color as mix of 4 colors such as CMYK). Any help would be appreciated
Thanks in advance

Réponses (2)

Walter Roberson
Walter Roberson le 27 Oct 2018
The *.icc file can be obtained at the link above.
I_cmyk = reshape(mat2gray(C),size(C,1), 1, 4);
inprof = iccread('USSheetfedCoated.icc');
outprof = iccread('sRGB.icm');
C = makecform('icc',inprof,outprof);
I_rgb = applycform(I_cmyk,C);
rgbmap = reshape(I_rgb, [], 3);
pointsize = 20; %adjust as desired
scatter3( X(:), Y(:), Z(:), pointsize, rgbmap );

5 commentaires

Kiran Vaddi
Kiran Vaddi le 27 Oct 2018
Hi, Thank for the above code I tried to use it but I seem to get the color as black for all the points? Can you kindly create a dummy data for C and (x,y,z) and show me the 3D plot with color coding? Would be really helpful
Thanking you!
C = rand(200,4);
X = rand(200,1); Y = rand(200,1); Z = rand(200,1);
I_cmyk = reshape(mat2gray(C),size(C,1), 1, 4);
inprof = iccread('USSheetfedCoated.icc');
outprof = iccread('sRGB.icm');
Cp = makecform('icc',inprof,outprof);
I_rgb = applycform(I_cmyk, Cp);
rgbmap = reshape(I_rgb, [], 3);
pointsize = 20; %adjust as desired
scatter3( X(:), Y(:), Z(:), pointsize, rgbmap, 'filled' );
You might have to look closely to see the difference in colors. Remember that high K values indicate darker areas.
Kiran Vaddi
Kiran Vaddi le 27 Oct 2018
Hi, Thanks for the update
I am getting something similar to this
But as can be seen it is difficult to find a corresponding Cn quadruple for a point Pn in the 3D space based on its color
I am looking for a color map which can do the following
Notice that here each corner represents one column (of Cn matrix) and dark Cyan mean C4=1 etc and anything in between can be mapped to its respective location in the tetrahedron
For eg: if a point Pm has a dark Cyan color in the 3D plot, I should be able to infer that it is being sampled from C4 corner of the tetrahedron and it has properties of C1=C2=C3=0 and C4=1
It would be really helpful if you can suggest a way to work this out
Thanking you!
Image Analyst
Image Analyst le 27 Oct 2018
I think the way I gave in my answer should work. Basically you have to normalize your C measurements, then take the mean of them all.
According to references I find, "dark cyan" is CMYK 100, 0, 0, 45. This is distinctly different than CMYK 100, 0, 0, 0, so if you want C1 to correspond to dark cyan then it is not possible to calculate it based upon relative portions 1.0, 0.0, 0.0, 0.0 in any permutation.
Using data cursor to read off the colors at the vertices of your diagram as best I can, and using the conversion at https://www.rapidtables.com/convert/color/rgb-to-cmyk.html (and note that max for RGB is 255 but max for CMYK is 100)
C1 - RGB [41 38 39] CMYK - [0 7 5 84]
C2 - RGB [246 233 74] CMYK - [0 5 70 4]
C3 - RGB [0 180 236] CMYK - [100 24 0 7]
C4 - RGB [234 15 137] CMYK - [0 94 41 8]
The only one of those that maps at all well to CMYK is C3, potentially pure cyan, but C3 has 1/4 magenta in the mix.
The CMYK that I get out of the conversion from the Mathworks Support link appear to be rather different than the values from the online calculator. It is possible that the conversion profile is quite different, but the differences are fairly large, so I am not convinced the conversion is accurate for the one provided by Mathworks Support.
Anyhow, your tetrahedron does not match CMYK.
I do not think that humans could be expected to mentally interpolate between four different values (C1, C2, C3, C4) based upon three pieces of information (R, G, B). Humans are not all that good at identifying mid colors, especially not in small swathes.

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 27 Oct 2018
Can you attach C in a .mat file, and include a screenshow of your 3-D plot?
What are the 3 axes in the 3-D plot? C1, C2, and C3? What to the 4 C's represent? X, Y, Z, and something? What exactly is a "point"? A plot in 4-D space, or a point in 3D space where C4 is some kind of intensity value at the x,y,z coordinate? If you have 200 points and want a colormap with 200 unique colors, why can't you just do
cmap = hsv(200); % Make 200 unique colors.

4 commentaires

Kiran Vaddi
Kiran Vaddi le 27 Oct 2018
Hi, I apologize . I won't be able to attach the C matrix but I can explain my problem better. Three axis in the 3D plot are some kind of coordinates Pn=(x,y,z) for a point which has associated values Cn=(C1,C2,C3,C4). And I have n=1 to 200 such points Essentially I need a color with which I can color code all 200 Pn's based on it's respective Cn You can think of Cn being sampled from a 4D space of a tetrahedron where each corner has C,M,Y,K colors respectively and we get a CMYK color mix based on where you're in the tetrahedron. I want to be able to attach a mixed color based on Cn to a point Pn in 3D space
I hope this explains it better
Any help would be greatly appreciated
OK, I'm making up something to help me visualize if. You have 200 points in 3-D space, let's say they're position. And for each point you have 4 measurements - let's say they are temperature, pressure, light level, and pollen count. And you want to put a marker there that has a color that is derived from some kind of function of the 4 measurements. So what I'd do is to normalize each measurement to 0-1. Then I'd take the mean of the 4 normalized measurements, and plot that. Then choose any standard, or custom, colormap you want. To start
normC1 = (C1(k) - C1Min) / (C1Max - C1Min); % Normalize 0-1.
normC2 = (C2(k) - C2Min) / (C2Max - C2Min); % Normalize 0-1.
Same for C3 and C4. Then I'd compute the mean
newValue(k) = mean([normC1, normC2, normC3, normC4]);
Then plot then and apply a colormap.
plot3(x, y, z, newValue);
colormap(.....
Walter Roberson
Walter Roberson le 27 Oct 2018
? plot3 does not take a 4th numeric input, and does not permit an array of color inputs ?
Image Analyst
Image Analyst le 27 Oct 2018
I guess you'd have to use scatter3() then, which can take a color for every point.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by