Hi I am designing a gui in which the user will press a button to select images and then display them in the axes I have created.
I do know how to display one image on a specific axes but how could I select and display more than one ?
Thanks
Hi I am designing a gui in which the user will press a button to select images and then display them in the axes I have created.
I do know how to display one image on a specific axes but how could I select and display more than one ?
Thanks
if the files are in the same folder you can use:
[filename, pathname, filterindex] = uigetfile( {file_types_to_display}, 'Window_Title', 'MultiSelect', 'on');
this will produce a cell with the selected file name as well as the paths. you can then use strcat or similar to produce the full path of the files to then use load in order to add them to the workspace.
uigetfile doesn't work with files in multiple folders.
another option is to do some sort of recursive search to list all files in the folder based on file extension or name and then proceed to load the ones you want. this way you would have all files in the folder and subfolder so you can use images in multiple folders. search MATLAB Exchange for recursive file search code.
EDIT 1: to display the selected images by using uigetfile, you need to put the code to select and display the images beneath the push-button callback generated by guide.
function pushbutton1_Callback(hObject, eventdata, handles)
%multi-file selection
[filename, pathname, ~] = uigetfile({ '*.jpg'}, 'Pick 3 files',...
'MultiSelect', 'on');
%generation of strings containing the full path to the selected images.
img1 = strcat(pathname, filename{1});
img2 = strcat(pathname, filename{2});
img3 = strcat(pathname, filename{3});
%assign an axes handle to preced imshow and use imshow to display the images
% in individual axes.
axes(handles.axes1);
imshow(img1);
axes(handles.axes2);
imshow(img2);
axes(handles.axes3);
imshow(img3);
the above code lets you select any number of images from a folder however it only shows the first 3 images in the generated cell 'filename'. to be able to select as many images as you want then scroll through them you need two more push-button callbacks for forward and back then..
function pushbutton1_Callback(hObject, eventdata, handles)
%assign global variable so the other pushbuttons can access the values
global k num_imgs pathname filename
%uigetfile in multiselect mode to select multiple files
[filename, pathname, ~] = uigetfile({'*.jpg'},...
'Pick 3 files',...
'MultiSelect', 'on');
%initialisation for which image to display after selection is made.
k = 1;
%dicern the number of images that where selected
num_imgs = length(filename);
%create string of full path to first image in selection and display
%the image
img1 = strcat(pathname, filename{k});
axes(handles.axes1);
imshow(img1);
function pushbutton2_Callback(hObject, eventdata, handles)
global k num_imgs pathname filename
%using global values of k create if statement to stop scrolling beyond the
%number of available images.
if k > num_imgs
%if the index value of the image to be displayed is greater than the
%number available default to the last image in the list
k = num_imgs;
else
%iterate upwards with each click of pushbutton2 to display the next
%image in the series.
k = k + 1;
img1 = strcat(pathname, filename{k});
axes(handles.axes1);
imshow(img1);
end
function pushbutton3_Callback(hObject, eventdata, handles)
global k num_imgs pathname filename
if k < 1
%if the index value of the image to be displayed is less than 1
%default to the first image in the list
k = 1;
else
k = k - 1;
img1 = strcat(pathname, filename{k});
axes(handles.axes1);
imshow(img1);
end
EDIT2: @user3755632 i'm not sure i understand. filename is a string and you can feed strings into imshow to display the image as long as the string includes the file name and the path if it is located outside the working directory. are you not using uigetfile to select the images? (can't comment on question due to lack of reputation)