Loading images from a .MAT file
Mostrar comentarios más antiguos
i have this function which i used to save a folder of images into a .MAT file as a database. Now i want to load the images from the data to use them but its a struct so i tried converting using struct2cell and that didn't get me anywhere. I seen about 3 different ways to get this to work but non seem to work which made me thing maybe i saved them wrong?
So i want to make a loop that loads all images from this database. all images have the same dimensions and file type .jpg
folder = 'F:\matlab\face\data';
ListOfImageNames = {};
ImageFiles = dir([folder '/*.*']); % Get all files.
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder, name, extension] = fileparts(baseFileName);
extension = upper(extension);
% Let's save just those we are interested in:
switch lower(extension)
case {'.png', '.bmp', '.jpg', '.tif', '.avi'}
% Allow only PNG, TIF, JPG, or BMP images
ListOfImageNames = [ListOfImageNames baseFileName];
otherwise
end
end
save('F:\matlab\face\testimagebase.mat','ListOfImageNames');
Respuesta aceptada
Más respuestas (2)
poongothai rajan
el 23 de Abr. de 2014
0 votos
can u please anyone help how to convert the .mat file into image file..thanks in advance
Shaveta Arora
el 27 de Jun. de 2015
0 votos
i have .mat one file which is 1x1 struct. how to read the image from this.
1 comentario
Image Analyst
el 27 de Jun. de 2015
Call load to read the mat file into a structure:
storedStruct = load(yourFileName);
Now, if you had a structure that you stored when you called save() to create the mat file, then that structure will be a field of the storedStuct variable. You can extract it into a variable if you want:
myStruct = storedStruct.myStruct;
Categorías
Más información sobre Convert Image Type en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!