Select an image folder in GUI

1 visualización (últimos 30 días)
as hz
as hz el 8 de Abr. de 2013
Comentada: Image Analyst el 6 de Abr. de 2017
Hi,
I have problem to select an image folder in GUI. My GUI functions like that, when I push the selectSourceButton button I select the folder. Later, when I push the startButton the program should read all the files.
It seems my problem is how to transfer the Source folder information between the functions. I hope anyone can help me.
Thank you.
function selectSourceButton_Callback(hObject, eventdata, handles)
% hObject handle to selectSourceButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.output = hObject;
sourceFolder = uigetdir();
textLabel = sprintf('%s', sourceFolder);
set(handles.sourceFolderEdit, 'string', textLabel);
myFolder = get(handles.sourceFolderEdit, 'String');
guidata(hObject, handles);
function startButton_Callback(hObject, eventdata, handles)
handles.output = hObject;
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end

Respuesta aceptada

Image Analyst
Image Analyst el 8 de Abr. de 2013
I'd just use one folder - not myFolder and not sourceFolder. Just pick one and attach it to handles.
function selectSourceButton_Callback(hObject, eventdata, handles)
sourceFolder = uigetdir();
set(handles.sourceFolderEdit, 'string', sourceFolder );
handles.sourceFolder = sourceFolder;
guidata(hObject, handles);
function startButton_Callback(hObject, eventdata, handles)
if ~isdir(handles.sourceFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', handles.sourceFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(handles.sourceFolder, '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile(handles.sourceFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
imageArray = imread(fullFileName);
end
  5 comentarios
Ishwarya Subramanian
Ishwarya Subramanian el 6 de Abr. de 2017
I'm using the above code..but i didnt get the images in sequential order. Can anyone please solve this
Image Analyst
Image Analyst el 6 de Abr. de 2017
Not sure what sorting order you want. Perhaps it's this: http://blogs.mathworks.com/pick/2014/12/05/natural-order-sorting/

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by