tahereh rashnavadi
tahereh rashnavadi

Reputation: 1

how can i retrieve multiple images which are stored in the .mat format in matlab?(convert .mat to image)

i have 70 face images which are stored in a .mat file called(sub1.mat) with the size of 8064*70 , each image is stored in the column vector in the 'sub.mat', now i want to convert each column to image format (gray image), below is the code i wrote but it does not give me a correct image, can some one please let me know what is the problem? i appreciate for your help.(the only information which i know about the image is that: the size of the image is 100*100)

load sub1       % a .mat format with the size of 8064*70
%the first image, size 8064*1
a=sub1(:,1)    %each column is an image of an individual
%convert the column matrix to 100*100 image
b=imresize(a,[100 100]);
im=mat2gray(b)
imwrite(im,'im1.pgm');

Upvotes: 0

Views: 746

Answers (1)

Oli
Oli

Reputation: 16035

By doing that, matlab will try to resize an image 8064x1 into a 100x100 image. To do that, matlab will stretch the vector to make it fit the dimensions 100x100. That most likely looks awful.

That's not what you want to do. You should find a way to know what was the original dimension of the images, and then use reshape .

im=reshape(sub1(:,1),originalSize);

If you don't know the original size, you cannot rebuild your images.

However, if you really don't know the original dimensions, I computed for you all the possibilities, you should test them:

[96 84]
[112 72]
[126 64]
[128 63]
[144 56]
[168 48]
[84 96]
[72 112]
[64 126]
[63 128]
[56 144]
[48 168]

Upvotes: 1

Related Questions