How to use the pyqtgraph.ImageItem function in pyqtgraph

To help you get started, we’ve selected a few pyqtgraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ronpandolfi / Xi-cam / xicam / plugins / tomography / widgets.py View on Github external
def __init__(self, data, bg_imageItem, pos, constrainX=False, constrainY=True, translateSnap=True, **kwargs):
        size = bg_imageItem.image.shape
        super(ROImageOverlay, self).__init__(pos, translateSnap=translateSnap, size=size, pen=pg.mkPen(None), **kwargs)

        self.data = data
        self.bg_imgeItem = bg_imageItem
        self._y_constrained = constrainY
        self._x_constrained = constrainX
        self._image_overlap = np.empty(size, dtype='float32')
        self._mask = np.zeros(size, dtype=bool)
        self.currentImage = None
        self.currentIndex = None
        self.flipped = False
        self.setCurrentImage(-1)
        self.flipCurrentImage()
        self.imageItem = pg.ImageItem(self.currentImage)
        self.imageItem.setParentItem(self)
        self.updateImage()
github Ulm-IQO / qudi / gui / poimanager / poimangui.py View on Github external
# All our gui elements are dockable, and so there should be no "central" widget.
        self._mw.centralwidget.hide()
        self._mw.setDockNestingEnabled(True)

        self._mw.roi_cb_high_percentile_DoubleSpinBox.setOpts(step=0.01, decimals=5)
        self._mw.roi_cb_low_percentile_DoubleSpinBox.setOpts(step=0.01, decimals=2)
        #####################
        # Setting up display of ROI map xy image
        #####################

        # Get the image for the display from the logic:
        self.roi_xy_image_data = self._poi_manager_logic.roi_map_data[:, :, 3].transpose()

        # Load the image in the display:
        self.roi_map_image = pg.ImageItem(self.roi_xy_image_data)
        self.roi_map_image.setRect(
            QtCore.QRectF(
                self._confocal_logic.image_x_range[0],
                self._confocal_logic.image_y_range[0],
                self._confocal_logic.image_x_range[1] - self._confocal_logic.image_x_range[0],
                self._confocal_logic.image_y_range[1] - self._confocal_logic.image_y_range[0]))

        # Add the display item to the roi map ViewWidget defined in the UI file
        self._mw.roi_map_ViewWidget.addItem(self.roi_map_image)
        self._mw.roi_map_ViewWidget.setLabel('bottom', 'X position', units='m')
        self._mw.roi_map_ViewWidget.setLabel('left', 'Y position', units='m')

        # Set to fixed 1.0 aspect ratio, since the metaphor is a "map" of the sample
        self._mw.roi_map_ViewWidget.setAspectLocked(lock=True, ratio=1.0)

        # Get the colorscales and set LUT
github pyqtgraph / pyqtgraph / examples / isocurve.py View on Github external
import numpy as np
import pyqtgraph as pg

app = QtGui.QApplication([])

## make pretty looping data
frames = 200
data = np.random.normal(size=(frames,30,30), loc=0, scale=100)
data = np.concatenate([data, data], axis=0)
data = pg.gaussianFilter(data, (10, 10, 10))[frames/2:frames + frames/2]
data[:, 15:16, 15:17] += 1

win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: Isocurve')
vb = win.addViewBox()
img = pg.ImageItem(data[0])
vb.addItem(img)
vb.setAspectLocked()

## generate empty curves
curves = []
levels = np.linspace(data.min(), data.max(), 10)
for i in range(len(levels)):
    v = levels[i]
    ## generate isocurve with automatic color selection
    c = pg.IsocurveItem(level=v, pen=(i, len(levels)*1.5))
    c.setParentItem(img)  ## make sure isocurve is always correctly displayed over image
    c.setZValue(10)
    curves.append(c)

