0

I'm trying to convert the image found here pgm image to jpg but I can't. I've tried the answer of the question found here but it didn't work. So, if anyone could please advise.

Community
  • 1
  • 1
Tak
  • 3,536
  • 11
  • 51
  • 93
  • Are you sure the file is not corrupted? even imagemagick's `identify` tool cant read it. Do you have any other files? Can you open this file in some other program? – Marcin Feb 06 '14 at 08:22
  • i've tried opening it using Gimp but it didn't work, thats why I thought may be there is another problem. I'll check another file and will get back to you – Tak Feb 06 '14 at 14:01

2 Answers2

3

The problem is in your file-header:

Pf 640 480 9757

According to Wikidepida and this man page your file should use P2 (for the graymap) instead of Pf (which seems to be invalid in all cases):

P2 640 480 9757

With that little change (made in a text editor) your file opens fine.

Schorsch
  • 7,761
  • 6
  • 39
  • 65
  • I'm now trying to convert this file to .jpg using the answer suggested in the question but it gives this error "UINT16 image data requires bitdepth specifically set to either 12 or 16." so any advise please? – Tak Feb 07 '14 at 01:54
  • 1
    Check [the documentation](http://www.mathworks.com/help/matlab/ref/imwrite.html)! Scroll down until you find **'BitDepth' — Number of bits per pixel** - you'll figure it out. – Schorsch Feb 07 '14 at 12:41
1

If you need more faces use the Cambridge's database
And do it like in your link.

$> im = imread( 'file.pgm' );

$> imwrite( im , 'nameForJpg.jpg');

And that's it!

Good Luck!

Live long and prosper!

Community
  • 1
  • 1
Manuel
  • 11
  • 1