what is the meaning for variable of .mat file

조회 수: 18 (최근 30일)
Soon Fei Fong
Soon Fei Fong 2015년 3월 7일
답변: Soon Fei Fong 2015년 3월 9일
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