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 Exchange에서 Convert 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