Created
May 29, 2019 17:33
-
-
Save taikomatsu/198a6ffea380354c3a3f46e164ec651b to your computer and use it in GitHub Desktop.
Display hdr using PySide2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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