There are two main folders which have 50 sub-folder each. In sub-folders there are tiff images. How to read images from sub-folders.

1 次查看(过去 30 天)
I have two folders with names M-001 and M-002 and in each of the main folder, I have sub-folders which contain tiff images. How could I read both the main folders at the same time to read all the tiff images.
Thanks.
  2 个评论
Md
Md 2017-5-4
编辑:Md 2017-5-4
Thank you. I am trying something like this:
clc
mainDirectory = {'C:\Users\amazon\Desktop\Acq_001','C:\Users\amazon\Desktop\Acq_002'};
subDirectory = dir([mainDirectory '/L*']);
for m = 1:length(subDirectory)
subFolder = dir([mainDirectory '\' subDirectory(m).name '\*.tif']);
for i = 1:length(subFolder)
filename = strcat([mainDirectory '\' subDirectory(m).name '\' subFolder(i).name]);
I=imread(filename); %% Read Image
end
end
but I am getting an error Function is not defined for 'cell' inputs.

请先登录,再进行评论。

采纳的回答

Prannay Jain
Prannay Jain 2017-5-1
% Create a cell array of pre-defined directory locations
folders = {'/media/DATA/M-001';'/media/DATA/M-002'};
for i = 1:numel(folders) % Loop through all folders in pre-defined cell array
myFolder = folders{i}; % Set folder to be processed
% Extract all sub-folders from the current folder
d = dir(myFolder); % List folder contents
idxs = [d(:).isdir]'; % Logical vector of directory contents that are folders
names = {d(:).name}'; % List of the names of all contents of the directory
folders = names(idxs); % Index into 'names' using 'idxs'
folders(ismember(folders,{'.','..'})) = []; % Remove '.' and '..' if they exist
for i = 1:numel(folders) % Loop through all sub-folders in cell array
myFolder = folders{i}; % Set folder to be processed
% Add file processing commands here
end
end

更多回答(0 个)

类别

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