首页 > 其他 > 详细

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

时间:2016-06-14 15:45:36      阅读:249      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!