本文整理汇总了Python中OpenEXR.Header方法的典型用法代码示例。如果您正苦于以下问题:Python OpenEXR.Header方法的具体用法?Python OpenEXR.Header怎么用?Python OpenEXR.Header使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenEXR
的用法示例。
在下文中一共展示了OpenEXR.Header方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writeEXR
# 需要导入模块: import OpenEXR [as 别名]
# 或者: from OpenEXR import Header [as 别名]
def writeEXR(img, file):
try:
img = np.squeeze(img)
sz = img.shape
header = OpenEXR.Header(sz[1], sz[0])
half_chan = Imath.Channel(Imath.PixelType(Imath.PixelType.HALF))
header['channels'] = dict([(c, half_chan) for c in "RGB"])
out = OpenEXR.OutputFile(file, header)
R = (img[:,:,0]).astype(np.float16).tostring()
G = (img[:,:,1]).astype(np.float16).tostring()
B = (img[:,:,2]).astype(np.float16).tostring()
out.writePixels({'R' : R, 'G' : G, 'B' : B})
out.close()
except Exception as e:
raise IOException("Failed writing EXR: %s"%e)
# Read training data (HDR ground truth and LDR JPEG images)
示例2: _WriteMixedDatatypesExr
# 需要导入模块: import OpenEXR [as 别名]
# 或者: from OpenEXR import Header [as 别名]
def _WriteMixedDatatypesExr(filename):
header = OpenEXR.Header(64, 64)
header['channels'] = {
'uint': Imath.Channel(Imath.PixelType(Imath.PixelType.UINT)),
'half': Imath.Channel(Imath.PixelType(Imath.PixelType.HALF))
}
channel_data = {
'uint': np.zeros([64, 64], dtype=np.uint32).tobytes(),
'half': np.zeros([64, 64], dtype=np.float16).tobytes()
}
output = OpenEXR.OutputFile(filename, header)
output.writePixels(channel_data)
output.close()
示例3: write_exr
# 需要导入模块: import OpenEXR [as 别名]
# 或者: from OpenEXR import Header [as 别名]
def write_exr(filename, values, channel_names):
"""Writes the values in a multi-channel ndarray into an EXR file.
Args:
filename: The filename of the output file
values: A numpy ndarray with shape [height, width, channels]
channel_names: A list of strings with length = channels
Raises:
TypeError: If the numpy array has an unsupported type.
ValueError: If the length of the array and the length of the channel names
list do not match.
"""
if values.shape[-1] != len(channel_names):
raise ValueError(
'Number of channels in values does not match channel names (%d, %d)' %
(values.shape[-1], len(channel_names)))
header = OpenEXR.Header(values.shape[1], values.shape[0])
try:
exr_channel_type = Imath.PixelType(_np_to_exr[values.dtype.type])
except KeyError:
raise TypeError('Unsupported numpy type: %s' % str(values.dtype))
header['channels'] = {
n: Imath.Channel(exr_channel_type) for n in channel_names
}
channel_data = [values[..., i] for i in range(values.shape[-1])]
exr = OpenEXR.OutputFile(filename, header)
exr.writePixels(
dict((n, d.tobytes()) for n, d in zip(channel_names, channel_data)))
exr.close()