Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display hdr using PySide2
from PySide2 import QtWidgets, QtGui
from PySide2 import QtCore
import sys
import imageio
import numpy as np
from PIL import Image, ImageQt
imgpath = 'myhdri.hdr'
imageio.plugins.freeimage.download()
img = imageio.imread(imgpath)
# easy gamma correction
img = np.power(img, 1/2.2)
img = np.clip(np.floor(img*255), 0, 255).astype(np.uint8)
image = Image.fromarray(img)
image.thumbnail((600, 600), Image.ANTIALIAS)
# GUIの構築
app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QMainWindow()
window.setWindowTitle('My HDRI Viewer')
main = QtWidgets.QWidget()
window.setCentralWidget(main)
lay = QtWidgets.QHBoxLayout()
main.setLayout(lay)
# PIL.ImageをQtで読める形に
qim = ImageQt.ImageQt(image)
map = QtGui.QPixmap().fromImage(qim)
### QPixmap().fromImage() にしないとなぜか有効なデータにならず、以下だとNG
#map = QtGui.QPixmap(ImageQt.ImageQt(image))
scene = QtWidgets.QGraphicsScene()
view = QtWidgets.QGraphicsView(scene)
map1 = scene.addPixmap(map)
lay.addWidget(view)
window.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.