calculate number of images
13 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Lalit Patil
el 1 de En. de 2013
Comentada: Walter Roberson
el 2 de Ag. de 2015
d = dir('*.bmp');
n = length(d);
i have a folder and i am calculating number of images in that folder, but it calculates only .bmp images.. Some times there will be png images also.. But whenever there will be images it will be of same extension. So, i want to make general code.. Whatever the images, it should calculate..
so, what should be the change in first line of code, if there are png images..?
0 comentarios
Respuesta aceptada
Walter Roberson
el 1 de En. de 2013
d = dir('*.bmp')
6 comentarios
Avnish Patel
el 2 de Ag. de 2015
Editada: Avnish Patel
el 2 de Ag. de 2015
Lalit Patil, After executing following code
d = dir('.');
n = length(d)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/180111/image.png)
You can see in above image, In My Folder, (5 images) + (3 ".m") files =8 further n=10
Matlab include 1 count for '.' and another 1 count for '..' So 2 count is extra than available contents/files in given folder.
Walter Roberson
el 2 de Ag. de 2015
d([d.isdir]) = [];
will remove the directory entries no matter which order they appear in and no matter what their names.
Más respuestas (1)
Image Analyst
el 1 de En. de 2013
Here's a snippet of code I use to load just the desired extensions. If you use this you won't have to worry about what file types are in the folder because the code handles all that - it will load just the files you know in advance that you are interested in into the listbox.
% Get a list of all files in the folder.
filePattern = fullfile(folder, '/*.*');
ImageFiles = dir(filePattern);
% Filter the list to pick out only files of
% file types that we want (image and video files).
ListOfImageNames = {}; % Initialize
for Index = 1:length(ImageFiles)
% Get the base filename and extension.
baseFileName = ImageFiles(Index).name;
[folder, name, extension] = fileparts(baseFileName);
% Examine extensions for ones we want.
extension = upper(extension);
switch lower(extension)
case {'.png', '.bmp', '.jpg', '.tif'}
% Keep only PNG, BMP, JPG, TIF image files.
ListOfImageNames = [ListOfImageNames baseFileName];
% otherwise
end
end
% Now we have a list of validated filenames that we want.
% Send the list of validated filenames to the listbox.
set(handles.lstImageList, 'string', ListOfImageNames);
% Need to set this to something smaller than the number it used to be,
% because if we deleted some files and called this then the old value could be beyond the end of the list
% and that would cause the listbox to not be displayed.
set(handles.lstImageList, 'value', []);
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!