jamesbowman / openexrpython

OpenEXR bindings for Python
Other
94 stars 35 forks source link

When convert exr image to jpg and png, it looks darker than actual. #37

Closed humayun closed 4 years ago

humayun commented 4 years ago

Hi,

I write script to convert exr image into png or jpg, but convert images looks darker. I think it is not rightly converted from float 32 to uint8 or due to alpha channel. Here is code:

def convert_exr2png(exr_file, png_file):
    # exr_file = '/data/humayun/test/m_3_3_0_0_0_0.0.exr'
    file = OpenEXR.InputFile(exr_file)
    pt = Imath.PixelType(Imath.PixelType.FLOAT)
    dw = file.header()['dataWindow']
    size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)

    rgbf = [Image.frombytes("F", size, file.channel(c, pt)) for c in "RGB"]

    extrema = [im.getextrema() for im in rgbf]
    darkest = min([lo for (lo, hi) in extrema])
    lighest = max([hi for (lo, hi) in extrema])
    scale = 255 / (lighest - darkest)

    def normalize_0_255(v):
        return (v * scale) + darkest

    rgb8 = [im.point(normalize_0_255).convert("L") for im in rgbf]
    Image.merge("RGB", rgb8).save(png_file)

Here is real image m_3_3_0_0_0_0_3 and converted image m_3_3_0_0_0_0_3

jamesbowman commented 4 years ago

Please can you provide more detail -- in particular why you think this is a bug OpenEXR Python?

humayun commented 4 years ago

Thank you. This was not bug in OpenEXR. That is more conversion from Float32 to uint8 and also gamma correction. I resolved that problem.

Best