Search code examples
matlabmatpgm

How to convert .pgm file to .mat file in Matlab?


I have to convert 'Yale' dataset whose format is .pgm to .mat file, I searched about this issue but couldn't find anything.

I appreciate any help.


Solution

  • Images can be saved in .mat format by using the save() function offered by MATLAB.

    Let us suppose the name of your image is xyz.pgm that has to be saved as xyz.mat. Following steps should do so :

    im = imread('xyz.pgm')
    save('xyz.mat','im')
    

    You can look into save() function to learn more about it.

    Instead if you just want to convert it into other image formats, you should look up imwrite().