radiobutton to switch between scatter3 datasets?

I would like to extend the vizualisation in my scatter3 project to inGamut colors. Right now, what I have is this :
The points represent the unconverted sRGB colors in Lab. The data tip shows both these Lab coordinates and how far they are relative to the Destination gamut. But I would like to have a radio button that would toggle between the unconverted sRGB "Lab" colors and the converted colors, once converted with applycform to the Desination gamut. Based on my experience with the Opacity slider control, I figure my code to add this functionality could be as follows :
% First, define the control
uicontrol('Style', 'radiobutton', ______, 'Callback', {@radiobuttonCB, h}); % h is the handle of the scatter3 figure
% Then, the callback
function radiobuttonCB(SliderH, EventData, h)
h=scatter3(LabIN(2,:),LabIN(3,:),LabIN(1,:),80,RGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
end
The initial scatter3 function is this :
h=scatter3(Lab(2,:),Lab(3,:),Lab(1,:),80,RGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
I'm not sure I can simply 're-call' the scatter3 with the new X,Y, Z parameters? How should I proceed?
And then, I'll to come up with some logic to toggle back to the original Lab data... Oh boy!

1 件のコメント

Roger Breton
Roger Breton 2021 年 12 月 23 日
Oops! I found the example code in the Help. Now, my figure looks like this :
So, it looks like I have to do my stuff in the callback function, shown this way in the Help documentation :
function bselection(source,event)
disp(['Previous: ' event.OldValue.String]);
disp(['Current: ' event.NewValue.String]);
disp('------------------');
end
I guess, then, I should reformulate my question, can I simply 're-call' or 're-issue' the scatter3 function from within this callback function :
function bselection(source,event)
h=scatter3(LabIN(2,:),LabIN(3,:),LabIN(1,:),80,RGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
end
Thanks in advance for your help and patience... I'll continue my research in case...

サインインしてコメントする。

 採用された回答

Roger Breton
Roger Breton 2021 年 12 月 23 日

0 投票

After much work, I got the solution working, although it is far from elegant. I had to define a bunch of global... I'll loop into app properties -- promised. This is the code I use :
function bselection(source,event)
global LabIMG LabIMG_Epson rawRGB imgRGB a b L k rgb DE76
if event.NewValue.String == "Epson"
hold off
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
else
hold off
h=scatter3(LabIMG(2,:),LabIMG(3,:),LabIMG(1,:),80,rawRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
end
hold on
h1 = trisurf(k,a,b,L,'FaceColor','interp','FaceVertexCData',rgb,'EdgeColor','none', 'FaceAlpha', 0.5)
linewidth = 1
xlabel('b*'),ylabel('a*'),zlabel('L*');
title('CIE-L*a*b* coordinates');
axis([-128 128 -128 128 0 100]);grid on;hold on;
% draw black lines indicating axis
line([-128 128],[0 0],[0 0],'color',[1 0 0],'lineWidth',linewidth); % Axis L* == a* == 0
line([0 0],[-128 128],[0 0],'color',[0 1 0],'lineWidth',linewidth); % Axis L* == b* == 0
line([0 0],[0 0],[0 100],'color',[0 0 1],'lineWidth',linewidth); % Axis a* == b* == 0
% Redefine labels
h.DataTipTemplate.DataTipRows(1).Label = 'b'; % X
h.DataTipTemplate.DataTipRows(2).Label = 'a='; % Y
h.DataTipTemplate.DataTipRows(3).Label = 'L='; % Z
row = dataTipTextRow('DE76=',DE76(:));
h.DataTipTemplate.DataTipRows(end+1) = row;
% Show datatip
% Syntaxe: datatip(target,x,y,z)
datatip(h, h.XData(1),h.YData(1),h.ZData(1));
disp(['Previous: ' event.OldValue.String]);
disp(['Current: ' event.NewValue.String]);
disp('------------------');
end
The code "ballooned" because I had to "repeat" figure setup code.
For now, I don't really care since I'm at a very experimental stage...
Thank you Chris!

その他の回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 12 月 23 日

0 投票

Right now, your color is set by your variable RGB (which appears to be undefined in the callback function you have shared). So long as this variable gets updated with your desired colors, yes, you can just re-call the bSelection function.
However, we are unaware of what other code may exist inside this callback function. Whether this is the right approach or not will have to be decided by you after taking that into consideration.

12 件のコメント

Roger Breton
Roger Breton 2021 年 12 月 23 日
Chris,
I would have found at some point that, not only do I need to change the 'source' Lab colors, in the X,Y,Z arguments of the scatter3 call but also the RGB colors? Boy! It makes me think of "Tango" : one step forward and two steps backward :-) .....
Thanks for your help.
Cris LaPierre
Cris LaPierre 2021 年 12 月 23 日
Just to be clear, RGB is just a variable. You are using it to specify the 'Color' property when you create the figure.
Consider sharing your app and data if you can (attach using the paperclip icon) so that we can help specifically with your application.
Roger Breton
Roger Breton 2021 年 12 月 23 日
I don't dare share my 'app" because you'll see just how an amateur I am... But, here goes.. But you're going to need my ICC printer profile? But you can always substitute yours to be able to trace through.
The code is getting very complicated. It should be broken down into more functions but I'm just at the stage of "tinkering" that I have not done it yet. Besides, I'm really new to Matlab, so I'm surely far from what seasoned Matlab users do...
At any rate, I managed to get to the point of being able to code my "alternative" scatter3 call, in reponse to clicking that radio button, and it looks like this :
function bselection(source,event)
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
end
The error I run into, now, is that the variables 'LabIMG_Epson' are no longer in scope! So I guess I need to find a way to define them 'globally' -- don't you like programming!
Thank you so much for your kind and patient help in advance, and appologize for mostly 'french' comments (my mother tongue). At the stage I'm at, to just be able to follow the logic, I write the comments in French FIRST, but I'm well aware it limits my communication capabilities when I try to post my code, here...
Cris LaPierre
Cris LaPierre 2021 年 12 月 23 日
Your callbacks are all functions, so any variables created inside a function are lost when the function ends. The exception to this in an app are variables that are created as properties of the app.
See this page for details on how to do this.
Roger Breton
Roger Breton 2021 年 12 月 23 日
BTW, I tried substituting my alternative scatter3 function call (with the alternate Lab values) in the original routine :
% scatter3 Call --------------------------------------------------------
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
h=scatter3(LabIMG(2,:),LabIMG(3,:),LabIMG(1,:),80,rawRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
The two scatter3 calls work perfect, meaning my arguments are 'correct'.
I experimented with declaring the variable LabIMG_Epson 'global' but I still get the same error in the callback function :
function bselection(source,event)
global LabIMG_Epson
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
end
Here is the error message that appears when I click the Epson radio button :
Error in plot_Lab_ReshapePermute>bselection (line 255)
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor',
[0,0,0], 'Linewidth', 1.3);
Error while evaluating ButtonGroup SelectionChangedFcn.
Roger Breton
Roger Breton 2021 年 12 月 23 日
Got it! Oh boy! The imgRGB parameter also has to be declared 'global'!
Cris LaPierre
Cris LaPierre 2021 年 12 月 23 日
Don't use globals!! Use app properties. This is the link I shared previously.
Roger Breton
Roger Breton 2021 年 12 月 23 日
It works!
Once I made the imgRGB global! But I have to clear the figure?
This is what I get (the two scatter3 combined) :
Roger Breton
Roger Breton 2021 年 12 月 23 日
Naturally, when I clear the figure with hold off, everything disappears!
So I have to re-issue the trisurf call again, but when I do that, I find I'm stuck with a bunch of variables are out of scope (k, a, b, L, rgb) all of a sudden, sadly :
function bselection(source,event)
global LabIMG_Epson
global imgRGB
hold off
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
h1 = trisurf(k,a,b,L,'FaceColor','interp','FaceVertexCData',rgb,'EdgeColor','none', 'FaceAlpha', 0.5)
end
More 'global' variables declarations... Until I come up with a better way to do this?
Cris LaPierre
Cris LaPierre 2021 年 12 月 23 日
編集済み: Cris LaPierre 2021 年 12 月 23 日
Again, don't use globals. Use app properties.
Roger Breton
Roger Breton 2021 年 12 月 23 日
編集済み: Roger Breton 2021 年 12 月 23 日
Too late!
I got this new code working :
function bselection(source,event)
global LabIMG_Epson imgRGB a b L k rgb
hold off
h=scatter3(LabIMG_Epson(2,:),LabIMG_Epson(3,:),LabIMG_Epson(1,:),80,imgRGB,'fill', 'MarkerEdgeColor', [0,0,0], 'Linewidth', 1.3);
hold on
h1 = trisurf(k,a,b,L,'FaceColor','interp','FaceVertexCData',rgb,'EdgeColor','none', 'FaceAlpha', 0.5)
end
I promise I'll take a look at app properties, Chris.
But any suggestion how I could toggle back to the original plot?
Roger Breton
Roger Breton 2021 年 12 月 23 日
I'm looking at app properties now... It is exhausting EVERYTHING I have to swallow and learn in no time...
Thanks for your help and patience.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

リリース

R2021b

質問済み:

2021 年 12 月 23 日

回答済み:

2021 年 12 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by