필터 지우기
필터 지우기

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