This program is part of Netpbm.
ppmtopgm reads a PPM as input and produces a PGM as output. The output is a "black and white" rendering of the original image, as in a black and white photograph. The quantization formula ppmtopgm uses is y = .299 r + .587 g + .114 b.
The dimensions and maxval of the output are the same as the input. Note that with only one color plane, there are far fewer brightnesses that can be represented with the same maxval than with three color planes, so you may want to increase the maxval of the input with pamdepth before giving it to ppmtopgm to avoid loss of information. For example, with a maxval of 1, there are 8 brightnesses that are possible in a PPM (though some of them are barely distinguishable), but only 2 brightness levels possible in a PGM.
Note that although there is a pgmtoppm program, it is not necessary for simple conversions from pgm to ppm , because any ppm program can read pgm (and pbm ) files automatically. pgmtoppm is for colorizing a pgm file. Also, see ppmtorgb3 for a different way of converting color to gray. And ppmdist generates a grayscale image from a color image, but in a way that makes it easy to differentiate the original colors, not necessarily a way that looks like a black and white photograph.
Cold-hearted orb that rules the night Removes the colors from our sight Red is gray, and yellow white But we decide which is right And which is a quantization error.