from PyQt5 import QtWidgets
from PyQt5 import QtGui
app = QtWidgets.QApplication([])
label = QtWidgets.QLabel()
pixmap = QtGui.QPixmap('파일 경로')
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.show()
app.exec_()
window가 뜨긴 하는데, 이미지가 없는 빈 window가 뜸
from PyQt5 import QtWidgets
from PyQt5 import QtGui
app = QtWidgets.QApplication([])
label = QtWidgets.QLabel()
fid = open('파일경로',"rb")
img=np.fromfile(fid, dtype='int8', sep="")
pixmap = QtGui.QPixmap(img)
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.show()
app.exec_()
QPixmap argument에는 numpy.ndarray 형식이 못 들어간다고 함. 즉 jpg나 png 형식이라면 경로만 입력해주어도 들어갈 수 있지만 raw 파일은 전처리 필요
from PyQt5 import QtWidgets
from PyQt5 import QtGui
app = QtWidgets.QApplication([])
label = QtWidgets.QLabel()
fid = open('파일경로',"rb")
img1 = np.fromfile(fid, dtype='int8', sep="")
def array2Pixmap(img):
img8 = (img/256.0).astype(np.uint8)
img8 = ((img8 - img8.min()) / (img8.ptp() / 255.0)).astype(np.uint8)
img = QtGui.QImage(img8, 512, 512, QtGui.QImage.Format_Grayscale8)
return img
img = array2Pixmap(img1)
pixmap = QtGui.QPixmap(img)
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.show()
app.exec_()
window가 뜨는데 그냥 검은화면만 있는 window가 뜬다. 3차원 이미지에 대한 전처리가 필요해 보인다.
from PySide2 import QtWidgets
from PySide2 import QtGui
import numpy as np
app = QtWidgets.QApplication([])
label = QtWidgets.QLabel()
fid = open('파일경로',"rb")
img1 = np.fromfile(fid, dtype = np.uint16)
def array2Pixmap(img, section_count, width, height, x, y, z):
img8 = (img/256.0).astype(np.uint8)
img8 = ((img8 - img8.min()) / (img8.ptp() / 255.0)).astype(np.uint8)
arr = img8.reshape(section_count, width, height)
arr_x = arr[x,:,:]
arr_y = arr[:,y,:]
arr_z = arr[:,:,z]
img_x = QtGui.QImage(arr_x.tobytes(), width, height, QtGui.QImage.Format_Grayscale8)
img_y = QtGui.QImage(arr_y.tobytes(), height, section_count, QtGui.QImage.Format_Grayscale8)
img_z = QtGui.QImage(arr_z.tobytes(), width, section_count, QtGui.QImage.Format_Grayscale8)
return [img_x, img_y, img_z]
original_img = array2Pixmap(img1, 200, 512, 512, 100, 256, 256)[0]
yz_img = array2Pixmap(img1, 200, 512, 512, 100, 256, 256)[1]
xz_img = array2Pixmap(img1, 200, 512, 512, 100, 256, 256)[2]
pixmap = QtGui.QPixmap.fromImage(xz_img)
label.setPixmap(pixmap)
label.resize(pixmap.width(), pixmap.height())
label.show()
app.exec_()
QIMAGE에 넣을땐 tobytes() 로 넣어야 한다..