这个问题与这个问题相关,但它是关于在 pyqtgraph.ImageView 中堆叠两个图像,第二个图像对第一个图像显示的统计数据没有贡献。
标题确实说明了一切。我有一个图像,我想用 pyqtgraph.ImageView 的所有优秀功能来显示,并且可以工作。然后我想用叠加层突出显示该图像的区域,但我不想干扰直方图。
就我而言,我有一个“坏点”位图;主图像是单色的,所以我想把那些坏点涂成红色。
看起来我可以尝试用我的位图制作 QImage,但是(A)这已经被证明很复杂,并且(B)对我来说使用 pyqtgraph 的全部意义是不必必须担心底层的 Qt 接口。
好的。我找到了这个答案——它比我想象的要容易。我只能说这个确实有效,但并不是完全正确。特别是,这似乎取决于
ImageView.addImage()
按顺序从下到上添加图像 - 如果我错了(例如,如果 addImage
将项目插入字典中)那么解决方案可能会破坏下一个我运行代码的时间。
理论是原始图像位于最底层,然后在其上将坏像素涂成红色的图层。为了确保我不只是有黑色和红色图像,好的像素不仅是黑色,而且是透明的。
在设置代码中:
self.image_item = ImageItem(image=np.zeros((240, 320)))
self.image_view = ImageView(imageItem=self.image_item)
self.image_overlay = ImageItem(image=np.concatenate((np.ones((240, 320, 3)), np.zeros((240, 320, 1))), axis=2))
self.image_view.addItem(self.image_overlay)
在每次更新图像时运行的代码中。请注意,
bad_pixels
是一个布尔数组,与我的图像大小相同,每个坏像素True
:
self.image_item.setImage(data.image, autoHistogramRange=True)
overlay = 255 * (bad_pixels.astype(np.uint8)[:, :, np.newaxis] * np.array((1, 0, 0, 1))[np.newaxis, np.newaxis, :])
self.image_overlay.setImage(overlay)