grayscale conversion and pgm file writer