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

답변 (1개)

Mohammad Sami
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
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 CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by