Specify the number of bytes that represent each sample in the input and that the byte-sequence is to be interpreted as little-endian
rawtopgm width height -bpp 1|2 -littleendian path/to/image.raw > path/to/output.pgm