Skip to content

Instantly share code, notes, and snippets.

@taikomatsu
Created May 29, 2019 17:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taikomatsu/198a6ffea380354c3a3f46e164ec651b to your computer and use it in GitHub Desktop.
Save taikomatsu/198a6ffea380354c3a3f46e164ec651b to your computer and use it in GitHub Desktop.
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