Write a GUI that displays an image in which all of the elements are the same color. Put 3 sliders in that allow the user to specify the amount of red, green, and blue in the image. Use the RGB method
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:13| Question number:24.13
All Answers
total answers (1)
ColorGUI.m
function ColorGUI
f = figure('Visible', 'off','Position',...
[360, 500, 400,400]);
% Minimum and maximum values for sliders
minval = 0;
maxval = 255;
% Create the slider objects
rslhan = uicontrol('Style','slider','Units',...
'Normalized','Position',[.1,.4,.25,.05], ...
'Min', minval, 'Max', maxval,'SliderStep', [1 1],
'Callback', @callbackfn);
gslhan = uicontrol('Style','slider','Units',...
'Normalized','Position',[.4,.4,.25,.05], ...
'Min', minval, 'Max', maxval,'SliderStep', [1 1],
'Callback', @callbackfn);
bslhan = uicontrol('Style','slider','Units',...
'Normalized','Position',[.7,.4,.25,.05], ...
'Min', minval, 'Max', maxval,'SliderStep', [1 1],
'Callback', @callbackfn);
% Text boxes to show slider values
hredtext = uicontrol('Style','text','BackgroundColor',
'white', ...
'Units','Normalized','Position', [.2,.3,.075,.025],...
'Visible', 'off');
hgreentext = uicontrol('Style','text','BackgroundColor',
'white', ...
'Units','Normalized','Position', [.525,.3,.075,.025],...
'Visible', 'off');
hbluetext = uicontrol('Style','text','BackgroundColor',
'white', ...
'Units','Normalized','Position', [.825,.3,.075,.025],...
'Visible', 'off');
% Create axes handle for plot
axhan = axes('Units', 'Normalized','Position',
[.4,.6,.2,.2]);
movegui(f,'center')
set(f,'Visible','on');
% Call back function displays the current slider values &
% shows color
function callbackfn(source,eventdata)
rnum=get(rslhan, 'Value');
gnum = get(gslhan, 'Value');
bnum = get(bslhan, 'Value');
set(hredtext,'Visible','on','String',num2str(rnum))
set(hgreentext,'Visible','on','String',num2str(gnum))
set(hbluetext,'Visible','on','String',num2str(bnum))
mat = zeros(2,2,3);
mat(:,:,1) = rnum;
mat(:,:,2) = gnum;
mat(:,:,3) = bnum;
mat = uint8(mat);
image(mat)
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer