How to sort the files obtained by ImageDatastore?
Afficher commentaires plus anciens
I used imageDatastore to obtain the directory of all the images in a folder.
Images = 'D:\Google Drive\MARYLAND\ENPM808 Independent Study\Independent Study\3D_map_poses\rgb';
rgb_image = imageDatastore(fullfile(Images),'IncludeSubfolders',false,'FileExtensions','.png','LabelSource','none');
But I realized that the order of the directories is not the same as the File Explorer and hence the generated video after processing the frames is erroneous.

Instead I need this to be in increasing order, (e.g. 1,3,7,9,10,16,...).
How can I do this? Thanks!
5 commentaires
KALYAN ACHARJYA
le 26 Août 2018
Question is not clear for me.
"How to sort the directories obtained by ImageDatastore?"
I suspect that you really meant to write "...sort the files..."
Your screenshot shows .png files with different names that are not in numeric order. The directories appear to be all identical.
Canberk Suat Gurel
le 26 Août 2018
Image Analyst
le 26 Août 2018
So, did Stephen's utility, described below in his answer, work for you? (Did you even see it?) If so, you can mark it as "Accepted" to give him credit for helping you.
Canberk Suat Gurel
le 26 Août 2018
Réponse acceptée
Plus de réponses (1)
A very neat and simple approach (from an answer by Pranay Koppula here) is to apply NATSORTFILES() to the FILES property of the IMAGEDATASTORE object:
obj = imageDatastore(..);
obj.Files = natsortfiles(obj.Files);
The function NATSORTFILES() can be downloaded here:
As Pranay Koppula wrote, it is unclear if this affects other attributes of the object.
1 commentaire
Nazmul Hasan
le 6 Jan 2023
I also used the same appraoch and got perfect results.


Catégories
En savoir plus sur Image Arithmetic dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!