How to load a set of images which have the same name in different subfolders for further image processing

1 visualización (últimos 30 días)
I have a parent folder.
The parent folder has several subfolders named 01, 02, 03, ...
Each subfolder have several images named tile_x001_y001, tile_x001_y002, tile_x001_y003, tile_x002_y001, tile_x002_y002, tile_x002_y003 ....
As you can see, the name of image indicates the information of image position. It would be used for image stitch after image processing.
It should be noted that the name of images in all subfolders is the same, as shown in the pictures.
Now I want to load the images with the same name in different subfolders for further image processing.
How can I do that? Does anybody can give me any suggestion?
Thank you very much in advance.
Gui

Respuestas (1)

Mohammad Sami
Mohammad Sami el 3 de Sept. de 2020
You can use the dir function to get the list of all the files in the folder and subfolder
listofallpngfiles = dir(fullfile(pwd,'**','*.png'));
listofallpngfiles = struct2table(listofallpngfiles);
fileswithsamename = unique(listofallpngfiles.name);
for i = 1:length(fileswithsamename)
name = fileswithsamename{i};
idx = strcmp(listofallpngfiles.name,name);
files = listofallpngfiles(idx,:);
filepaths = fullfile(files.folder,files.name);
% do something with the file
end
  3 comentarios
Mohammad Sami
Mohammad Sami el 3 de Sept. de 2020
You can use the montage to display multiple images on a figure. https://www.mathworks.com/help/images/ref/montage.html
Another option could be to use imtile function to create a tiled image from multiple images and then use imshow to show it.
https://www.mathworks.com/help/matlab/ref/imtile.html

Iniciar sesión para comentar.

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by