Randomly shuffle folder of images and save it

4 ビュー (過去 30 日間)
Elysi Cochin
Elysi Cochin 2022 年 8 月 3 日
回答済み: KSSV 2022 年 8 月 3 日
I have 5 images named 1.jpg, 2.jpg ... 5.jpg
I wanted to create a random number of 1 to 5 and write these images in the random number order, as 6.jpg, 7.jpg ... 10.jpg
Suppose the random order generated is 3, 1, 4, 5, 2
I wanted to write 3.jpg as 6.jpg; 1.jpg as 7.jpg; ..... 2.jpg as 10.jpg
Now i have total 10 images. Again I want to create a random number of 1 to 10 and write these images in the random number order, as 11.jpg, 12.jpg ... 20.jpg
Till I get 25 images in total in the folder

採用された回答

KSSV
KSSV 2022 年 8 月 3 日
imgFiles = dir('*.jpg') ;
N = length(imgFiles) ;
n = randsample(1:10,N) ; % you can out your limits here
for i = N
I = imread(imgFiles(i).name) ;
fname = strcat(num2str(n(i)),'.jpg') ;
imwrite(I,fname) ;
end

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by