How can user select a directory to pull images from?

조회 수: 2 (최근 30일)
Caitlin Taylor
Caitlin Taylor 2018년 6월 14일
댓글: Stephen23 2018년 6월 14일
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
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
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');

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by