Jerry's Dev-Lab
JERRY KON's PROFESSIONAL ACTIVITIES AND INTERESTS
Sunday, April 8, 2018
Friday, December 9, 2016
Wednesday, October 12, 2016
Get Pixel Channel In Exr File
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]
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]
Subscribe to:
Posts (Atom)