我想加载32位EXR文件,然后将其调整为非常小的分辨率(如200x200)并输出为8位jpg。问题是输入图像最多需要2秒钟,而我什至不需要图像随附的所有数据。 有没有办法以较低的分辨率或第n个像素输入EXR,这样整个过程会更快?
def main(exrfile, jpgfile):
file = OpenEXR.InputFile(exrfile)
pt = Imath.PixelType(Imath.PixelType.FLOAT)
dw = file.header()['dataWindow']
size = (dw.max.x - dw.min.x + 1, dw.max.y - dw.min.y + 1)
rgbf = [Image.frombytes("F", size, file.channel(c, pt)) for c in "RGB"]
extrema = [im.getextrema() for im in rgbf]
darkest = min([lo for (lo,hi) in extrema])
lighest = max([hi for (lo,hi) in extrema])
scale = 255 / (lighest - darkest)
def normalize_0_255(v):
return (v * scale) + darkest
rgb8 = [im.point(normalize_0_255).convert("L") for im in rgbf]
Image.merge("RGB", rgb8).resize((200,200)).save(jpgfile)