フィルターのクリア

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 Center および File ExchangeFile Operations についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by