what is the meaning for variable of .mat file

Hi, I have two colour image in .jpg. How can I convert them into 1 .mat file with only 1 variable like 2x28x28 array.
here is the code that i have try, but it generate 2 variable as below
  • pic1 = imread('image_0001.jpg');
  • pic1 = imresize(pic1, [28, 28]);
  • pic2 = imread('image_0002.jpg');
  • pic2 = imresize(pic2, [28, 28]);
  • save('BothPics.mat', 'pic1', 'pic2');

 Respuesta aceptada

Image Analyst
Image Analyst el 7 de Mzo. de 2015
bothPics = cat(3, pic1, pic2); % Create 28x28x2 array
save(('BothPics.mat', 'bothPics');

2 comentarios

Image Analyst
Image Analyst el 7 de Mzo. de 2015
Soon's "Answer" moved here because it's not an Answer to the original question but a reply to me:
thank for your reply and answer.
  1. just to confirm that the number "3" are three slices/color channels for each image?
  2. How do I restore/display these two images separately from .mat file. My current .mat file is 28x28x6 after execute the command above.
Image Analyst
Image Analyst el 7 de Mzo. de 2015
Editada: Image Analyst el 7 de Mzo. de 2015
Soon,
1. No, 3 means that you're concatenating in the third dimension. You gave what I assumed were two 28-by-28 2-D grayscale images. It could just as well have been 32 multispectral images and it still would have been 3, not 32.
2. You evidently had 2 color images. I don't know why you wanted to combine these into a single 3D image instead of keeping them as 2 separate 3D images. This is why you had 6 color planes along your z direction - 3 from one image and another 3 from the other image. 3+3=6. Why not just save and recall them separately? They can still be stored in one mat file:
save('mydata.mat', 'pic1', 'pic2');
To recall
storedStructure = load('mydata.mat');
pic1 = storedStructure.pic1;
pic2 = storedStructure.pic2;

Iniciar sesión para comentar.

Más respuestas (2)

Soon Fei Fong
Soon Fei Fong el 8 de Mzo. de 2015

0 votos

Hi, The reason that I desire to combine them is because currently I working on object classification using deep learning. I found an deep learning example (CNN) which using MNIST database, the mnist.mat file have 1 variable with array 60000x784 format. what I know is there have 60000 .jpg images with 28x28(784) for each. So I desire to substitute the mnist.mat with my own database and train the network. So is it no way to separate out the image from an 28x28x6 .mat file?

1 comentario

You can save things in a structure array and save that.
allImages(1).pic = pic1;
allImages(2).pic = pic2;
% and so on...
save('mydata.mat', 'allImages')

Iniciar sesión para comentar.

Soon Fei Fong
Soon Fei Fong el 9 de Mzo. de 2015

0 votos

I will get something as below:
Can I get something like this ? 2 mean 2 images, 784(28x28).
  • a 2x784 uint8

Categorías

Más información sobre Read, Write, and Modify Image en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Mzo. de 2015

Respondida:

el 9 de Mzo. de 2015

Community Treasure Hunt

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

Start Hunting!

Translated by