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 visualización (últimos 30 días)
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 comentarios
Md
Md el 4 de Mayo de 2017
Editada: Md el 4 de Mayo de 2017
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.

Iniciar sesión para comentar.

Respuesta aceptada

Prannay Jain
Prannay Jain el 1 de Mayo de 2017
% 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

Más respuestas (0)

Categorías

Más información sobre File Operations en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by