Randomly selecting images from a directory

17 Ansichten (letzte 30 Tage)
AK
AK am 25 Mai 2021
Beantwortet: Image Analyst am 25 Mai 2021
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!

Akzeptierte Antwort

J. Alex Lee
J. Alex Lee am 25 Mai 2021
Use "dir" and "randperm"
  4 Kommentare
J. Alex Lee
J. Alex Lee am 25 Mai 2021
eagle eyes! yea, i have nothing really to add to what Jan answered in previous post.
AK
AK am 25 Mai 2021
Thank you I was able to get it working!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Image Analyst
Image Analyst am 25 Mai 2021
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

Kategorien

Mehr zu File Operations finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by