How can user select a directory to pull images from?

1 visualización (últimos 30 días)
Caitlin Taylor
Caitlin Taylor el 14 de Jun. de 2018
Comentada: Stephen23 el 14 de Jun. de 2018
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 comentario
Stephen23
Stephen23 el 14 de Jun. de 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:

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 14 de Jun. de 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');

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by