How to load a set of images which have the same name in different subfolders for further image processing
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
Mohammad Sami
2020 年 9 月 3 日
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 件のコメント
Mohammad Sami
2020 年 9 月 3 日
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
参考
カテゴリ
Help Center および File Exchange で File Operations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!