Select folders one by one using imageDatastore function

2 Ansichten (letzte 30 Tage)
Mesho
Mesho am 29 Mai 2024
Kommentiert: Mesho am 30 Mai 2024
Dear all,
I have a "Parent_Folder" and inside it I have another 5-subfolders that contain images inside them: Folder_1, Folder_2, Folder_3, Folder_4, Folder_5.
By using "imageDatastore" function, I want to make a loop in order to chose folders one by one, something like this:
for i = 1: 5
%in the 1st loop when i = 1
Group_A = Folder_1
Group_B = Folder_2, Folder_3, Folder_4, Folder_5
%in the 2nd loop when i = 2
Group_A = Folder_2
Group_B = Folder_1, Folder_3, Folder_4, Folder_5
%in the 3rd loop when i = 3
Group_A = Folder_3
Group_B = Folder_1, Folder_2, Folder_4, Folder_5
and so on.
Any idea how to make such a loop?
best regards,
Mesho

Akzeptierte Antwort

Sai Pavan
Sai Pavan am 29 Mai 2024
Hello,
I understand that you have a "Parent_Folder" and want to have five sets of "Group_A" and "Group_B" subfolder groups such that "Group_A" has one subfolder and "Group_B" has the rest of the four folders to store the images inside them in a "imageDatastore" with the help of their paths.
Please refer to the below code snippet that illustrates this task:
parentFolderPath = 'Parent_Folder';
subfolders = {'Folder_1', 'Folder_2', 'Folder_3', 'Folder_4', 'Folder_5'}; % List of subfolder names
for i = 1:length(subfolders)
% Group_A will be the current subfolder
groupAPath = fullfile(parentFolderPath, subfolders{i});
Group_A = imageDatastore(groupAPath, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
% Group_B will be all other subfolders
groupBPaths = subfolders([1:i-1, i+1:end]); % Exclude current folder
groupBPaths = fullfile(parentFolderPath, groupBPaths); % Full paths
Group_B = imageDatastore(groupBPaths, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
end
Please refer to the below documentation to learn more about:
Hope it helps!

Weitere Antworten (0)

Kategorien

Mehr zu Images finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by