How can user select a directory to pull images from?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commento
Stephen23
il 14 Giu 2018
'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:
Risposte (1)
Image Analyst
il 14 Giu 2018
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 Commenti
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!