Randomly selecting images from a directory

Hello,
I have a directory of 10000 JPEG files. I want to write a script that can randomly select 100 images from this directory and save these images to a new folder on my desktop. How do I do this?
Thank you!

 採用された回答

J. Alex Lee
J. Alex Lee 2021 年 5 月 25 日

0 投票

Use "dir" and "randperm"

4 件のコメント

AK
AK 2021 年 5 月 25 日
Thanks! how would use randperm to select the file the index corresponds to?
Rik
Rik 2021 年 5 月 25 日
編集済み: Rik 2021 年 5 月 25 日
Have you read the documentation for randperm? What did you try? Also, what makes this different from you previous question?
J. Alex Lee
J. Alex Lee 2021 年 5 月 25 日
eagle eyes! yea, i have nothing really to add to what Jan answered in previous post.
AK
AK 2021 年 5 月 25 日
Thank you I was able to get it working!

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 5 月 25 日

0 投票

This is how I'd do it:
fileList = dir('*.jp*');
numFiles = length(fileList)
orderToUse = randperm(numFiles);
for k = 1 : numFiles
% Get what random index this one is.
index = orderToUse(k);
% Construct the full filename.
fullFileName = fullfile(fileList(index).folder, fileList(index).name);
fprintf('Processing #%d of %d:\n which is file #%d in the list : %s\n',...
k, numFiles, index, fullFileName);
% Now do something with the file....
end

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

タグ

質問済み:

AK
2021 年 5 月 25 日

回答済み:

2021 年 5 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by