码迷,mamicode.com
首页 > 其他好文 > 详细

获取exr图片上像素点的颜色通道

时间:2016-06-14 15:47:17      阅读:283      评论:0      收藏:0      [点我收藏+]

标签:

 

google了好久,都没找到合适的方法,还是自己撸一串吧。


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]
#examples
get_channel(‘*.exr‘,(0,0))

 

获取exr图片上像素点的颜色通道

标签:

原文地址:http://www.cnblogs.com/jerrykon/p/5584147.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!