- "fullfile: function: https://www.mathworks.com/help/matlab/ref/fullfile.html
- "imageDatastore: function: https://www.mathworks.com/help/matlab/ref/matlab.io.datastore.imagedatastore.html
Select folders one by one using imageDatastore function
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Sai Pavan
2024-5-29
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!
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!