We can display an image in a specific axes (axes4) based on a user selection from a popup menu by creating a GUI with an axes and a popup menu using MATLAB App Designer or GUIDE. The GUI should include options for different color channels (e.g., RED, BLUE, GREEN). In the callback function of popup menu, we read the image and extract the selected color channel. By setting "axes4" as the current axes using the "axes" function, we ensure that the "imagesc" function displays the image in the correct location, allowing dynamic updates based on user interaction.
Below is the sample MATLAB code to achieve the same:
function myImageDisplayApp
% Create a figure
hFig = figure('Name', 'Image Display App', 'NumberTitle', 'off', ...
'MenuBar', 'none', 'ToolBar', 'none', 'Position', [100, 100, 600, 400]);
% Create axes4
handles.axes4 = axes('Parent', hFig, 'Units', 'normalized', ...
'Position', [0.1, 0.3, 0.35, 0.6]);
% Create popupmenu2
handles.popupmenu2 = uicontrol('Style', 'popupmenu', ...
'String', {'Select', 'RED', 'BLUE', 'GREEN'}, ...
'Units', 'normalized', ...
'Position', [0.5, 0.8, 0.3, 0.1], ...
'Callback', @(hObject, eventdata) popupmenu2_Callback(hObject, eventdata, handles));
% Callback function for popupmenu2
function popupmenu2_Callback(hObject, ~, handles)
str = get(hObject, 'String');
val = get(hObject, 'Value');
% Only proceed if a valid color is selected
if val > 1
% Load the image
a = imread('C:\Users\dchangoi\Downloads\image1.JPG');
% Select the color channel based on user selection
switch str{val}
case 'RED'
channel = a(:,:,1);
case 'BLUE'
channel = a(:,:,3);
case 'GREEN'
channel = a(:,:,2);
end
% Display the selected channel in axes4
axes(handles.axes4); % Set the current axes to axes4
imagesc(channel); % Display the selected color channel
axis image off; % Adjust axis properties
end
end
end
Please find attached the documentation of functions used for reference:
I hope this assists in resolving the issue.


