MATLAB how can I save an image?

Alon Shmiel picture Alon Shmiel · Apr 9, 2012 · Viewed 13k times · Source

I tried the commands:

 imshow(originalImage);
 imsave;

it works, but I want the matlab to automatically save the image in bmp format (in the current folder). I tried to use:

 save('myimage.bmp','originalImage');

the picture was saved, but on the image itself, instead of the picture, I saw this message: "windows photo viewer can't open this picture because the file apears to be damaged, corrupted, or is too large". (the size of the picture is 5kb).

Thanks!

Answer

Castilho picture Castilho · Apr 9, 2012

Use the function imwrite to do that:

imwrite(image_matrix, 'myimage.bmp', 'bmp')

imwrite documentation on mathworks