3

I'm looking for more efficient solution of converting .exr to 8bit JPEG with gamma encoding. Currently, I make use of OpenEXR module and numpy. Here is the code snippets:

File = OpenEXR.InputFile(exrfile)
PixType = Imath.PixelType(Imath.PixelType.FLOAT)
DW = File.header()['dataWindow']
Size = (DW.max.x - DW.min.x + 1, DW.max.y - DW.min.y + 1)

rgb = [numpy.fromstring(File.channel(c, PixType), dtype=numpy.float32) for c in 'RGB']
for i in range(3):
    rgb[i] = numpy.where(rgb[i]<=0.0031308,
            (rgb[i]*12.92)*255.0,
            (1.055*(rgb[i]**(1.0/2.4))-0.055) * 255.0)

rgb8 = [Image.fromstring("F", Size, c.tostring()).convert("L") for c in rgb]
#rgb8 = [Image.fromarray(c.astype(int)) for c in rgb]
Image.merge("RGB", rgb8).save(jpgfile, "JPEG", quality=95)

I'm wondering if there is even efficient solution for that?

Drake Guan
  • 14,514
  • 15
  • 67
  • 94
  • My another experiment shows that [boolean (or "mask") index arrays](http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays) performs much efficient than `numpy.where`. Still looking for any better way for this. – Drake Guan Sep 09 '13 at 04:03

0 Answers0