what is the meaning for variable of .mat file

16 次查看(过去 30 天)
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');

采纳的回答

Image Analyst
Image Analyst 2015-3-7
bothPics = cat(3, pic1, pic2); % Create 28x28x2 array
save(('BothPics.mat', 'bothPics');
  2 个评论
Image Analyst
Image Analyst 2015-3-7
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 2015-3-7
编辑:Image Analyst 2015-3-7
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;

请先登录,再进行评论。

更多回答(2 个)

Soon Fei Fong
Soon Fei Fong 2015-3-8
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 个评论
Image Analyst
Image Analyst 2015-3-8
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')

请先登录,再进行评论。


Soon Fei Fong
Soon Fei Fong 2015-3-9
I will get something as below:
Can I get something like this ? 2 mean 2 images, 784(28x28).
  • a 2x784 uint8

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by