Pyqt5 使用QGraphicsView 显示图片

需要使用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:比例还需要改一下,方向好像也有问题,再加鼠标动作捕捉。

  • 5
    点赞
  • 33
    收藏
    觉得还不错? 一键收藏
  • 10
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值