The code shown only saves the names of the image files and not the image data itself. This is because the variable 'ListOfImageNames' is a cell array of names, and SAVE just stores it in the MAT-file as such.
If you want to save the actual image data, you should call IMREAD on each image to get its data into MATLAB, and then use SAVE for the actual data. One way to do this is to create a struct and add fields to this struct as you find and read images. Here's how that might look, based off of your code:
function saveImages(folder)
ListOfImageNames = {};
ImagesToSave = struct();
ImageFiles = dir([folder '/*.*']);
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder, name, extension] = fileparts(baseFileName);
extension = upper(extension);
switch lower(extension)
case {'.png', '.bmp', '.jpg', '.tif', '.avi'}
ListOfImageNames = [ListOfImageNames baseFileName];
ImagesToSave.(name) = imread(baseFileName);
otherwise
end
end
save('testimagebase.mat','-struct','ImagesToSave');
Now if you call LOAD on your MAT-file, you will be returned the same structure that you originally saved, with a field for each image containing its data:
>> saveImages(pwd)
>> myimages=load('testimagebase.mat')
myimages =
image1: [2178x2448x3 uint8]
myimage2: [676x1088x3 uint8]
Best Answer