To read the. pgm file in C, please link the blog http://blog.csdn.net/a350203223/article/details/13102513
PGM file Format PGM----Portable Graymap format.
The PGM format is the minimum standard for grayscale file formats. The format of the PGM file is defined as follows: A PGM file consists of one or more PGM images. There is no data before or after the multiple images. Each PGM image consists of the following parts:-A "magic number", which is used to calibrate the file format.
The magic number of PGM is "P5". -Blank area (space, TAB, enter, line wrap)-image width, decimal ascii-white space-image high, decimal ASCII-blank area-Maximum grayscale value (maxval), decimal ascii. Must be less than 65536-a new line or another white space character- An image of gray value with a wide * height of empty grids. Each grayscale value is taken from 0 to Maxval, 0 for Black, and maxval for white. Each grayscale value is represented by 1-2 bytes. If maxval is less than 256, that line is one byte, otherwise two bytes. Maximum bytes (
Most significant byte) starts-each grayscale value is the density value that represents the current pixel value after the CIE rec.709 gamma correction.
-A very common PGM format alternative format is the linear grayscale value (without gamma correction), pnmgamma with such a PGM file as input, output a standard PGM file-#符号之后的一行为注释行, will be omitted.
-The raster value for each pixel is represented as a decimal ASCII value. -Each pixel has a space before and after the raster value.
So there will be greater than or equal to 1 spaces between the two pixels.
-No more than 70 characters per line. PGM File Example: P5 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0  &NBsp 0 0 0 0 0 0 0 0 0 0 3 3 3 & nbsp; 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0 0 3 0 0 0 0& nbsp; 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0 0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0 0 3 0 0 0 0 & nbsp; 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0 0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0 0 0 0 0 0 0 & nbsp; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0