import OpenEXR, Imath, array
def get_channel(exr_file,pixel_pos,channel='R'):
# Open the input file
file = OpenEXR.InputFile(exr_file)
f_header=file.header()
dw = f_header['dataWindow']
#get pixel pos relative to the datawidnow
pixel_data_pos=(pixel_pos[0]-dw.min.x, pixel_pos[1]-dw.min.y)
#convert 2d array to 1d array index
pixel_index=pixel_data_pos[1]*(dw.max.x-dw.min.x+1)+pixel_data_pos[0]-1
# Read the specified channle color as 32-bit floats
float_type = Imath.PixelType(Imath.PixelType.FLOAT)
return array.array('f', file.channel(channel, float_type)).tolist()[pixel_index]
No comments:
Post a Comment