what is the meaning for variable of .mat file
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Soon Fei Fong
le 7 Mar 2015
Réponse apportée : Soon Fei Fong
le 9 Mar 2015
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 commentaires
Réponse acceptée
Image Analyst
le 7 Mar 2015
bothPics = cat(3, pic1, pic2); % Create 28x28x2 array
save(('BothPics.mat', 'bothPics');
2 commentaires
Image Analyst
le 7 Mar 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.
- 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
le 7 Mar 2015
Modifié(e) : Image Analyst
le 7 Mar 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;
Plus de réponses (2)
Soon Fei Fong
le 8 Mar 2015
1 commentaire
Image Analyst
le 8 Mar 2015
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')
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
