My precious scatter3 labels are mixed-up?

2 views (last 30 days)
Everything was working "fine" this morning -- I was in MatLab's heavens. But now, I've descended to hell, it seems.
Here's the result I'm getting now :
As you can see, I have the L, a, b datatips in the 'correct' order.
But, somehow, the numbers show incorrectly.
For example, Lab = -63.6769 42.1539 13.4103. There's no such thing as a negative L* value!
It is as though the values are "reversed" in the labels?
If you look at the content of the Lab values, in column 12, you'll see what I mean (same with Column 2) :
I enclose the script. I suspect the error occurs around the datatip definition :
img=imread('4x3_RGB.tif');
img_double=double(img)./255;
Lab3=rgb2lab(img_double, 'WhitePoint','d50');
% ------------------------------------------------------
Lab = reshape(permute(Lab3,[3 1 2]),3,[]);
% ------------------------------------------------------
f = figure;
set(f,'PaperUnits','centimeters');
set(f,'name','plot_Lab - colorimg@ugr.es');
set(0,'units','pixels') ;
screen = get(0,'screensize');
set(f,'Position',[200,screen(4)-screen(4)/3-200,screen(3)/2,screen(4)/3]);
linewidth = 1;
cform = makecform('lab2srgb','AdaptedWhitePoint',whitepoint('D50'));
RGB = applycform(Lab',cform);
min_Lab = min(Lab,[],2);
max_Lab = max(Lab,[],2);
if min_Lab(1) > 0
min_Lab(1) = 0;
end
if min_Lab(2) > -100
min_Lab(2) = -100;
end
if min_Lab(3) > -100
min_Lab(3) = -100;
end
if max_Lab(1) < 100
max_Lab(1) = 100;
end
if max_Lab(2) < 100
max_Lab(2) = 100;
end
if max_Lab(3) < 100
max_Lab(3) = 100;
end
h=scatter3(Lab(3,:),Lab(2,:),Lab(1,:),80,RGB,'fill');
xlabel('b*'),ylabel('a*'),zlabel('L*');
title('CIE-L*a*b* coordinates');
axis([min_Lab(3) max_Lab(3) min_Lab(2) max_Lab(2) min_Lab(1) max_Lab(1)]);grid on;hold on;
% draw black lines indicating axis
line([min_Lab(3) max_Lab(3)],[0 0],[0 0],'color',[0 0 0],'lineWidth',linewidth); % Axis L* == a* == 0
line([0 0],[min_Lab(2) max_Lab(2)],[0 0],'color',[0 0 0],'lineWidth',linewidth); % Axis L* == b* == 0
line([0 0],[0 0],[min_Lab(1) max_Lab(1)],'color',[0 0 0],'lineWidth',linewidth); % Axis a* == b* == 0
% Redefine labels
h.DataTipTemplate.DataTipRows(1).Label = 'L=';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'b=';
% Show datatip
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
I confess I've been scratching my head for a few hours now... I'll keep searching.. Hope I'll find the answer on my own, but in case... This might be something very obvious...
  3 Comments
Roger Breton
Roger Breton on 16 Dec 2021
I tried to see whether I can get any data from the 'runtime'. So I managed to find the Property Inspector :
Which show the XData, YData and ZData values (1x12 Double) for the plot.
This is the XData :
This is the YData :
And this is the XData :
Obviously, the Z axis corresponds to L*.
The YData is the a*.
The XData is the b*.
Sorry to put you through this mess.
Adam Danz
Adam Danz on 17 Dec 2021
Use the demo at the very end of my answer to your previous question.
https://www.mathworks.com/matlabcentral/answers/1612500-how-to-modify-scatter3-default-mouseover-display#answer_856610
It assigns datatip labels based on your axis labels assuming that you said the axis labels before you set the data tip labels.

Sign in to comment.

Accepted Answer

Voss
Voss on 16 Dec 2021
Note the order of the arguments in the call to scatter3:
h=scatter3(Lab(3,:),Lab(2,:),Lab(1,:),80,RGB,'fill');
so x corresponds to 'b', y is 'a', and z is 'L'.
Your code for axes labeling, setting axes limits, and plotting black axes lines all seems to respect this order properly. But the data tip labels are done out of order:
h.DataTipTemplate.DataTipRows(1).Label = 'L=';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'b=';
where, as far as I can tell from the documentation on datatips, Row 1 corresponds to the x-coordinate of the data, Row 2 is y, and Row 3 is z. (I don't know if there's a way to change this.) Therefore, the labels should go:
h.DataTipTemplate.DataTipRows(1).Label = 'b=';
h.DataTipTemplate.DataTipRows(2).Label = 'a=';
h.DataTipTemplate.DataTipRows(3).Label = 'L=';
That should get the values labelled accurately in the datatips.
But then, of course, I imagine you want the labels to go in L-a-b order (i.e., z-y-x). If there is no way to change the order of the Rows in a datatip, then one way you can do what you want is to redefine the axes so that x is 'L', y is 'a', and z is 'b' (you can rotate the axes programmatically so that the x-axis points upward like the z-axis does now, so that visually the result will be the same, but with correct datatip label ordering). This would require some refiguring of your existing code, unfortunately.
Just reordering the rows in the datatip labels would be easier, but, again, I don't know if it's possible.
  3 Comments
Adam Danz
Adam Danz on 17 Dec 2021
This is the same thing I explained in several of my comments to your previous question.
https://www.mathworks.com/matlabcentral/answers/1612500-how-to-modify-scatter3-default-mouseover-display#answer_856610
Roger Breton
Roger Breton on 17 Dec 2021
Just a follow-up comment...
This is a picture with saturated blues I used in my earlier attempts at '3D' plotting :
It's a Gouldian Finch I reduced down to 50 x 60 pixels, to experiment with. I derived my early work from an color management API called 'argyllcms.com'. It's quite advanced as an open-source effort. It has an option to generate 3D plots of various color device characterization targets. Historically, it used VRML but recently moved to X3DOM. The 'problem' is that using this approach, to ultimately be able to plot a picture like this Gouldian Finch got me to invest a lot of time to learn a 3D JavaScript environment for which I only found limited support... In looking at various vidéos on YouTube, I stumbled upon some scatter3 demos that wowed me. So, having Matlab already installed on my PC was the perfect excuse to get started... And, here is the results -- I'm so proud of where I managed to get so far, with your help and the other folks who lent a helping hand :
It is an encouraging start. It's actually quite impressive when I think of the relatively little number of lines of code to get to this result? And being able to mouse over the data and have the Lab values come up! I mean, wow! Now, the next step is to be able to superimpose the gamut of an output device as a wireframe, so that it's easy to tell which colors are out of gamut of the Destination device -- can't wait.
By the way, I'm impressed that this image of 50x60 pixels = 3000 pixels loaded up so quickly!

Sign in to comment.

More Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!