如何使用ImageIO的FreeImage将和hdr转换为jpeg映像?
我编写了一个函数,接受和EXR并将其转换为jpg,结果如下所示:
因此,我很难理解如何将HDR转换成具有类似结果的jpg。我从这里免费下载了HDR:interior&r=1k
我只是不知道如何将hdr中的浮动数字范围转换为jpg图像位深度。
人类发展报告> JPG
import imageio
import os
def convert_hdr_to_jpg(filepath):
if not os.path.isfile(filepath):
return False
directory = os.path.dirname(filepath)
filename, extension = os.path.splitext(filepath)
if not extension.lower() in ['.hdr', '.hdri']:
return False
# imageio.plugins.freeimage.download() #DOWNLOAD IT
image = imageio.imread(filepath, format='HDR-FI')
output = os.path.join(directory, filename + '.jpg')
imageio.imwrite(output, image)
EXR > JPG
import os, json, logging, time, random
from math import sqrt
from collections import namedtuple
from PIL import Image
import numpy
import OpenEXR
import Imath
def convert_exr_to_jpg(filepath):
'''
Description:
Generates a jpg image for the supplied exr file
Args:
filepath (str): filepath to image
Returns:
bool: Returns True on success otherwise returns False
'''
if not os.path.isfile(filepath):
log.error('Missing file: {}'.format(filepath))
return False
name, extension = os.path.splitext(os.path.basename(filepath))
if extension not in ['.exr']:
log.warning('Invalid image file format: {}'.format(filepath))
return False
File = OpenEXR.InputFile(filepath)
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 = [numpy.fromstring(File.channel(c, PixType), dtype=numpy.float32) for c in 'RGB']
for i in range(3):
rgb[i] = numpy.where(rgb[i]<=0.0031308,
(rgb[i]*12.92)*255.0,
(1.055*(rgb[i]**(1.0/2.4))-0.055) * 255.0)
rgb8 = [Image.frombytes("F", Size, c.tostring()).convert("L") for c in rgb]
# rgb8 = [Image.fromarray(c.astype(int)) for c in rgb]
output = os.path.normpath(os.path.join(os.path.dirname(filepath), name + '.jpg'))
Image.merge("RGB", rgb8).save(output, quality=80)
log.info('Created: {}'.format(output))
发布于 2022-11-10 08:23:24
sudo apt-get install -y openimageio-tools
oiiotool probe.hdr -o probe.png
# https://github.com/OpenImageIO/oiio/discussions/3579
# https://launchpad.net/ubuntu/+source/openimageio
https://stackoverflow.com/questions/47725161
复制相似问题