Info

此问题已关闭。 请重新打开它进行编辑或回答。

How do I allow user to choose either a folder or an image(or selective images) to run the rest of the functions?

1 次查看(过去 30 天)
Currently it is able to select a folder but I want the users to have other options if they want to select an image/ selective images instead.
%% ACCESS ALL IMAGES IN THE FOLDER
selpath = uigetdir;
imageFolder = dir(fullfile(selpath,'\*.jpg'));
numfiles = length(imageFolder);
ori_roi = cell(numfiles, 1);
i = 1;
%% LOOP THROUGH ALL IMAGES IN THE FOLDER & RUN ALL THE 5 FUNCTIONS
for i=1:length(imageFolder)
tic
functionError = 0;
filename = fullfile(selpath,imageFolder(i).name);
originalImage = imread(filename);
fprintf("Image name: %s\n",imageFolder(i).name);
...
  3 个评论
Shu Yi Ho
Shu Yi Ho 2019-8-15
Thanks for the reply but it doesn't work for my case. Unable to see the individual images when i clicked on the folder.
Geoff Hayes
Geoff Hayes 2019-8-16
Shu - please clarify what you mean by unable to see the individual images. Where are you expecting to see them? Are you not seeing the files or are you expecting to see the actual image?

回答(1 个)

Walter Roberson
Walter Roberson 2019-8-16
choice = menu('How do you want to select images?', 'by folder', 'individual image');
switch choice
case 0
%user cancelled
return
case 1
%% ACCESS ALL IMAGES IN THE FOLDER
selpath = uigetdir;
if ~ischar(selpath)
%user cancelled
return
end
imageFolder = dir(fullfile(selpath,'*.jpg'));
filenames = fullfile(selpath, {imageFolder.name});
case 2
%% ACCESS ONE IMAGE IN A FOLDER
[selfile, selpath] = uigetfile({'*.jpg', '*.png', '*.tif', '*.*'}, 'Pick a file');
if ~ischar(selfile)
%user cancelled
return
end
filenames = {fullfile(selpath, selfile)};
otherwise
error('somehow choice is out of range??')
end
numfiles = length(filenames);
ori_roi = cell(numfiles, 1);
%% LOOP THROUGH ALL IMAGES IN THE FOLDER & RUN ALL THE 5 FUNCTIONS
for i=1:numfiles
tic
functionError = 0;
filename = filenames{i};
[~, basename, ~] = filepaths(filename);
originalImage = imread(filename);
fprintf("Image name: %s\n",basename);
...
ori_roi{i} = ....
toc
end

Community Treasure Hunt

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

Start Hunting!

Translated by