Explanation of PGM and PPM image file format
Seeing an image file in Linux - one viewer is xv, another is ee.
For xv --> Type "xv", use the right mouse button to access the menu
for loading, viewing, saving image files in various formats.
Common image formats are GIF and JPEG.
For reading image data, two other formats, PGM and PPM are also used.
PGM - grey scale images (one value per pixel)
PPM - color images (three values, red green blue - rgb, per pixel)
At the top of the image file is a code for the particular format:
P2 - PGM grey scale image, stored in ASCII, one value per pixel
P3 - PPM color image, stored in ASCII, 3 values rgb per pixel
P5 - PGM grey scal image stored in binary (compressed) format
P6 - PPM color image stored in binary (compressed) format
Here's the first few lines of fig1.pgm. This image file is a grey scale
image in P2 format. The second line, beginning with #, is a comment.
Comment lines begin with the symbol "#". The next two numbers specify
the width and height (#cols and #rows) of the image. The next number,
255, is the highest pixel value in the array.
Below the 255 are the pixel values in ASCII format.
P2 <-- Image format type
# CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) <-- Comment
97 128 <-- 97 columns (width) and 128 rows (height) of image
255 <-- Max pixel value
45 45 49 57 65 65 61 85 125 138 121 117 117 121 121 121 117
109 146 215 219 219 223 206 182 190 194 194 190 194 198 198 198 202
198 194 190 190 194 198 198 202 202 202 198 198 194 194 194 194 198
198 198 198 198 194 194 194 198 198 198 202 198 198 194 190 194 194
194 198 198 190 190 210 215 215 210 206 170 146 146 142 130 65 45
40 45 49 61 53 36 16 28 28 61 121 142 53 53 53 57 69
. . .
Here's the same file in PPM (color) format. Note the 3 values per
pixel. Since the rgb values are the same for each pixel, this would
still be a grey scale image.
P3 <-- Image format type
# CREATOR: XV Version 3.10a Rev: 12/29/94 (PNG patch 1.2) <-- Comment
291 384 <-- 291 columns (width) and 384 rows (height) of image
255 <-- Max pixel value
45 45 45 45 45 45 49 49 49 57 57 57 65 65 65 85 85
85 121 121 121 . . .
P2 and P3 modes are stored in ASCII format, readable by an editor.
These take up alot of space. The binary versions, P5 and P6, take
less space, but they must be read in binary form.