필터 지우기
필터 지우기

how can i read multiple images one by one from a particular folder?

조회 수: 1 (최근 30일)
apurva mane
apurva mane 2015년 2월 23일
편집: Stalin Samuel 2015년 2월 23일
we are doing project on sorting of black colored raisins by using image processing. For that we need reading of multiple images from folder and compare them with given database.

답변 (1개)

Stalin Samuel
Stalin Samuel 2015년 2월 23일
편집: Stalin Samuel 2015년 2월 23일
dirName = '---your directory-----'
dirData = dir(dirName); %Get the data for the current directory
dirIndex = [dirData.isdir]; %Find the index for directories
fileList = {dirData(~dirIndex).name}'; % Get a list of the files
if ~isempty(fileList)
fileList = cellfun(@(x) fullfile(dirName,x),... % Prepend path to files
fileList,'UniformOutput',false);
end
subDirs = {dirData(dirIndex).name}; % Get a list of the subdirectories
validIndex = ~ismember(subDirs,{'.','..'}); % Find index of subdirectories
x = 0 % that are not '.' or '..'
for iDir = find(validIndex)
% Loop over valid subdirectories
x=x+1
nextDir = fullfile(dirName,subDirs{iDir}); % Get the subdirectory path
fileList = [fileList; getAllFiles(nextDir)]; % Recursively call getAllFiles
end
nfil=size(fileList)
for m = 1:nfil
Currrent_Image= imread(sprintf('%s',fileList{m,1}));
end
  댓글 수: 1
Stephen23
Stephen23 2015년 2월 23일
편집: Stephen23 2015년 2월 23일
This is a good answer, but it is unreadable. Consider:
  1. Put comments before each line, not at the end of the line.
  2. Don't use # to indicate a comment.
  3. Keep code lines together as much as possible
  4. Be consistent with indenting.
It could be significantly improved by removing the reference to multiple sub-directories and the function getAllFiles, which is not a standard MATLAB function, and this reference is unlikely to help a new user to read their files. In fact the whole for loop should be removed.
If this was readable and the for loop removed, then I would consider voting for it, as it does contain good practices such as using fullfile.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by