How to sort images from a folder in subfolders using the data from a excel/ .mat file?

2 ビュー (過去 30 日間)
Niculai Traian
Niculai Traian 2018 年 11 月 11 日
コメント済み: TADA 2018 年 11 月 11 日
Hello, I have a dataset with flowers (8000 pictures) and i need to sort them in subfolders (rose, tulip, etc) and i have the imagelabel.mat witch is a double value (1x8000) where i can see how many examples are for each class. How can i sort them without having to create folders and copy-paste the images in folders? A code example would help a lot. Thanks

採用された回答

TADA
TADA 2018 年 11 月 11 日
編集済み: TADA 2018 年 11 月 11 日
You need to iterate through your dataset and ensure the necessary subfolder exist, then move the file
% concat sub folder path
subfolderPath = [parentDirPath '\' flowerName];
% check if subfolder exists
if ~exist(subfolderPath, 'dir')
% create subfolder
mkdir(subfolderPath);
end
% move file from original path to subfolder
[status, msg] = movefile([parentDirPath '\' fileName], [subfolderPath '\' fileName]);
% check if file moved successfully
if ~status
% log error
end
That's the general idea
  4 件のコメント
Niculai Traian
Niculai Traian 2018 年 11 月 11 日
ok, but do i need to use
[status, msg] = movefile([parentDirPath '\' fileName], [subfolderPath '\' fileName]);
for each image? they are named image_0001 and so on. I was hoping that the script will sort them automatically by using the data i provided in .mat file
TADA
TADA 2018 年 11 月 11 日
You will have to loop through your data and do that for each file
for i = 1:length(yourData)
% use above code
end
I don't know the names of your variables or how your data is saved or anything else about it.
That's the general idea

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by