简体   繁体   中英

how to import multiple folders containing images ,in matlab?

I want to select just folders instead of selecting each images individually. for example I have 8 folders and each of then including 72 dicom images. my purpose is to just select 8 folders and save each folder images in one row of array. I have written this code but it only read multiple images in one folder. please help me to solve my problem.

function cell=readfromfile()
[filename, pathname] = uigetfile('*.*', 'Pick folder','Multiselect','on');
img_dir =pathname;
filename(1);
    N =length(filename);
strfile =filename{1};
img = dicomread(fullfile(img_dir, strfile));
siz_img = size(img);
% create result matrix:
% load all the remaining images and put them in the matrix
for ii=2:N
    strfile =filename{ii};
    I{ii}=dicomread( fullfile(pathname, filename{ii}) );
end

Neither uigetfile or uigetdir allow you to select multiple folders, so I would probably just use uigetdir to get the path of the selected folder. If you know you have 8 folders you can just call this in a loop 8 times (making sure not to overwrite you data). If you don't know how many folders you have you may need to so something cunning, but I haven't really thought about it.

I would then use dir to get a list of the files in your folders. You may need to use something like dir('*.png'); if you have any subfolders or other files you don't want to read in the folder.

Your reading of the images looks fine from there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM