I'm trying to write a converters algorithm that takes a JPEG image and returns its PGM (Portable Gray Map) version. The problem is that I can't understand how the "official" JPG->PGM convertitors work in terms of what value to assign to the final pixel (i guess, 0->255) starting from the classic RGB format.
At the beginning, I used this formula (it's the same used by OpenCV's CV_RGB2GRAY conversion):
0.30*R + 0.59*G + 0.11*B = val
I wrote a simple code to test my results: it takes a color image and its PGM version (already converted using GIMP). Then it converts the color image using the previous formula. The goal is to have a grayscale image that is pixel-to-pixel equal to the PGM input.
At this point, it does not return the same values. Can you help me?