How can user select a directory to pull images from?
1 次查看(过去 30 天)
显示 更早的评论
I have written a program/gui to take images and allow a user to define a start frame and an index for which images are desired and file these certain images in a new folder and location. Previously, I was just opening the images up in my directory and "add(ing) to path". But I am trying to allow the user to tell you where you get the images and the way I am doing gives an error. I am leaving out some code that I didn't think was relevant. I am including the error at the bottom. Any advice on how to get the user to be able to enter in the location of the original folder/files of interest would be appreciated.
f= figure;
whatpath = 'Where are your unindexed images?';
BackSlash = '\';
wdinput = uicontrol(f,'style', 'pushbutton','string', whatpath,
'position', [100,350,360,20],
'callback', 'whatpath = uigetdir;[filepath,whatdir]=fileparts(whatpath);WD = strcat(filepath,BackSlash,whatdir);set(gcbo,''String'',WD)');
whatdirectory = strcat(WD,'\',Ftype);
imagefiles = dir(whatdirectory);%Find the jpg files
nfiles = length(imagefiles);%How many files are there
for ii=start:nfiles
currentfilename = imagefiles(ii).name;
currentimage = imread(currentfilename);
images{ii} = currentimage;
end
Error using imread>get_full_filename (line 516)
File "Image_S001_0001.tif" does not exist.
Error in imread (line 340)
fullname = get_full_filename(filename);
Error in EveryNthforDIC (line 101)
currentimage = imread(currentfilename);
1 个评论
Stephen23
2018-6-14
'callback', 'whatpath = uigetdir;[filepath,whatdir]=fileparts(whatpath);WD = strcat(filepath,BackSlash,whatdir);set(gcbo,''String'',WD)'
Do NOT define the callback as a char vector. The MATLAB documentation specifically advises against doing this: "Defining a callback as a character vector is not recommended. The use of a function specified as function handle enables MATLAB to provide important information to your callback function." You should use a function handle. And pass the data properly using guidata or nested functions:
回答(1 个)
Image Analyst
2018-6-14
Try this:
% User wants to specify a folder where the image files live.
startingFolder = pwd; % or wherever you want.
folder = uigetdir(startingFolder, 'Select folder');
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!