4

I am converting a RGB image to EXR format, using openexr, as follows:

int w = 1024;
int h = 768;

Array2D<Rgba> p (h, w);
QString fileName = "Penguins.jpg";
QImage Image = QImage(fileName);


QRgb c;

for (int y = 0; y < h; ++y)
{
    for (int x = 0; x < w; ++x)
    {
        c = Image.pixel(x,y);
        Rgba &p = px[y][x];
        p.r = qRed(c)/255.0;
        p.g = qGreen(c)/255.0;
        p.b = qBlue(c)/255.0;
        p.a = 1;
    }
}

However, the converted image has different color, compare to the result of the graphics editor software, such as Adobe Photoshop. Below, you can see the given image, and the converted one (opened in Adobe Photoshop): Given Image .jpg Converted Image .exr

csuo
  • 820
  • 3
  • 16
  • 31

1 Answers1

2

The RGB values contained in most common image formats such as JPEG are gamma corrected. The RGB values in OpenEXR are linear. You need to do a conversion on each pixel to make it linear.

The proper transformation to linear would be the sRGB formula. However for a quick test you can approximate it by taking the power of 2.2:

    p.r = pow(qRed(c)/255.0, 2.2);
    p.g = pow(qGreen(c)/255.0, 2.2);
    p.b = pow(qBlue(c)/255.0, 2.2);
Mark Ransom
  • 299,747
  • 42
  • 398
  • 622
  • Thanks for your answer, after applying the conversion the colors seem correct in Adobe Photoshop, although I do not understand why with mac preview, the colors are different. – csuo Mar 10 '14 at 12:58
  • @csuo Macs used to use a different gamma of 1.8, see https://support.apple.com/kb/HT3712 – Mark Ransom Mar 10 '14 at 16:27