user2614596
user2614596

Reputation: 630

How to convert PPM images to JPG in Matlab?

I have some PPM images (stereo) that I read with imread() and I want to save the same images in JPEG with different Quality factors. Here is my code.

%Read PPM image
L = imread(filename_L);

%Create JPEG Q85 from PPM
filename_L85 = strcat(filename_L,'_ppm_to_jpeg.jpg');
imwrite(L,filename_L85,'JPEG','Quality',85);

And here the error I get.

Error using imwrite>parse_inputs (line 528)
The colormap should have three columns.

Error in imwrite (line 418)
[data, map, filename, format, paramPairs] = parse_inputs(varargin{:});

Error in testFinale (line 75)
    imwrite(L,filename_L85,'JPEG','Quality',85);

How can I write JPEG images previously read in PPM format? Thanks

Upvotes: 0

Views: 789

Answers (1)

Jonathan
Jonathan

Reputation: 817

Could it be that is just has to do with your case of 'JPEG', the documentation of imwrite specifies parameters for file type as lowercase.

Apart from that you might not even need it as the file type is derived from the extension which in this case is set explicitly to .jpg already.

So you might either go for:

imwrite(L,filename_L85,'jpeg','Quality',85);

or perhaps even easier:

imwrite(L,filename_L85,'Quality',85);

Upvotes: 0

Related Questions