MATLAB: How to read image files with specific filename pattern out from folder with subfolders using imagedatastore

image processingMATLAB

I have a folder of images with subfolders. The folder contains subfolders and each subfolder contains 4 views of an individual object. I want to work with 1 view of every object, which means I need only 1 image from every subfolder. Currently I use imagedatastore. What kind of Name-value pair argument can help with this?
For you to see the problem, this is my attempt:
location = 'C:\Users\CCS\Desktop\spproject\P-*.jpg';
imds = imageDatastore(location,'IncludeSubfolders',1);
Of course, the 'P-*.jpg' doesn't work, but that's what I want. I want the imds to read in only the files with the beginning part of the name ''P-'', from this folder with subfolders. Is it possible?

Best Answer

You can also pass paths to the required files
location = 'C:\Users\CCS\Desktop\spproject\**\P-*.jpg'; % ** will match all the subfolders
files = dir(location);
imds = imageDatastore(files);