## animate!
ptr = 0
github rafellerc / Pytorch-SiamFC / appSiamFC / display.py View on Github external
self.score_box.setAspectLocked(True)
        self.gt_box.setAspectLocked(True)
        self.ref_box.setAspectLocked(True)

        self.fpsLabel = pg.LabelItem(justify='left')
        MainWindow.addItem(self.fpsLabel, 0, 0)
        self.visibleLabel = MainWindow.addLabel('', 0, 1)
        self.bufferLabel = MainWindow.addLabel('', 0, 2)
        self.nameLabel = MainWindow.addLabel('', 4, 0, colspan=3)
        font = QtGui.QFont()
        font.setPointSize(4)
        self.nameLabel.setFont(font)

        self.score_img = pg.ImageItem()
        self.gt_img = pg.ImageItem()
        self.ref_img = pg.ImageItem()
        self.score_box.addItem(self.score_img)
        self.gt_box.addItem(self.gt_img)
        self.ref_box.addItem(self.ref_img)
        # self.view_box.setRange(QtCore.QRectF(0, 0, 512, 512))
        self.bounding_box = QtWidgets.QGraphicsRectItem()
        self.bounding_box.setPen(QtGui.QColor(255, 0, 0))
        self.bounding_box.setParentItem(self.gt_img)
        self.gt_box.addItem(self.bounding_box)
        brush = QtGui.QBrush(QtGui.QColor(0, 255, 0))
        self.peak = pg.GraphItem(size=30, symbol='+', pxMode=True,
                                 symbolBrush=brush,
                                 symbolPen=None)
        self.peak.setParentItem(self.score_img)
        self.score_box.addItem(self.peak)
        self.peak_pos = None
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 255, alpha=0))
github vasole / pymca / PyMca / plotting / backends / PyQtGraphBackend.py View on Github external
# this sends a mouse event
        self.scene().sigMouseClicked.connect(self._mouseClicked)

        self.__lastMouseClick = ["middle", time.time()]

        self._oldActiveCurve = None
        self._oldActiveCurveLegend = None
        self._logX = False
        self._logY = False
        self._imageItem = None
        if 0:
            import numpy
            x = numpy.arange(10000*200.)
            x.shape = 200, 10000
            self.invertY(True)
            self._imageItem = pg.ImageItem(image=x)
            self._imageItem.setZValue(0)
            #self._imageItem.setCompositionMode(QtGui.QPainter.CompositionMode_Multiply)
            self.addItem(self._imageItem)
github flika-org / flika / plugins / detect_puffs / threshold_cluster.py View on Github external
def linkTif(self):
        self.clusterItem=pg.ImageItem(self.puffs.cluster_im[0])
        self.data_window.imageview.view.addItem(self.clusterItem)
        self.clusterItem.setOpacity(.5)
        self.data_window.sigTimeChanged.connect(self.updateTime)        
        puff=self.puffs.getPuff()
        x=np.floor(puff.kinetics['x']); y=np.floor(puff.kinetics['y'])
        roi_width=self.udc['roi_width']
        r=(roi_width-1)/2
        x0=x-r; x1=x+r+1; y0=y-r; y1=y+r+1;
        pts=[(x0,y0),(x0,y1),(x1,y1),(x1,y0),(x0,y0)]
        self.roi=makeROI('rectangle',pts,self.data_window)
        self.data_window.deleteButtonSignal.disconnect(self.roi.deleteCurrentROI)
        self.redTraces=[]
        self.data_window.keyPressSignal.connect(self.keyPressEvent)
        self.roi.plotSignal.connect(self.linkTracefig)
        self.roi.plot()
github portugueslab / stytra / stytra / gui / camera_display.py View on Github external
self.control_params = self.experiment.camera_state

        # Create the layout for the camera view:
        self.camera_display_widget = pg.GraphicsLayoutWidget()

        # Display area for showing the camera image:
        self.display_area = pg.ViewBox(lockAspect=1, invertY=False)
        self.display_area.setRange(
            QRectF(0, 0, 640, 480), update=True, disableAutoRange=True
        )
        self.scale = 640

        self.display_area.invertY(True)
        # Image to which the frame will be set, initially black:
        self.image_item = pg.ImageItem()
        self.image_item.setImage(np.zeros((640, 480), dtype=np.uint8))
        self.display_area.addItem(self.image_item)

        self.camera_display_widget.addItem(self.display_area)

        # Queue of frames coming from the camera
        if hasattr(experiment, "frame_dispatcher"):
            self.frame_queue = self.experiment.frame_dispatcher.gui_queue
        else:
            self.frame_queue = self.camera.frame_queue

        # Queue of control parameters for the camera:
        self.control_queue = self.camera.control_queue
        self.camera_rotation = self.camera.rotation

        self.layout = QVBoxLayout()
