Effacer les filtres
Effacer les filtres

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

1 vue (au cours des 30 derniers jours)
apurva mane
apurva mane le 23 Fév 2015
Modifié(e) : Stalin Samuel le 23 Fév 2015
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.

Réponses (1)

Stalin Samuel
Stalin Samuel le 23 Fév 2015
Modifié(e) : Stalin Samuel le 23 Fév 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 commentaire
Stephen23
Stephen23 le 23 Fév 2015
Modifié(e) : Stephen23 le 23 Fév 2015
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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by