需要使用Pyqt5来显示MRI图片(240*240*155)的三视图,使用三个QGraphicsView 显示, 在实现过程中发现几个问题:
1、先使用Nibabel读入图像数组,拆成三个维度的图像,再使用
depth_image = image[:, :, img_index[2]]
img = depth_image
frame = PyQt5.QtGui.QImage(img, img.shape[0],img.shape[1], img.shape[0],
PyQt5.QtGui.QImage.Format_Indexed8)
pix = QPixmap.fromImage(frame)
转换成QImage再转换成QPixmap,这时候产生错误:
TypeError: arguments did not match any overloaded call:
QImage(): too many arguments
QImage(QSize, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(bytes, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(sip.voidptr, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(bytes, int, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(sip.voidptr, int, int, int, QImage.Format): argument 1 has unexpected type 'numpy.ndarray'
QImage(List[str]): argument 1 has unexpected type 'numpy.ndarray'
QImage(str, format: str = None): argument 1 has unexpected type 'numpy.ndarray'
QImage(QImage): argument 1 has unexpected type 'numpy.ndarray'
QImage(Any): too many arguments
通过创建一个numpy数组的复制解决,原理未知:
depth_image = image[:, :, img_index[2]].copy()
2、在用QGraphicsView 进行显示时,发现图像成条纹状:
后来发现是维度有问题,改了一下:
frame = PyQt5.QtGui.QImage(img, img.shape[1],img.shape[0], img.shape[1],PyQt5.QtGui.QImage.Format_Indexed8)
可以正常显示。
TODO:比例还需要改一下,方向好像也有问题,再加鼠标动作捕捉。