github bbfrederick / rapidtide / rapidtide / OrthoImageItem.py View on Github external
def newViewWindow(view, xdim, ydim, left, top, scalefacx, scalefacy, imgsize, enableMouse=False):
    #print(left, top, scalefacx, scalefacy, imgsize)
    theviewbox = view.addViewBox(enableMouse=enableMouse, enableMenu=False, lockAspect=1.0)
    theviewbox.setAspectLocked()
    # theviewbox.enableAutoRange(enable=False)
    theviewbox.setBackgroundColor([0, 0, 0])
    # theviewbox.setRange(
    #    QtCore.QRectF(0, 0, xdim, ydim), 
    #    xRange=(0, int(xdim - 1)), yRange=(0, int(ydim - 1)),
    #    padding=0.0, disableAutoRange=True)
    # theviewbox.setRange(padding=0.0, disableAutoRange=True)

    theviewfgwin = pg.ImageItem()
    theviewbox.addItem(theviewfgwin)
    theviewfgwin.setZValue(10)
    theviewfgwin.translate(left, top)
    theviewfgwin.scale(scalefacx, scalefacy)

    theviewbgwin = pg.ImageItem()
    theviewbox.addItem(theviewbgwin)
    theviewbgwin.setZValue(0)
    theviewbgwin.translate(left, top)
    theviewbgwin.scale(scalefacx, scalefacy)

    theviewvLine = pg.InfiniteLine(angle=90, movable=False, pen='g')
    theviewvLine.setZValue(20)
    theviewbox.addItem(theviewvLine)
    theviewhLine = pg.InfiniteLine(angle=0, movable=False, pen='g')
    theviewhLine.setZValue(20)
github freesurfer / freesurfer / python / freesurfer / samseg / hdav.py View on Github external
def draw(self):
        self.viewbox_axial.clear()
        self.viewbox_coronal.clear()
        self.viewbox_sagittal.clear()

        for layer in self.layers:
            axial = layer['data'][:, :, int(self.cursor_pos[2])]
            coronal = layer['data'][:, int(self.cursor_pos[1]), :]
            sagittal = layer['data'][int(self.cursor_pos[0]), :, :]
            image_axial = pg.ImageItem(axial)
            image_coronal = pg.ImageItem(coronal)
            image_sagittal = pg.ImageItem(sagittal)
            if 'cmap' in layer and layer['cmap'] is not None:
                start, stop = layer['cmap'].pos[0], layer['cmap'].pos[-1]
                lut = layer['cmap'].getLookupTable(start=start, stop=stop)
                image_axial.setLookupTable(lut)
                image_coronal.setLookupTable(lut)
                image_sagittal.setLookupTable(lut)
            if layer['visible']:
                self.viewbox_axial.addItem(image_axial)
                self.viewbox_coronal.addItem(image_coronal)
                self.viewbox_sagittal.addItem(image_sagittal)

        axial_pos = pg.Point(self.cursor_pos[[0, 1]])
        coronal_pos = pg.Point(self.cursor_pos[[0, 2]])
        sagittal_pos = pg.Point(self.cursor_pos[[1, 2]])
        self.cursor_axial_x.setPos(axial_pos)
github pairinteraction / pairinteraction / gui / pairinteraction.py View on Github external
"""map = np.zeros((width_pixelunits,height_pixelunits)) # x-y-coordinate system, origin is at the bottom left corner                        
                        
                        map[::,::2] = 3
                        map[-1,-1] = 10
                        map[0,0] = 10
                        
                        
                        
                        aspectRatio = map.shape[1]/map.shape[0] # TODO calculate it before"""
                        
                        
                        
                        
                        
                        img = pg.ImageItem(image=map, opacity=alpha, autoDownsample=True, lut=self.lut, levels=[0,1])
                        img.setRect(QtCore.QRectF(posLeft-0.5/self.displayunits2pixelunits_x,self.yMin-0.5/self.displayunits2pixelunits_y,posRight-posLeft,self.yMax-self.yMin+1/self.displayunits2pixelunits_y)) # xMin, yMin, xSize, ySize # TODO energyMin anpassen wegen Pixelgroesse
                        img.setZValue(3)
                        self.ui.graphicsview_potential_plot.addItem(img)
                        
                        dataamount += len(energy)*10
                    
                        del self.buffer_energiesMap_potential[self.colormap_buffer_minIdx]
                        del self.buffer_positionsMap_potential[self.colormap_buffer_minIdx]
                        del self.buffer_overlapMap_potential[self.colormap_buffer_minIdx]
                        self.colormap_buffer_minIdx += 1