Info

この質問は閉じられています。 編集または回答するには再度開いてください。

reading multiple imgaes from folder in a sequence

1 回表示 (過去 30 日間)
Iram Shahzadi
Iram Shahzadi 2018 年 11 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I am using following code to read multiple images from a source folder, rotate them and save in target folder. However the images are not read in same sequence as they are in source folder. I want the images to be processed one by one in sequence from source folder. Can anyone please help me to identify the issue with this code.
folder = 'E:\Source folder\';
filePattern = fullfile(folder, '*.png');
myFiles = dir(filePattern);
for k = 1 : length(myFiles)
fullFileName = fullfile(myFiles(k).folder, myFiles(k).name);
imageArray = imread(fullFileName);
I1=(imageArray);
figure
imshow(I1);
I2=I1';
figure
imshow(I2);
Res='E:\target folder';
mkdir(Res);
baseFN= sprintf('%d.png',k);
fullFileName = fullfile(Res,baseFN)
imwrite(I2,fullFileName);
end

回答 (1 件)

KSSV
KSSV 2018 年 11 月 14 日
編集済み: KSSV 2018 年 11 月 14 日
Have a look on this file exchange function: natsort
  1 件のコメント
Iram Shahzadi
Iram Shahzadi 2018 年 11 月 15 日
folder = 'E:\Source folder\';
filePattern = fullfile(folder, '*.png');
myFiles = dir(filePattern);
myFiles = sort({myFiles.name});
for k = 1 : length(myFiles)
fullFileName = string(fullfile(folder, myFiles(k)));
imageArray = imread(fullFileName);
I1=(imageArray);
imshow(I1);
I2=I1';
imshow(I2);
Res='E:\target folder';
mkdir(Res);
baseFN= sprintf('%d.png',k);
fullFileName = fullfile(Res,baseFN);
imwrite(I2,fullFileName);
Thanks for help @KSSV. slight changes I made to above piece of code. Simply using 'sort' function of matlab can help to read image sequentially.

Community Treasure Hunt

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

Start Hunting!

Translated by