Turning the visibility inside a function does not work?

1 view (last 30 days)
I have this simple code :
a = lab(:,2);
b = lab(:,3);
L = lab(:,1);
k = boundary(a,b,L);
sRGBGamut = trisurf(k,a,b,L,'FaceColor','interp', 'FaceVertexCData',rgb,'EdgeColor','none');
set(sRGBGamut, 'Visible', 'off'); %<<<<<<<<<<<<<<<<<<<<<< see this line of code?
xlabel('a*')
ylabel('b*')
zlabel('L*')
axis([-128 128 -128 128 0 100])
view(10,35)
axis equal
title('sRGB gamut surface', 'in L*a*b* space'); % Add Title to Current Axes
ax.TitleHorizontalAlignment = 'left';
As you see, there is no point turning the visibility of the plot off here, but, for the sake of testing, it works. But for some reason, it refuses to work when issued from within a callback function. See this code :
function popupCallback(popup,event)
sels = get(popup,'String');
idx = get(popup,'Value');
Choix = sels{idx};
global sRGBGamut;
switch(Choix)
case 'sRGB'
title('sRGB gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'on');
fprintf('sRGB\n' );
case 'AdobeRGB'
title('AdobeRGB gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'off');
fprintf('AdobeRGB\n' );
case 'P3'
title('Display P3 gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'off');
fprintf('P3\n' );
case 'Rec2020'
title('Rec2020 gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'off');
fprintf('Rec2020\n' );
%otherwise
% fprintf('Invalid grade\n' );
end
end
What baffles me is that changing the title works great. But not turning the visibility of the plot?
  3 Comments
Roger Breton
Roger Breton on 14 Jan 2022
Hate to admit, the source of the error was 18 inches away from the monitor... It's called a "Code18" error...
If you would have had access to the whole script, you might have stumble on the sRGBGamut variable that was originally named just 'Gamut' but, uncle Roger, here, in its infinite wisdom, decided to rename it sRGBGamut as the handle of the trisurf object but forgot about renaming the global variable name as well, which remained simply 'Gamut' ...
Code18... Sorry for the intermission...
Roger Breton
Roger Breton on 14 Jan 2022
Edited: Walter Roberson on 15 Jan 2022
Here is my complete code :
global sRGBGamut ax;
figure;
ax=axes;
popup = uicontrol('Style', 'popup',...
'String', {'sRGB','AdobeRGB','P3','Rec2020'},...
'Position', [10 10 100 50],'background','green',...
'Value',1,'Callback',@popupCallback);
[r,g,b] = meshgrid(linspace(0,1,20)); % linspace(0,1,50)
rgb = [r(:), g(:), b(:)];
lab = rgb2lab(rgb); % Input - double (0.0 à 1.0)
lab2 = rgb2lab(rgb,'ColorSpace','adobe-rgb-1998');
a = lab(:,2);
b = lab(:,3);
L = lab(:,1);
k = boundary(a,b,L);
sRGBGamut = trisurf(k,a,b,L,'FaceColor','interp', 'FaceVertexCData',rgb,'EdgeColor','none');
xlabel('a*')
ylabel('b*')
zlabel('L*')
axis([-128 128 -128 128 0 100])
view(10,35)
axis equal
title('sRGB gamut surface', 'in L*a*b* space'); % Add Title to Current Axes
ax.TitleHorizontalAlignment = 'left';
function popupCallback(popup,event)
sels = get(popup,'String');
idx = get(popup,'Value');
Selection = sels{idx};
global sRGBGamut;
switch(Selection)
case 'sRGB'
title('sRGB gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'on');
fprintf('sRGB\n' );
case 'AdobeRGB'
title('AdobeRGB gamut surface', 'in L*a*b* space');
% axis off;
set(sRGBGamut, 'Visible', 'off');
fprintf('AdobeRGB\n' );
case 'P3'
title('Display P3 gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'off');
fprintf('P3\n' );
case 'Rec2020'
title('Rec2020 gamut surface', 'in L*a*b* space');
set(sRGBGamut, 'Visible', 'off');
fprintf('Rec2020\n' );
%otherwise
% fprintf('Invalid grade\n' );
end
end
The goal of this script is to show my students the various shapes of simple RGB color spaces. sRGB and AdobeRGB are 'built-in' but I want to bring some other ones as ICC profiles. I understand I'll have to use cform and that's OK.
Since I'm quite new to Matlab, I thought, naively perhaps, I could simply 'precompute' all the gamuts (trisurf) of all the ICC profiles I care to list in my drop-down menu and simply 'toggle' between each one in a switch statement by selectively turning each gamuts visibility off/on.
Later, I'd wish to add an "... other" to my drop-down list to all the user to navigate to a directory, somewhere, to select any ICC profile, to load up its gamut.
Right now, my code is designed to handle RGB spaces but I'll be adding extra code to handle CMYK space.

Sign in to comment.

Answers (0)

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!