Win10环境openEXR-Python安装及例程

环境:windows 10 + VS 2017 + python 3.5

try1

用下面的命令直接安装,报错

pip install OpenEXR

try2

下载包,手动编译 -> 未能解决编译报错
参考:
Build OpenEXR on Windows
openexr windows 平台编译

try3

从下面链接直接下载wheel文件,注意选择和自己python版本匹配的文件下载
用pip(19.2 or newer) 安装下载的.whl 文件
Unofficial Windows Binaries for Python Extension Packages

PS:
Python OpenEXR doc

读写例程

读入EXR文件,转换为HDR文件
def EXR2HDR(imDir, hdrDir):
    File = OpenEXR.InputFile(baseDir+dataDir+Scene+'/'+Frame)
    PixType = Imath.PixelType(Imath.PixelType.FLOAT)
    DW = File.header()['dataWindow']
    Size = (DW.max.x - DW.min.x + 1, DW.max.y - DW.min.y + 1)
    rgb = [np.fromstring(File.channel(c, PixType), dtype=np.float32) for c in 'RGB']
    rgbResize =[np.reshape(x,(Size[1],Size[0],1)) for x in rgb]
    hdr = np.concatenate((rgbResize[0],rgbResize[1],rgbResize[2]),2) # H,W,C
    # imageio.imwrite(hdrDir,hdr,format='hdr')
    return hdr

获取exr图片的属性

print(file.header())
'''
{'displayWindow': (0, 0) - (1023, 767),  #图片的大小
 'pixelAspectRatio': 1.0, 
 'screenWindowWidth': 1.0, 
 'screenWindowCenter': (0.0, 0.0), 
 'channels': {'G': FLOAT (1, 1)},  #图片中的通道信息,此处是灰度,所以是G;如果是彩色的话,就是RGB,看情况;
 'dataWindow': (0, 0) - (1023, 767), 
 'compression': ZIP_COMPRESSION, 
 'lineOrder': INCREASING_Y}
'''

为获取类型最大值/数据最大值

min_value = np.iinfo(im.dtype).min
max_value = np.iinfo(im.dtype).max
# docs:
#   [`np.iinfo`] (machine limits for integer types)
#   [`np.finfo`] (machine limits for floating point types)

HDR和LDR转换

def sRGBDeLinearize(linearsRGB):
    linearsRGB = np.where(linearsRGB<=0.0031308, linearsRGB*12.92, 1.055*(linearsRGB**(1.0/2.4))-0.055)
    return linearsRGB
'''
In both cases, the floating-point s value ranges from 0 to 1
When you're reading an sRGB image, and you want linear intensities, 
apply this formula to each intensity:
'''
float s = read_channel();
float linear;
if (s <= 0.04045) linear = s / 12.92;
else linear = pow((s + 0.055) / 1.055, 2.4);
'''
Going the other way, when you want to write an image as sRGB, 
apply this formula to each linear intensity:
'''
float linear = do_processing();
float s;
if (linear <= 0.0031308) s = linear * 12.92;
else s = 1.055 * pow(linear, 1.0/2.4) - 0.055; ( Edited: The previous version is -0.55 )

参考:
Using FreeImage convert hdr to jpg
What are the practical differences when working with colors in a linear vs. a non-linear RGB space?
openexr-making-sense-of-rgb-float-values

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。