Question

How can I create a .mat file which holds a bunch of images in matlab?

I'm using the images as a training set, so figured it would be easier to load from a .mat than load 100+ images every time I run the program.

If I'm thinking about this the wrong way, please point me in the right direction. Thanks.

Was it helpful?

Solution

You can simply combine all images (each of which is a 3D matrix for color images) into a 4D matrix with last dimension is the total number. And save this 4D matrix to a .mat file for later loading.

For grayscale images, you only need to combine them into a 3D matrix as each of which is 2D.

As commented by @Divakar, you may need to combine them into a cell array if the sizes of the images are not consistent.


Edit: Suppose you have combined the images into a 3D/4D matrix called data, you can use save data; to save it into disk and use load data; to load it back.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top