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');
0 个评论
采纳的回答
Image Analyst
2015-3-7
bothPics = cat(3, pic1, pic2); % Create 28x28x2 array
save(('BothPics.mat', 'bothPics');
2 个评论
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.
- just to confirm that the number "3" are three slices/color channels for each image?
- 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
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
2015-3-8
1 个评论
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')
另请参阅
类别
在 Help Center 和 File 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!
