Is it perhaps related to this 
<https://groups.google.com/d/msg/pyqtgraph/yzZRmQcd5Fg/BAHtwTg7ZJEJ>? 
Though I'm not sure how.

On Thursday, August 3, 2017 at 11:18:23 AM UTC-7, Alexander Tomlinson wrote:
>
> Hello,
>
> I have a GraphicsLayoutWidget with two ImageItems overlayed. The bottom 
> one is just a constant feed from a camera. Ocasionally, I capture a frame 
> and overlay with some transparency using opacity option of setImage. This 
> works without issue. However, I want to threshold this overlay at times, 
> and after adding an alpha value the image is no longer displayed. Any help 
> or insight would be appreciated. I've pasted below the relevant code. 
>
> import numpy as np
> import pyqtgraph as pg
> from PyQt4 import QtGui, QtCore
>
>
> class Frame(QtGui.QWidget):
>     """
>     Main frame.
>     """
>     def __init__(self):
>         # a bunch of init stuff
>         self.do_threshold = False
>         self.overlay_opacity = 0.5
>
>     def update_viewer(self, img_data):
>         """
>         Makes call to update image viewer.
>
>         :param img_data: image data
>         """
>         self.image_viewer.update(img_data)
>
>     def update_overlay(self, img_data_overlay):
>         """
>         Updates the overlay.
>
>         :param img_data_overlay: image data of the overlay
>         """
>         if self.do_threshold:
>             threshed = np.copy(img_data_overlay)
>             threshed[threshed < self.overlay_threshold] = 0
>             
>             # make into RGBA
>             threshed = np.dstack([threshed] * 3)
>             alpha = np.full((threshed.shape[1], threshed.shape[0], 1), 0.5, 
> np.uint8)
>             # commenting out below line, so that it's RGB, makes it appear 
> again
>             threshed = np.concatenate([threshed, alpha], axis=2)
>
>             self.image_viewer.update_overlay(threshed)
>
>         else:
>             self.image_viewer.update_overlay(img_data_overlay, 
> overlay_opacity=self.overlay_opacity)
>
>
> class ImageWidget(pg.GraphicsLayoutWidget, object):
>     """
>     Widget for the display from the camera.
>     """
>     def __init__(self, parent=None):
>         super(ImageWidget, self).__init__(parent=parent)
>
>         vb = self.addViewBox(row=1, col=1)
>
>         self.viewer = pg.ImageItem()
>         self.viewer_overlay = pg.ImageItem()
>
>         vb.addItem(self.viewer)
>         vb.addItem(self.viewer_overlay)
>         
>         # set overlay to always be on top
>         self.viewer_overlay.setZValue(1)
>
>         vb.setAspectLocked(True)
>
>     def update(self, img_data):
>         """
>         Updates image
>
>         :param img_data: image data
>         """
>         self.viewer.setImage(img_data, autoLevels=True)
>
>     def update_overlay(self, img_data_overlay, overlay_opacity=None):
>         """
>         Updates overlay data
>
>         :param img_data_overlay: image data of overlay
>         :param overlay_opacity: transparency of the overlay
>         """
>         if overlay_opacity is not None:
>             self.viewer_overlay.setImage(img_data_overlay, autoLevels=True, 
> opacity=overlay_opacity)
>         else:
>             self.viewer_overlay.setImage(img_data_overlay, autoLevels=True)
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/02ce6ceb-127c-465f-b8d3-d070e5f35c2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to