how can i read multiple images one by one from a particular folder?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
Antworten (1)
Stalin Samuel
am 23 Feb. 2015
Bearbeitet: Stalin Samuel
am 23 Feb. 2015
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 Kommentar
Stephen23
am 23 Feb. 2015
Bearbeitet: Stephen23
am 23 Feb. 2015
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.
Siehe auch
Kategorien
Mehr zu Environment and Settings finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!