Turning the visibility inside a function does not work?

조회 수: 5 (최근 30일)
Roger Breton
Roger Breton 2022년 1월 14일
편집: Walter Roberson 2022년 1월 15일
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
Roger Breton
Roger Breton 2022년 1월 14일
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 2022년 1월 14일
편집: Walter Roberson 2022년 1월 15일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by