I am trying to write a converter algorithm that accepts a JPEG image and returns its version of PGM (Portable Gray Map). The problem is that I cannot understand how the “official” JPG-> PGM converters work in terms of what value should be assigned to the final pixel (I think 0-> 255), starting with the classic RGB format.
In the beginning I used this formula (it is also used to convert OpenCV CV_RGB2GRAY):
0.30 * R + 0.59 * G + 0.11 * B = val
I wrote simple code to test my results: it accepts a color image and its version of PGM (already converted using GIMP). He then converts the color image using the previous formula. The goal is to have a grayscale image that is pixel by pixel equal to the PGM input signal.
At this point, it does not return the same values. Can you help me?
algorithm image jpeg pgm file-conversion
TheUnexpected
source share