필터 지우기
필터 지우기

how to read image from folder with many subfolder directories

조회 수: 14 (최근 30일)
riya shahrin
riya shahrin 2020년 3월 28일
댓글: Image Analyst 2022년 11월 16일
I need to read images from many subfolders in a fixed folder for further processing of image in a loop.
For better understaning a flowchart is given here.
My matlab code and datasetImage folder are in same folder.I need to read image .tif image in every subfolders.For note there are some folders which is missing like IM005.It will be very helpfull if anyone can help me to read ***.TIF file for further processing.Thanks in advance.

채택된 답변

Image Analyst
Image Analyst 2020년 3월 28일
Try this:
% Get a list of all TIFF files in the current folder AND in all subfolders below it.
fileListing = dir('**/*.tif*');
% For each file we learned of, process it...
numberOfFiles = length(fileListing)
for k = 1 : numberOfFiles
% Get the full filename (folder & base file name) of this particular file.
thisFullFileName = fullfile(fileListing(k).folder, fileListing(k).name);
fprintf('Processing image %d of %d : %s...\n', k, numberOfFiles, thisFullFileName);
% Now do something with this image. For example, display it:
% First read image into a variable.
thisImage = imread(thisFullFileName);
% Now display it.
imshow(thisImage);
drawnow; % Force immediate refresh of screen.
% Now perform other operations on the image if you want...
end
  댓글 수: 1
Image Analyst
Image Analyst 2020년 3월 28일
It doesn't matter if some files or folders are "missing" - the fileListing will contain a list of only those files that are there and process only those. You can put your feature extraction below the line of code that says "Now perform other operations...".

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 3월 28일
Try something like this
files = dir('**/*.tiff');
for i=1:numel(files)
filename = fullfile(files(i).folder, files(i).name);
% do preocessing on images. for example:
im = imread(filename);
% more code
end
  댓글 수: 6
Zesen
Zesen 2022년 11월 16일
thank you handsome man!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by