Sort images in pixelLabelDatastore in serial order

3 vues (au cours des 30 derniers jours)
Eberechi ICHI
Eberechi ICHI le 12 Oct 2022
Réponse apportée : Tushar le 21 Fév 2023
I was able to sort the images in imageDatastore in the right order using the natsortfiles function.
Please how do i do same for a pixelLabelDatastore. it's showing this error when i do same.
'Setting the Files property is not supported. Please create a new pixelLabelDatastore instead'.
X_test = imageDatastore(test_image,'IncludeSubfolders',true,'LabelSource','foldernames');
X_test.Files = natsortfiles(X_test.Files);
Y_test = pixelLabelDatastore(test_label,classNames,labelIDs,'IncludeSubfolders',true);
Y_test.Files = natsortfiles(Y_test.Files);

Réponses (1)

Tushar
Tushar le 21 Fév 2023
Hi,
A pixelLabelDatastore stores files in lexicographical order. For example, if you have twelve files named 'file1.jpg', 'file2.jpg', … , 'file11.jpg', and 'file12.jpg', then the files are stored in this order:
'file1.jpg'
'file10.jpg'
'file11.jpg'
'file12.jpg'
'file2.jpg'
'file3.jpg'
...
'file9.jpg'
In contrast, an imageDatastore stores files in the order they are added to the datastore. If you simultaneously read a ground truth image and pixel label data, then you may encounter a mismatch between the images and the labels. If this occurs, then rename the pixel label files so that they have the correct order. For example, rename 'file1.jpg', … , 'file9.jpg' to 'file01.jpg', …, 'file09.jpg'.
Now, coming to the issue what you are facing, it is that setting the files property for imageDataStore is supported, while not supported yet for pixelLabelDatastore.
(I reproduced the same issue, and used sort_nat to sort naturally : Natural Sort)
A possible workaround for your situation is to sort the values of pixelLabelDataStore into a separate variable or a new instance, and use it externally without changing the files property of the current pixelLabelDataStore instance.
You can try something like:
newVar = sort_nat(Y_test.Files);
% or newVar = natsortfiles(Y_test.Files);
% Now, you can use the sorted values correspondingly
Hope it helps!!

Catégories

En savoir plus sur Convert Image Type dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by