Python: obtain radiometric values from OpenEXR channels

109 Views Asked by At

Good morning everybody! I created a physically accurate scene in Blender and my aim, using python, is to study radiometric conditions over the rendered scene in order to obtain an illumination map in terms of [W/m^2]. I saved images in OpenEXR file format, due to its high dynamic-range properties and I wanted to obtain a Relative Luminance Map starting from RGB values in "R" "G" "B" channels. The major issue is how to scale linear values from OpenEXR channels to have physically accurate values between [0, 1], needed to obtain Relative Luminance map maintaining the HDR properties of the file format. Part of the code is reported below.

    pt = Imath.PixelType(Imath.PixelType.FLOAT)
    exrfile = exr.InputFile(filename)
    dw = exrfile.header()['dataWindow']
    size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
    redstr = exrfile.channel('R', pt)
    red = np.fromstring(redstr, dtype = np.float32)
    red.shape = (size[1], size[0]) # Numpy arrays are (row, col)

    greenstr = exrfile.channel('G', pt)
    green = np.fromstring(greenstr, dtype = np.float32)
    green.shape = (size[1], size[0]) # Numpy arrays are (row, col)

    bluestr = exrfile.channel('B', pt)
    blue = np.fromstring(bluestr, dtype = np.float32)
    blue.shape = (size[1], size[0]) # Numpy arrays are (row, col)


    rel_luminance = 0.2126*red[:,:]+0.7152*green[:,:]+0.0722*blue[:,:] 

For a test image the obtained Max values of the three channels are respectively:

Max(R) = 198.16421508789062

Max(G) = 173.5792999267578

Max(B) = 163.20120239257812

The obtained values are obviously not in the range between [0, 1], moreover I am not able to understand the global maximum value to scale the channels and obtain what i want.

Has someone some tips to solve my problem? Thanks in advice.

1

There are 1 best solutions below

0
On

A few points…

  1. RGB is tristimulus information. It will never be “radiometric” but rather radiometric-like representations within the limitations of tristimulus.
  2. There is no limitation on the upper or lower limits in an EXR tristimulus encoding. The meaning comes from the ratios between the values, or an additional piece of information in the rare case the units are intended to be absolute.
  3. A good rule of thumb is that any time the term lum is in a word, it is photometric (IE human-centric domain) where rad is likely radiometric. Illuminance, luminance etc. are photometric massaged values,while irradiance and radiance are the physical model side.
  4. Calculating achromatic luminance from an RGB triplet is a weighted sum of components. For BT.709 based sRGB tristimulus systems, that weighting is 0.2126 * R + 0.7152 * G + 0.0722 * B. Again, note this is an approximation based off of the CIE 1920 luminous efficacy function. Also note, luminance does not adequately represent the cumulative equivalent achromatic luminance contribution.