Just get all the files in the directory and keep only the ones with the extensions you want. You could even get the list of all valid image extension from imformats:
extensions = {'bmp', 'tif', jpg'};
registry = imformats;
extensions = [registry.ext];
allfiles = dir(fullfile(somepath, '*.*'));
isimage = arrayfun(@(f) ~f.isdir && any(strcmp(regexp(f.name, '\.(.*)$', 'tokens', 'once'), extensions')), allfiles);
imagefiles = allfiles(isimage);
for imagefile = imagefiles'
Im = imread(fullfile(somepath, imagefile.name));
...
end
Best Answer