Convert PGM in P5 format to P2 format

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
maheshravella
Posts: 2
Joined: 2014-04-12T08:32:56-07:00
Authentication code: 6789

Convert PGM in P5 format to P2 format

Post by maheshravella »

Hello,

I'm new to ImageMagick. I have been trying to convert a PGM image in P5 format to P2 format on a windows system. I have installed the ImageMagick-6.8.9. Kindly provide me with step by step process to convert the image.

Thanks in advance!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert PGM in P5 format to P2 format

Post by snibgo »

These are both grayscale. P5 is binary (ie compressed). P2 is ASCII (ie not compressed). So the following should do the job:

Code: Select all

convert in.pgm -compress None out.pgm
snibgo's IM pages: im.snibgo.com
maheshravella
Posts: 2
Joined: 2014-04-12T08:32:56-07:00
Authentication code: 6789

Re: Convert PGM in P5 format to P2 format

Post by maheshravella »

Thanks snibgo. i have tried that and i'm getting the following error:

convert.exe: unable to open image `1.pgm': No such file or directory @ error/blo
b.c/OpenBlob/2647.
convert.exe: no images defined `out.pgm' @ error/convert.c/ConvertImageCommand/3
161.

Please help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert PGM in P5 format to P2 format

Post by snibgo »

What is shown when you type "dir 1.pgm"?
snibgo's IM pages: im.snibgo.com
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert PGM in P5 format to P2 format

Post by anthony »

I do however recommend you use the actual PBMPlus Library command for conversion.
These three are all equivalent and were basically the result of the libraries long history
pnmtopnm -plain
pnmnoraw
pnmtoplainpnm

The reason is while IM gets the Image format correct, it only uses spaces between wach pixel value. The above however adds returned between each row of values, meaning that each row of pixels forms it own line, whcih can help greatly in scripted processing of the image values. This is actually one of the greatest benifits of this image format... scripted processing of values, and IM examples goes into this at various times for various reasons.

See IM examples, common Image Formats, PBMPlus
http://www.imagemagick.org/Usage/formats/#pbmplus

For scripting the alternative is IM Enumerated Pixels format (".txt") but after the header line, this lists one pixel per line, making it a very verbose format by comparison. Still very useful though.


There was suggestions made to allow you to specify the 'level' for the output values, beyond what you can get using -depth, but that has never been implemented. SIDE: PBMplus can use any level up to 65535 (16 bit) for the output values.

PS: I was the one to release the PBMplus patch release in 1996. And yes I have been around that long!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply