Esempio n. 1
0
    def showFFTWaterfall(self, name):
        view = pg.PlotItem(invertY=True)
        view.showGrid(x=True, y=True)
        self.win.addItem(view, colspan=20)
        img = pg.ImageItem(border='w')

        histogram = pg.HistogramLUTItem()
        histogram.setImageItem(img)
        #histogram.setHistogramRange(0,100)
        histogram.gradient.restoreState({
            'ticks': [(0.3333, (0, 255, 255, 255)),
                      (0.6666, (255, 255, 0, 255)), (1, (0, 255, 0, 255)),
                      (0, (64, 64, 255, 64))],
            'mode':
            'rgb'
        })
        histogram.setFixedWidth(128)
        self.win.addItem(histogram)

        img.translate(0, -self.sp.MAX_FFTS)
        view.addItem(img)
        img.setImage(np.rot90(self.sp.ffts[:int(self.sp.FFT_SIZE / 2)]))
        view.setXLink(name)
        img.scale(self.sp.SAMPLE_RATE / self.sp.FFT_SIZE, 1)

        def update():
            img.setImage(np.flip(np.rot90(
                self.sp.ffts))[:int(self.sp.FFT_SIZE / 2)],
                         autoLevels=False)

        self.mainTmr.timeout.connect(update)
Esempio n. 2
0
    def create_img_view(self):
        self.img_view_box = self.pg_layout.addViewBox(0, 1)
        self.img_view_box.setAspectLocked(True)

        self.img_item = pg.ImageItem()
        self.img_view_box.addItem(self.img_item)

        self.left_axis = pg.AxisItem('left', linkView=self.img_view_box)
        self.pg_layout.addItem(self.left_axis, 0, 0)

        self.bot_axis = pg.AxisItem('bottom', linkView=self.img_view_box)
        self.pg_layout.addItem(self.bot_axis, 1, 0, 1, 2)

        self.img_item_left = pg.ImageItem()
        self.img_view_box.addItem(self.img_item_left)

        self.img_plot_item = pg.PlotCurveItem(pen='r')

        self.img_view_box.addItem(self.img_plot_item)

        self.img_histogram_LUT = pg.HistogramLUTItem(self.img_item)
        self.img_histogram_LUT.axis.hide()
        self.pg_layout.addItem(self.img_histogram_LUT, 0, 2)
        self.changeView()

        x = np.linspace(0, 1024)
        y = x
        self.img_plot_item.setData(x=x, y=x)
Esempio n. 3
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # Viewbox
        self.cwidget = pg.GraphicsLayoutWidget()
        self.vb = self.cwidget.addViewBox(row=1, col=1)
        self.vb.setMouseMode(pg.ViewBox.RectMode)
        self.img = pg.ImageItem(axisOrder='row-major')
        self.img.translate(-0.5, -0.5)
        self.vb.addItem(self.img)
        self.vb.setAspectLocked(True)
        self.hist = pg.HistogramLUTItem(image=self.img)
        self.hist.vb.setLimits(yMin=0, yMax=66000)
        self.hist.gradient.loadPreset('greyclip')
        for tick in self.hist.gradient.ticks:
            tick.hide()
        self.cwidget.addItem(self.hist, row=1, col=2)

        self.roiButton = guitools.BetterPushButton('Show ROI')
        self.roiButton.setCheckable(True)
        self.runButton = QtWidgets.QCheckBox('Run')
        self.ROI = guitools.VispyROIVisual(rect_color='yellow',
                                           handle_color='orange')

        # Add elements to GridLayout
        grid = QtWidgets.QGridLayout()
        self.setLayout(grid)
        grid.addWidget(self.cwidget, 0, 0, 1, 6)
        grid.addWidget(self.roiButton, 1, 0, 1, 1)
        grid.addWidget(self.runButton, 1, 1, 1, 1)

        # Connect signals
        self.roiButton.toggled.connect(self.sigROIToggled)
        self.runButton.clicked.connect(self.sigRunClicked)
Esempio n. 4
0
    def createSpectrogramWindow(cls):
        # Interpret image data as row-major instead of col-major
        pg.setConfigOptions(imageAxisOrder='row-major')

        pg.mkQApp()
        cls.spectrogramsWindows.append(pg.GraphicsLayoutWidget())
        # A plot area (ViewBox + axes) for displaying the image
        cls.spectrogramPlotItems.append(cls.spectrogramsWindows[cls.windowIdx].addPlot())
        # Add labels to the axis
        cls.spectrogramPlotItems[cls.windowIdx].setLabel('bottom', "Time", units='sec')
        # If you include the units, Pyqtgraph automatically scales the axis and adjusts the SI prefix (in this case kHz)
        # self.SpectrogramPlotItem.setLabel('left', "Frequency", units='Hz')

        # Item for displaying image data
        cls.spectrogramImageItems.append(pg.ImageItem())
        cls.spectrogramPlotItems[cls.windowIdx].addItem(cls.spectrogramImageItems[cls.windowIdx])
        # Add a histogram with which to control the gradient of the image
        cls.spectrogramHistItems.append(pg.HistogramLUTItem())
        # Link the histogram to the image
        cls.spectrogramHistItems[cls.windowIdx].setImageItem(cls.spectrogramImageItems[cls.windowIdx])

        cls.spectrogramHistItems[cls.windowIdx].gradient.restoreState({'mode': 'rgb','ticks': [(0.5, (0, 182, 188, 255)),
                                                            (1.0, (246, 111, 0, 255)),
                                                            (0.0, (75, 0, 113, 255))]})
        cls.spectrogramHistItems[cls.windowIdx].gradient.saveState()
        # If you don't add the histogram to the window, it stays invisible, but I find it useful.
        cls.spectrogramsWindows[cls.windowIdx].addItem(cls.spectrogramHistItems[cls.windowIdx])
        # Show the window
        cls.spectrogramsWindows[cls.windowIdx].show()    
        cls.windowIdx = cls.windowIdx + 1    
Esempio n. 5
0
def test_NonUniformImage_lut():

    window = pg.GraphicsLayoutWidget()
    viewbox = pg.ViewBox()
    window.setCentralWidget(viewbox)
    window.resize(200, 200)
    window.show()

    x = [1.0, 3.0, 10.0]
    y = [1.0, 2.0, 4.0]
    X, Y = np.meshgrid(x, y, indexing='ij')
    Z = X * Y

    image = NonUniformImage(x, y, Z, border=fn.mkPen('g'))
    viewbox.addItem(image)

    lut = pg.HistogramLUTItem()
    window.addItem(lut)

    image.setLookupTable(lut, autoLevel=True)

    h = image.getHistogram()
    lut.plot.setData(*h)

    QtTest.QTest.qWaitForWindowExposed(window)
    QtTest.QTest.qWait(100)

    assertImageApproved(window, 'nonuniform_image/lut-3x3')
Esempio n. 6
0
    def loadRefImage(self):
        self.file_name = QtWidgets.QFileDialog().getOpenFileName(
            self, "Select Ref Image", '', 'image file(*png *jpeg *tiff *tif )')
        if self.file_name:
            self.ref_image = plt.imread(self.file_name[0])
            if self.ref_image.ndim == 3:
                self.ref_image = self.ref_image.sum(2)
            self.statusbar.showMessage(f'{self.file_name[0]} selected')
        else:
            self.statusbar.showMessage("No file has selected")
            pass

        try:
            self.ref_view.clear()
        except:
            pass

        # A plot area (ViewBox + axes) for displaying the image
        self.p1 = self.ref_view.addPlot(title="")

        # Item for displaying image data
        self.img = pg.ImageItem()
        hist = pg.HistogramLUTItem()
        hist.setImageItem(self.img)
        self.ref_view.addItem(hist)

        self.p1.addItem(self.img)
        self.ref_image = rotate(self.ref_image, -90)
        self.img.setImage(self.ref_image)
        self.img.setCompositionMode(QtGui.QPainter.CompositionMode_Plus)
        # self.img.translate(100, 50)
        # self.img.scale(0.5, 0.5)
        self.img.hoverEvent = self.imageHoverEvent
        self.img.mousePressEvent = self.MouseClickEvent
Esempio n. 7
0
    def setup_figure(self):

        self.graph_layout = pg.GraphicsLayoutWidget(border=(100, 100, 100))
        self.graph_layout.show()
        self.graph_layout.setWindowTitle('pyqtgraph example: ImageItem')

        plot_pos = np.array([[0, 0], [0, 1], [0, 2], [1, 0], [1, 1], [1, 2],
                             [2, 0], [2, 1], [2, 2]])
        self.img_plots = []
        self.img_items = []
        for i in range(9):
            img_plot = self.graph_layout.addPlot(row=plot_pos[i, 0],
                                                 col=plot_pos[i, 1])
            img_item = pg.ImageItem()
            img_plot.addItem(img_item)
            img_plot.showGrid(x=True, y=True)
            img_plot.setAspectLocked(lock=True, ratio=1)
            self.img_plots.append(img_plot)
            self.img_items.append(img_item)

        self.hist_lut = pg.HistogramLUTItem()
        self.graph_layout.addItem(self.hist_lut,
                                  colspan=1,
                                  rowspan=3,
                                  col=3,
                                  row=0)
        self.hist_lut.setImageItem(self.img_items[0])
        #self.hist_lut.vb.setLimits(yMin=0, yMax=1)
        self.hist_lut.sigLookupTableChanged.connect(
            self.on_Lookup_Table_Changed)
        self.hist_lut.sigLevelsChanged.connect(self.on_Lookup_Table_Changed)
Esempio n. 8
0
    def __init__(self, img_arr, binary_array, parent=None, title='ImageWindow'):
        super(OverlayImageWindow, self).__init__(parent)
        self.setWindowTitle(title)
        self.img_arr = img_arr
        self.binary_array = binary_array

        win = pg.GraphicsLayoutWidget()
        self.vb = pg.ViewBox(enableMouse=False, enableMenu=False)

        self.img_item = DragImageItem(img_arr[0])

        pos = np.array([0., 1.])
        color = np.array([[0., 0., 0., 0.], [1., 0., 0., self.alpha]])
        cm = pg.ColorMap(pos, color)
        lut = cm.getLookupTable(0., 1.)

        self.olay_updated.connect(self.update_overlay)

        self.overlay_item = pg.ImageItem(binary_array[0])
        self.overlay_item.setLookupTable(lut)
        self.vb.addItem(self.img_item)
        self.vb.addItem(self.overlay_item)
        self.vb.setAspectLocked()
        win.addItem(self.vb)

        self.circle = QGraphicsEllipseItem(30., 30., 0., 0.)
        self.vb.addItem(self.circle)

        hist = pg.HistogramLUTItem()
        hist.setImageItem(self.img_item)
        win.addItem(hist)

        win.setStyleSheet("background-color:black;")
        self.setCentralWidget(win)
Esempio n. 9
0
    def _initImageItems(self, layout):
        self.win = pg.GraphicsLayoutWidget()
        layout.addWidget(self.win, 1)
        self.win.scene().sigMouseClicked.connect(self.plotClicked)

        self.vb = pgw.ModifiedViewBox(parent=self, lockAspect=True,
                                      invertY=True, enableMenu=False,
                                      enableMouse=True, border=[100, 100, 100])
        self.win.addItem(self.vb)
        # Item for displaying image data
        self.img = pg.ImageItem(viewbox=self.vb)
        self.img.setZValue(100)
        self.vb.addItem(self.img)
        self.maskimg = pg.ImageItem(viewbox=self.vb)
        self.maskimg.setZValue(101)
        self.vb.addItem(self.maskimg)
        self.mask_boundary = pg.ImageItem(viewbox=self.vb)
        self.mask_boundary.setZValue(102)
        self.vb.addItem(self.mask_boundary)
        self.draw = pgw.ClickDrawableImageItem(viewbox=self.vb,
                                               end_draw_callback=self.draw_completed)
        self.draw.setZValue(103)
        self.vb.addItem(self.draw)

        # Contrast/color control
        self.hist = pg.HistogramLUTItem()
        self.win.addItem(self.hist)
        self.hist.vb.setMouseEnabled(y=False)
        self.hist.setImageItem(self.img)
Esempio n. 10
0
    def plot_spectro(self, values, widget):
        fs = 1000  ####sampling frequency
        f, t, Sxx = signal.spectrogram(values, fs)

        pg.setConfigOptions(imageAxisOrder='row-major')
        self.img = pg.ImageItem()
        widget.addItem(self.img)
        # Add a histogram to control the gradient of the image
        self.hist = pg.HistogramLUTItem()
        # Link the histogram to the image
        self.hist.setImageItem(self.img)
        # Fit the min and max levels of the histogram
        self.hist.setLevels(np.min(Sxx), np.max(Sxx))

        self.hist.gradient.restoreState({
            'mode':
            'rgb',
            'ticks': [(0.5, (0, 182, 188, 255)), (1.0, (246, 111, 0, 255)),
                      (0.0, (75, 0, 113, 255))]
        })
        self.img.setImage(Sxx)

        self.img.scale(t[-1] / np.size(Sxx, axis=1),
                       f[-1] / np.size(Sxx, axis=0))

        widget.setXRange(0, t[-1], padding=0)
        widget.setYRange(0, f[-1], padding=0)

        widget.setLimits(xMin=0, xMax=t[-1], yMin=0, yMax=f[-1])
        # Add labels to the axis
        widget.setLabel('bottom', "Time", units='s')

        widget.setLabel('left', "Frequency", units='Hz')
Esempio n. 11
0
    def __init__(self, *args, **kwargs):
        super(Base2DGraph, self).__init__(*args, **kwargs)
        self._plot = self.addPlot()
        self._plot.showGrid(True, True, 0.5)

        self.vb = self.plot.getViewBox()
        self.vb.setAspectLocked()
        self.image_item = pg.ImageItem()
        self._plot.addItem(self.image_item)

        # Contrast/color control
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.image_item)

        self.iso = pg.IsocurveItem(level=0.8, pen='g')
        self.iso_line = pg.InfiniteLine(angle=0, movable=True, pen='g')

        self.iso.setParentItem(self.image_item)
        self.iso.setZValue(5)

        # Draggable line for settings isocurve level
        self.hist.vb.addItem(self.iso_line)
        self.hist.vb.setMouseEnabled(y=False)
        self.iso_line.setValue(0.8)
        self.iso_line.setZValue(1000)

        def update_isocurve():
            self.iso.setLevel(self.iso_line.value())

        self.iso_line.sigDragged.connect(update_isocurve)
Esempio n. 12
0
    def init_plot_area(self):
        win2 = pg.GraphicsLayoutWidget()  #title="Camera")
        win2.setWindowTitle('Camera')

        self.imv = pg.ImageItem(np.random.normal(size=(4096, 3000)))
        imv = self.imv

        view = pg.ViewBox()
        view.setAspectLocked(True)
        view.addItem(imv)
        self.roi = pg.LineSegmentROI([[10, 10], [100, 100]], pen='r')
        self.roi.sigRegionChanged.connect(self.update_cut)
        view.addItem(self.roi)
        win2.addItem(view)

        hist = pg.HistogramLUTItem()
        hist.setImageItem(imv)
        hist.setLevels(0, 2**8)  # 2**12)
        win2.addItem(hist)

        win2.nextRow()
        self.p2 = win2.addPlot(colspan=2)
        self.p2.setMaximumHeight(250)

        self.win2 = win2
Esempio n. 13
0
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)

        self.layout = QtGui.QHBoxLayout(self)
        self.viewport = GraphicsLayoutWidget()
        self.view = self.viewport.addViewBox(colspan=3,
                                             rowspan=3,
                                             lockAspect=False,
                                             enableMenu=True)
        self.img = pg.ImageItem()
        self.view.addItem(self.img)

        # Get the colormap
        colormap = cm.get_cmap("jet")
        colormap._init()
        lut = (colormap._lut * 255).view(
            np.ndarray
        )  # Convert matplotlib colormap from 0-1 to 0 -255 for Qt
        # Apply the colormap
        self.img.setLookupTable(lut)

        self.h = self.viewport.addViewBox(enableMenu=False, colspan=3)
        self.hist = pg.HistogramLUTItem(image=self.img, fillHistogram=False)
        self.hist.setImageItem(self.img)
        self.h.addItem(self.hist)

        self.imv = pg.ImageView(view=self.view, imageItem=self.img)

        self.layout.addWidget(self.imv)
        self.setLayout(self.layout)
Esempio n. 14
0
def plot_image2(data, cmap):
    """
    Plot array as an image.
    :param data: 2-D array
    """
    pl = pg.plot()
    image = pg.ImageItem(border='w')

    pl.addItem(image)

    hist = pg.HistogramLUTItem()
    # Contrast/color control
    hist.setImageItem(image)
    # pl.addItem(hist)

    image.setImage(data)
    #pos = np.array([0., 1., 0.5, 0.25, 0.75])
    #color = np.array([[0, 0, 255, 255], [255, 0, 0, 255], [0, 255, 0, 255], (0, 255, 255, 255), (255, 255, 0, 255)],
    #             dtype=np.ubyte)
    #cmap = pg.ColorMap(pos, color)
    lut = cmap.getLookupTable(0.0, 1.0, 256)
    image.setLookupTable(lut)

    hist.gradient.setColorMap(cmap)
    pl.autoRange()
Esempio n. 15
0
    def drawSpectrogram(self, minFreq=1, maxFreq=1):
        minFreq_Slider = self.minFreqOfSpectrogram
        maxFreq_Slider = self.maxFreqOfSpectrogram
        freq = 1 / self.sampleTime
        ft = fourierTransform(self.editedVoltsData, int(freq))
        ft.deleteRangeOfFrequancy(0, minFreq_Slider)
        ft.deleteRangeOfFrequancy(maxFreq_Slider, int(freq / 2))
        realsAfterEdit = ft.fn_InverceFourier(ft.data_fft)
        frequancyArr, timeArr, Sxx = signal.spectrogram(
            np.array(realsAfterEdit), freq)
        pyqtgraph.setConfigOptions(imageAxisOrder='row-major')

        win = self.SpectrogramViewer
        p1 = win.addPlot()

        img = pyqtgraph.ImageItem()
        p1.addItem(img)
        hist = pyqtgraph.HistogramLUTItem()
        hist.setImageItem(img)
        win.addItem(hist)
        hist.setLevels(np.min(Sxx), np.max(Sxx))
        hist.gradient.restoreState({
            'mode':
            'rgb',
            'ticks': [(0.5, self.RGB_Pallete_1), (1.0, self.RGB_Pallete_2),
                      (0.0, self.RGB_Pallete_3)]
        })
        img.setImage(Sxx)
        img.scale(timeArr[-1] / np.size(Sxx, axis=1),
                  frequancyArr[-1] / np.size(Sxx, axis=0))
        p1.setLimits(xMin=0, xMax=timeArr[-1], yMin=0, yMax=frequancyArr[-1])
        p1.setLabel('bottom', "Time", units='s')
        p1.setLabel('left', "Frequency", units='Hz')
Esempio n. 16
0
    def __init__(self, *args, **kwargs):

        super().__init__(*args, **kwargs)

        self.img = pg.ImageItem()
        self.plot.addItem(self.img)

        # Isocurve draplotsg
        self.iso = pg.IsocurveItem(level=1000, pen=color_palette[2])
        self.iso.setParentItem(self.img)
        self.iso.setZValue(5)

        # Contrast/color control
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.img)
        self.plots.addItem(self.hist)

        # Draggable line for setting isocurve level
        self.isoLine = pg.InfiniteLine(angle=0,
                                       movable=True,
                                       pen=color_palette[2])
        self.hist.vb.addItem(self.isoLine)
        self.hist.vb.setMouseEnabled(
            y=False)  # makes user interaction a little easier
        self.isoLine.setValue(1000)
        self.isoLine.setZValue(1000)  # bring iso line above contrast controls
        self.isoLine.sigDragged.connect(self.updateIsocurve)

        # Monkey-patch the image to use our custom hover function.
        # This is generally discouraged (you should subclass ImageItem instead),
        # but it works for a very simple use like this.
        self.img.hoverEvent = self.imageHoverEvent

        self.img.translate(-0.5, -0.5)

        self.scalex = 1
        self.scaley = 1

        self.cx = 0
        self.cy = 0

        self.nplots = 0

        self.table.setColumnCount(3)
        self.table.setRowCount(2)
        self.table.setColumnWidth(0, 200)
        self.table.setColumnWidth(1, 150)
        self.table.setColumnWidth(2, 150)
        self.table.setHorizontalHeaderLabels(['xvalue', 'yarray', 'zarray'])

        self.combox = NumericDataCombo(self.ap.df)
        self.comboy = NumericDataCombo(self.ap.df)
        self.comboz = NumericDataCombo(self.ap.df)

        self.table.setCellWidget(0, 0, self.combox)
        self.table.setCellWidget(0, 1, self.comboy)
        self.table.setCellWidget(0, 2, self.comboz)

        self.mk_buttons()
Esempio n. 17
0
    def __init__(self):
        TemplateBaseClass.__init__(self)
        self.setWindowTitle('pyqtgraph example: Qt Designer')

        # Create the main window
        self.ui = WindowTemplate()
        self.ui.setupUi(self)
        #frame view
        self.vb = pg.ViewBox()
        self.vb.setAspectLocked()
        self.ui.frameView.setCentralItem(self.vb)
        self.frameView = pg.ImageItem()
        self.vb.addItem(self.frameView)
        #load frames button
        self.ui.loadFrames.clicked.connect(self.loadFrames)
        #save data button
        self.ui.saveTracks.clicked.connect(self.saveTracks)
        self.ui.loadTracks.clicked.connect(self.loadTracks)

        ##scroll bar
        self.ui.frameScrollBar.valueChanged.connect(
            self.frameScrollBar_valueChanged)

        ### ROI's
        #int_pnt = [14.171640, 5.061034]
        int_pnt = (0, 0)
        self.i1_init = i1
        self.i1_init = [[x + int_pnt[0], y + int_pnt[1]]
                        for x, y in self.i1_init]

        self.i2_init = i2
        self.i2_init = [[x + int_pnt[0], y + int_pnt[1]]
                        for x, y in self.i2_init]

        self.thorax_poly = PolyMaskROI(self.i1_init, closed=True, pen=(1, 6))
        self.basalar_poly = PolyMaskROI(self.i2_init, closed=True, pen=(1, 3))

        self.thorax_pos = np.zeros(
            (1000, np.shape(self.i1_init)[0], np.shape(self.i1_init)[1]))
        self.thorax_pos[:, :, :] = np.array(self.i1_init)[np.newaxis, :, :]

        self.basalar_pos = np.zeros(
            (1000, np.shape(self.i2_init)[0], np.shape(self.i2_init)[1]))
        self.basalar_pos[:, :, :] = np.array(self.i2_init)[np.newaxis, :, :]

        self.vb.addItem(self.thorax_poly)
        self.thorax_poly.sigRegionChanged.connect(self.poly_state_change)

        self.vb.addItem(self.basalar_poly)
        self.basalar_poly.sigRegionChanged.connect(self.poly_state_change)

        # Contrast/color control
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.frameView)
        self.ui.frameHist.setCentralItem(self.hist)

        self.current_frame = 0
        self.show()
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.data = []
        self.mean_data = []
        self.pattern = []
        self.pattern_grid = []

        # Image Widget
        imageWidget = pg.GraphicsLayoutWidget()
        self.img_vb = imageWidget.addViewBox(row=0, col=0)
        self.img_vb.setMouseMode(pg.ViewBox.PanMode)
        self.img = pg.ImageItem()
        self.img.translate(-0.5, -0.5)
        self.img_vb.addItem(self.img)
        self.img_vb.setAspectLocked(True)
        self.img_hist = pg.HistogramLUTItem(image=self.img)
        imageWidget.addItem(self.img_hist, row=0, col=1)

        self.show_mean_btn = QtGui.QPushButton()
        self.show_mean_btn.setText('Show mean image')
        self.show_mean_btn.pressed.connect(self.show_mean)

        frame_label = QtGui.QLabel('Frame # ')
        self.frame_nr = QtGui.QLineEdit('0')
        self.frame_nr.textChanged.connect(self.setImgSlice)
        self.frame_nr.setFixedWidth(45)

        self.slider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
        self.slider.setMinimum(0)
        self.slider.setMaximum(np.shape(self.data)[0])
        self.slider.setTickInterval(5)
        self.slider.setSingleStep(1)
        self.slider.valueChanged[int].connect(self.slider_moved)

        self.pattern_scatter = pg.ScatterPlotItem()
        self.pattern_scatter.setData(pos=[[0, 0], [10, 10], [20, 20], [30, 30],
                                          [40, 40]],
                                     pen=pg.mkPen(color=(255, 0, 0),
                                                  width=0.5,
                                                  style=QtCore.Qt.SolidLine,
                                                  antialias=True),
                                     brush=pg.mkBrush(color=(255, 0, 0),
                                                      antialias=True),
                                     size=1,
                                     pxMode=False)

        layout = QtGui.QGridLayout()
        self.setLayout(layout)

        layout.addWidget(self.show_mean_btn, 0, 0)
        layout.addWidget(self.slider, 0, 1)
        layout.addWidget(frame_label, 0, 2)
        layout.addWidget(self.frame_nr, 0, 3)
        layout.addWidget(imageWidget, 1, 0, 1, 4)

        self._show_pat = False
        self.pat_grid_made = False
Esempio n. 19
0
    def __init__(self, parent=None):
        # initialization of the superclass
        super(VideoMainWindow, self).__init__(parent)
        # setup the GUI
        self.setupUi(self)
        pg.setConfigOptions(background=pg.mkColor(0.5))
        pg.setConfigOptions(foreground=pg.mkColor(0.3))
        self.setWindowTitle('pyqtgraph example: Image Analysis')

        # Preserve plot area's aspect ration so image always scales correctly
        self.graphicsView.p1.setAspectLocked(True)

        # Use a file dialog to choose tiff stack
        file, mask = QFileDialog.getOpenFileName(self, 'Open a .tif/.tiff stack')
        # Read image data
        self.img_data_raw = volread(file)
        frames = self.img_data_raw.shape[0]

        # Transpose second and third axes (y, x) to correct orientation (x, y)
        self.img_data = np.transpose(self.img_data_raw, (0, 2, 1))
        # Flip each frame in the left/right direction, expected to be up/down
        for i in range(frames):
            self.img_data[i] = np.fliplr(self.img_data[i])

        self.ptr = 0
        self.lastTime = ptime.time()
        self.fps = None
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.update)
        self.timer.start(50)    # 50 ms =~ 20 fps

        # Levels/color control with a histogram
        # TODO try with a HistogramLUTWidget
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.graphicsView.img)
        self.graphicsView.widget.addItem(self.hist)

        # Isocurve drawing
        self.iso = pg.IsocurveItem(level=0.8, pen='g')
        self.iso.setParentItem(self.graphicsView.img)
        self.iso.setZValue(5)

        # Draggable line for setting isocurve level
        self.isoLine = pg.InfiniteLine(angle=0, movable=True, pen='g')
        self.hist.vb.addItem(self.isoLine)
        self.hist.vb.setMouseEnabled(y=False)  # makes user interaction a little easier
        self.isoLine.setValue(0.8)
        self.isoLine.setZValue(1000)  # bring iso line above contrast controls
        self.isoLine.sigDragged.connect(self.updateIsocurve)

        # Generate image data
        self.graphicsView.img.setImage(self.img_data[0])
        # self.graphicsView.img.scale(self.img_data.shape[1], self.img_data.shape[2])
        self.hist.setLevels(self.img_data.min(), self.img_data.max())

        # build isocurves from smoothed data
        self.isoLine.setValue(self.img_data.max() / 2)
        self.iso.setData(pg.gaussianFilter(self.img_data[0], (2, 2)))
Esempio n. 20
0
    def setup_figure(self):

        #if hasattr(self, 'graph_layout'):
        #    self.graph_layout.deleteLater() # see http://stackoverflow.com/questions/9899409/pyside-removing-a-widget-from-a-layout
        #    del self.graph_layout
            
        ui = self.ui = load_qt_ui_file(sibling_path(__file__, 'andor_ccd_readout.ui'))
        
        ## ui connection
        self.hw = andor = self.app.hardware['andor_ccd']
        andor.settings.exposure_time.connect_to_widget(ui.andor_ccd_int_time_doubleSpinBox)
        andor.settings.em_gain.connect_to_widget(ui.andor_ccd_emgain_doubleSpinBox)
        andor.settings.temperature.connect_to_widget(ui.andor_ccd_temp_doubleSpinBox)
        andor.settings.ccd_status.connect_to_widget(ui.andor_ccd_status_label)
        andor.settings.shutter_open.connect_to_widget(ui.andor_ccd_shutter_open_checkBox)
        
        self.settings.bg_subtract.connect_to_widget(ui.andor_ccd_bgsub_checkBox)
        ui.andor_ccd_acquire_cont_checkBox.stateChanged.connect(self.start_stop)
        ui.andor_ccd_acq_bg_pushButton.clicked.connect(self.acquire_bg_start)
        ui.andor_ccd_read_single_pushButton.clicked.connect(self.acquire_single_start)
        
        andor.settings.temp_status.connect_to_widget(self.ui.temp_status_label)
        andor.settings.temp_setpoint.connect_to_widget(self.ui.temp_setpoint_doubleSpinBox)
        
        self.settings.save_h5.connect_to_widget(self.ui.save_h5_checkBox)
        
        andor.settings.connected.connect_to_widget(self.ui.hw_connect_checkBox)
        
        self.settings.wl_calib.connect_to_widget(self.ui.wl_calib_comboBox)


        #### PLot window
        self.graph_layout = pg.GraphicsLayoutWidget()
        self.ui.plot_groupBox.layout().addWidget(self.graph_layout)
        
        self.spec_plot = self.graph_layout.addPlot()
        self.spec_plot_line = self.spec_plot.plot([1,3,2,4,3,5])
        self.spec_plot.enableAutoRange()
        self.spec_infline = pg.InfiniteLine(movable=True, angle=90, label='x={value:0.2f}', 
                       labelOpts={'position':0.1, 'color': (200,200,100), 'fill': (200,200,200,50), 'movable': True})
        self.spec_plot.addItem(self.spec_infline)

        
        
        self.graph_layout.nextRow()
        
        self.img_plot = self.graph_layout.addPlot()
        #self.img_plot.getViewBox().setLimits(minXRange=-10, maxXRange=100, minYRange=-10, maxYRange=100)
        self.img_plot.showGrid(x=True, y=True)
        self.img_plot.setAspectLocked(lock=True, ratio=1)
        self.img_item = pg.ImageItem()
        self.img_plot.addItem(self.img_item)


        self.hist_lut = pg.HistogramLUTItem()
        self.hist_lut.autoHistogramRange()
        self.hist_lut.setImageItem(self.img_item)
        self.graph_layout.addItem(self.hist_lut)
Esempio n. 21
0
    def setup_figure(self):

        if hasattr(self, 'graph_layout'):
            self.graph_layout.deleteLater(
            )  # see http://stackoverflow.com/questions/9899409/pyside-removing-a-widget-from-a-layout
            del self.graph_layout

        #self.ui = self.graph_layout = pg.GraphicsLayoutWidget(border=(100,100,100))
        #self.ui.setWindowTitle(self.name)
        self.ui = load_qt_ui_file(
            sibling_path(__file__, "winspec_remote_readout.ui"))

        self.graph_layout = pg.GraphicsLayoutWidget(border=(100, 100, 100))
        self.ui.plot_groupBox.layout().addWidget(self.graph_layout)

        self.spec_plot = self.graph_layout.addPlot()
        self.spec_plot_line = self.spec_plot.plot([1, 3, 2, 4, 3, 5])
        self.spec_plot.enableAutoRange()

        self.infline = pg.InfiniteLine(movable=True,
                                       angle=90,
                                       label='x={value:0.2f}',
                                       labelOpts={
                                           'position': 0.8,
                                           'color': (200, 200, 100),
                                           'fill': (200, 200, 200, 50),
                                           'movable': True
                                       })
        self.spec_plot.addItem(self.infline)

        self.graph_layout.nextRow()

        if self.SHOW_IMG_PLOT:
            self.img_plot = self.graph_layout.addPlot()
            self.img_item = pg.ImageItem()
            self.img_plot.addItem(self.img_item)
            self.img_plot.showGrid(x=True, y=True)
            self.img_plot.setAspectLocked(lock=True, ratio=1)

            self.hist_lut = pg.HistogramLUTItem()
            self.hist_lut.autoHistogramRange()
            self.hist_lut.setImageItem(self.img_item)
            self.graph_layout.addItem(self.hist_lut)

        ### Widgets
        self.settings.continuous.connect_to_widget(self.ui.continuous_checkBox)
        self.settings.wl_calib.connect_to_widget(self.ui.wl_calib_comboBox)
        self.settings.save_h5.connect_to_widget(self.ui.save_h5_checkBox)

        self.ui.start_pushButton.clicked.connect(self.start)
        self.ui.interrupt_pushButton.clicked.connect(self.interrupt)
        self.app.hardware[
            'winspec_remote_client'].settings.acq_time.connect_to_widget(
                self.ui.acq_time_doubleSpinBox)
        self.settings.n_accumulations.connect_to_widget(
            self.ui.n_accumulations_doubleSpinBox)
    def setup_figure(self):

        self.plot_items = dict()
        self.img_items = dict()
        self.hist_luts = dict()
        self.display_image_maps = dict()
        self.cross_hair_lines = dict()

        for ii, name in enumerate(self.names):
            if (ii % 2) - 1:
                self.graph_layout.nextRow()
            plot = self.plot_items[name] = self.graph_layout.addPlot(
                title=name)
            img_item = self.img_items[name] = pg.ImageItem()
            img_item.setOpts(axisOrder='row-major')
            img_item.setAutoDownsample(True)
            plot.addItem(img_item)
            plot.showGrid(x=True, y=True)
            plot.setAspectLocked(lock=True, ratio=1)

            vLine = pg.InfiniteLine(angle=90, movable=False)
            hLine = pg.InfiniteLine(angle=0, movable=False)

            self.cross_hair_lines[name] = hLine, vLine
            plot.addItem(vLine, ignoreBounds=True)
            plot.addItem(hLine, ignoreBounds=True)

            hist_lut = self.hist_luts[name] = pg.HistogramLUTItem()
            hist_lut.setImageItem(img_item)
            self.graph_layout.addItem(hist_lut)

        self.graph_layout.nextRow()
        self.optimizer_plot_adc = self.graph_layout.addPlot(
            title='Analog Optimizer', colspan=2)
        self.optimizer_plot_adc.addLegend()
        self.optimizer_plot_adc.showButtons()
        self.optimizer_plot_adc.setLabel('left', text='SEM Signal', units='V')

        self.optimizer_plot_ctr = self.graph_layout.addPlot(
            title='Counter Optimizer', colspan=2)
        self.optimizer_plot_ctr.addLegend()
        self.optimizer_plot_ctr.showButtons()
        self.optimizer_plot_ctr.setLabel('left', text='Count Rate', units='Hz')

        self.hist_buffer_plot_lines = dict()

        opt_plots = dict(
            ai0=self.optimizer_plot_adc,
            ai1=self.optimizer_plot_adc,
            ctr0=self.optimizer_plot_ctr,
            ctr1=self.optimizer_plot_ctr,
        )

        for i, name in enumerate(self.names):
            self.hist_buffer_plot_lines[name] = opt_plots[name].plot(
                pen=(i, len(self.names)), name=name)
Esempio n. 23
0
    def __init__(self):
        super().__init__()
        self.setObjectName("Contour")
        self.plot = self.addPlot()
        self.image = pg.ImageItem()
        self.contour = self.plot.addItem(self.image)

        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.image)
        self.addItem(self.hist)
Esempio n. 24
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.image = None

        self.toolbar = QToolBar('setting', self)

        self.autoLevel = True
        self.autoLevelAction = QAction(QIcon(':/icons/autoLevel.png'),
                                       'Auto Level', self)
        self.autoLevelAction.setCheckable(True)
        self.autoLevelAction.setChecked(True)
        self.toolbar.addAction(self.autoLevelAction)

        self.crosshairAction = QAction(QIcon(':/icons/crosshair.png'),
                                       'Cross Hair', self)
        self.crosshairAction.setCheckable(True)
        self.crosshairAction.setChecked(False)
        self.toolbar.addAction(self.crosshairAction)
        self.toolbar.setIconSize(QSize(16, 16))

        self.graphicsLayout = pg.GraphicsLayoutWidget(self)

        self.plot = self.graphicsLayout.addPlot()
        self.plot.setAspectLocked(True)

        self.imageItem = pg.ImageItem()
        self.plot.addItem(self.imageItem)
        self.vLine = pg.InfiniteLine(angle=90, movable=False)
        self.hLine = pg.InfiniteLine(angle=0, movable=False)
        self.plot.addItem(self.vLine, ignoreBounds=True)
        self.plot.addItem(self.hLine, ignoreBounds=True)

        self.histogram = pg.HistogramLUTItem()
        self.histogram.setImageItem(self.imageItem)
        # self.histogram.vb.setMouseEnabled(y=False)
        self.graphicsLayout.addItem(self.histogram)

        self.label = pg.LabelItem(justify='left')
        self.graphicsLayout.nextRow()
        self.graphicsLayout.addItem(self.label)

        self.mainLayout = QVBoxLayout()
        self.mainLayout.setContentsMargins(0, 0, 0, 0)
        self.mainLayout.addWidget(self.toolbar)
        self.mainLayout.addWidget(self.graphicsLayout)
        self.setLayout(self.mainLayout)

        self.autoLevelAction.triggered.connect(self.onAutoLevelAction)
        self.crosshairAction.triggered.connect(self.onCrosshairAction)
        self.proxy = pg.SignalProxy(self.imageItem.scene().sigMouseMoved,
                                    rateLimit=60,
                                    slot=self.onMouseMoved)

        self.onCrosshairAction(False)
Esempio n. 25
0
    def __init__(self, window):
        super().setupUi(window)

        self.look_timer = QTimer()
        self.look_timer.timeout.connect(self.user_look_timer_timeout_handler)
        self.look_timer.setTimerType(0)
        self.look_timer.start(20)

        # self.btn_save_image.clicked.connect(self.user_btn_save_image_click_handler)

        self.cameraSystem = None
        self.tt = 0

        pg.setConfigOptions(antialias=True)
        self.graphicsWidget = pg.GraphicsLayoutWidget()
        p1 = self.graphicsWidget.addPlot(title="image")

        # Item for displaying image data
        self.image = pg.ImageItem()

        p1.addItem(self.image)

        # Contrast/color control
        self.hist = pg.HistogramLUTItem()
        self.hist.setImageItem(self.image)
        self.graphicsWidget.addItem(self.hist)
        self.hist.setHistogramRange(0, 100)
        # Generate image data
        # data = np.random.random(size=(480, 640))
        # for i in range(0, 480):
        #     for j in range(0, 640):
        #         data[i][j] = 200
        # self.image.setImage(data)

        self.grid_graph.addWidget(self.graphicsWidget)

        # camera init
        self.cameraSystem = PointCloud.CameraSystem()

        self.devices = self.cameraSystem.scan()

        if len(self.devices) == 1:
            print(" Find one device.")
            self.user_camera_window = ShowDepthNoGUI.MainWindow(
                self.cameraSystem, self.devices)
            # key = input("Input enter key to quit.")
            # print(" Quit now.")
            # window.stop()
        else:
            print(" No device found.")

            print(" before del  cameraSystem.")
            del self.cameraSystem
            print(" after del  cameraSystem.")
            cameraSystem = None
Esempio n. 26
0
 def init_graph_spatial(self):
     self.winI = self.UI.MainGraphView
     # 2D Image View
     self.plotSpatial = self.winI.addPlot(title="Spatial image")  # plot area (ViewBox + axes) for displaying the image
     self.imgSpatial = pg.ImageItem() # item for displaying image data: either a 2D numpy array or a 3D array
     self.plotSpatial.addItem(self.imgSpatial)
     # Histrogramm
     hist = pg.HistogramLUTItem()
     hist.setImageItem(self.imgSpatial)
     hist.setMaximumWidth(150)
     self.winI.addItem(hist)
Esempio n. 27
0
 def init_graph_ARPES(self):
     self.winA= self.UI.MainGraphView_2
     # 2D Image View
     self.plotARPES = self.winA.addPlot(title="ARPES image")
     self.imgARPES = pg.ImageItem() 
     self.plotARPES.addItem(self.imgARPES)   
     # Histrogramm
     hist = pg.HistogramLUTItem()
     hist.setImageItem(self.imgARPES)
     hist.setMaximumWidth(150)
     self.winA.addItem(hist) 
Esempio n. 28
0
    def __init__(self):
        super().__init__()

        self.ctx = zmq.Context()
        self.frame_sub = self.ctx.socket(zmq.SUB)
        self.frame_sub.connect(f'tcp://pi-meso.local:{Ports.CAM_FRAME}')
        self.frame_sub.subscribe(b'')
        self.frame_sub.rcvtimeo = 10

        self.frame_times = deque(maxlen=100)
        self.frame = None

        self.setGeometry(50, 50, self.init_width, self.init_height)
        self.setWindowTitle('Preview')

        # Initialize a central widget and a main layout.
        self._central_widget = QtGui.QWidget(self)
        self.setCentralWidget(self._central_widget)
        self._layout = QtGui.QVBoxLayout()
        self._central_widget.setLayout(self._layout)
        self.setAutoFillBackground(True)

        #-----------------------------------------------------------------------
        # Initialize image viewing area.

        # - Initialize a graphics layout for the image area.
        self._graphics_layout = pg.GraphicsLayoutWidget()
        self._layout.addWidget(self._graphics_layout)

        # - Add a view box to enable scaling/panning and mouse drags.
        self._view_box = self._graphics_layout.addViewBox(lockAspect=True,
                                                          row=0,
                                                          col=0,
                                                          invertY=True)
        self._view_box.setMenuEnabled(False)

        # - Add a image item to the view box.
        self._image = pg.ImageItem()
        self._view_box.addItem(self._image)

        #-----------------------------------------------------------------------
        # Initialize histogram

        # - Initialize other attributes and state variables.

        self.hist = pg.HistogramLUTItem(self._image)
        self._graphics_layout.addItem(self.hist)

        self.input_timer = QtCore.QTimer()
        self.input_timer.timeout.connect(self.get_input)
        self.input_timer.start(20)

        self._update()
        self.show()
    def buildHistogram(self):
        pg.setConfigOption('background', 'k')
        pg.setConfigOptions(imageAxisOrder='row-major')
        self.histogram = pg.GraphicsLayoutWidget()

        self.inf2 = pg.InfiniteLine(movable=False,
                                    angle=90,
                                    label='t={value:0.2f}',
                                    labelOpts={
                                        'position': 0.5,
                                        'color': (0, 0, 0),
                                        'fill': (200, 200, 200, 50),
                                        'movable': False
                                    })
        self.inf3 = pg.InfiniteLine(movable=True,
                                    angle=0,
                                    label='t={value:0.2f}',
                                    labelOpts={
                                        'position': 0.5,
                                        'color': (0, 0, 0),
                                        'fill': (200, 200, 200, 50),
                                        'movable': True
                                    })
        self.inf3.setPos([0, 1000])
        self.histogramPlot = self.histogram.addPlot()
        img = pg.ImageItem()
        self.histogramPlot.addItem(img)
        self.histogramPlot.addItem(self.inf2)
        self.histogramPlot.addItem(self.inf3)
        hist = pg.HistogramLUTItem()
        hist.setImageItem(img)
        self.histogram.addItem(hist)
        hist.setLevels(np.min(self.Sxx), np.max(self.Sxx))

        hist.gradient.restoreState({
            'mode':
            'rgb',
            'ticks': [(0.5, (0, 182, 188, 255)), (1.0, (246, 111, 0, 255)),
                      (0.0, (75, 0, 113, 255))]
        })
        img.setImage(self.Sxx)
        img.scale(self.t[-1] / np.size(self.Sxx, axis=1),
                  self.f[-1] / (np.size(self.Sxx, axis=0)))
        self.histogramPlot.setLimits(xMin=0,
                                     xMax=self.t[-1],
                                     yMin=0,
                                     yMax=self.f[-1])
        self.histogramPlot.setLabel('bottom', "Time", units='s')
        self.histogramPlot.setLabel('left', "Frequency", units='Hz')

        plt.pcolormesh(self.t, self.f, self.Sxx)
        plt.ylabel('Frequency [Hz]')
        plt.xlabel('Time [sec]')
        plt.colorbar()
Esempio n. 30
0
    def makeSpectrum(self):

        if self.nameFileWave == "":
            overlap = self.dlugoscZakladki(
                self.comboBoxDlugoscZakladki.currentText())
            window = self.comboBoxOkno.currentText().lower()
            nperseg = int(self.comboBoxDlugoscProbki.currentText())
        else:

            overlap = self.dlugoscZakladki(
                self.comboBoxDlugoscZakladki.currentText())
            window = self.comboBoxOkno.currentText().lower()
            nperseg = int(self.comboBoxDlugoscProbki.currentText())

            tempwindow = get_window(window, nperseg)
            tempoverlap = nperseg * overlap
            tempoverlap = int(round(tempoverlap))

            try:
                f, t, S = self.stft(self.tempy, self.tempRegionRate,
                                    tempwindow, nperseg, tempoverlap, window)
                S = 20 * np.log10(S)
                self.plotSonogram.close()
                self.plotSonogram = pg.PlotWidget()
                self.plotSonogram.setTitle("SPEKTOGRAM")
                self.plotSonogram.setLabel('bottom', "Czas", units='s')
                self.plotSonogram.setLabel('left', "Czestotliwosc", units='Hz')

                pg.setConfigOptions(imageAxisOrder='row-major')
                self.img = pg.ImageItem()
                self.plotSonogram.addItem(self.img)
                hist = pg.HistogramLUTItem()
                hist.setImageItem(self.img)
                hist.setLevels(np.min(S), np.max(S))
                hist.gradient.restoreState({
                    'mode':
                    'rgb',
                    'ticks': [(0.0, (0, 255, 255, 255)),
                              (0.25, (0, 0, 255, 255)), (0.5, (0, 0, 0, 255)),
                              (0.75, (255, 0, 0, 255)),
                              (1.0, (255, 255, 0, 255))]
                })
                self.img.setImage(S)
                self.img.scale(t[-1] / np.size(S, axis=1),
                               f[-1] / np.size(S, axis=0))
                self.plotSonogram.setLimits(xMin=0,
                                            xMax=t[-1],
                                            yMin=0,
                                            yMax=f[-1])
                self.verticalLayout.addWidget(self.plotSonogram)

            except:
                pass