Convert Images in MATLAB to different file formats (bmp, gif, hdf, jpg, jpeg, jp2, jpx, pbm, pgm, ppm, pnm, pcx, png, ras, tif, tiff, xwd)

In MATLAB you can easily convert your image from a specific format to another format in the following list:
bmp, gif, hdf, jpg, jpeg, jp2, jpx, pbm, pgm, ppm, pnm, pcx, png, ras, tif, tiff, xwd.
Although here I mention some examples, you can convert anything mentioned in the above list easily in 2 lines of code.

first of all you need to read the image file:

I = imread('myImage.png');

here I assume that I have an image with png format, but you can have other formats as well.

The next step is, convert it to your desired format and write it:

imwrite(I,'myImage2.bmp');
imwrite(I,'myImage3.gif');
imwrite(I,'myImage4.hdf');
imwrite(I,'myImage5.jpg');
imwrite(I,'myImage6.bpm');
imwrite(I,'myImage7.pgm');
imwrite(I,'myImage8.ppm');
imwrite(I,'myImage9.tiff');

For more details check the MATLAB document page.

About machinelearning1

This weblog is about Machine Learning and all related topics that one needs to challenge real world with artificial intelligence.
This entry was posted in Linux, MATLAB, OpenCV, programming, Software, Ubuntu and tagged , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

2 Responses to Convert Images in MATLAB to different file formats (bmp, gif, hdf, jpg, jpeg, jp2, jpx, pbm, pgm, ppm, pnm, pcx, png, ras, tif, tiff, xwd)

  1. sajjad says:

    Is it possible to change image format without writing on disk?

  2. ibtos says:

    but what’s the problem in my matlab it can’t covert image jpg to ppm

Leave a comment