how can i read multiple images one by one from a particular folder?
1 次查看(过去 30 天)
显示 更早的评论
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
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
2015-2-23
编辑:Stephen23
2015-2-23
This is a good answer, but it is unreadable. Consider:
- Put comments before each line, not at the end of the line.
- Don't use # to indicate a comment.
- Keep code lines together as much as possible
- 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 Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!