Example #1
0
    def __init__(self, *args, positions: np.array=None, data: np.array=None, colormap: str=None, **kwargs):
        super().__init__(*args, **kwargs)

        # Initialize data structures
        self.positions = positions
        self.data = data
        self.rgb_data: Union[None, np.array] = None
        self.polygons: List[QtCore.QPolygonF] = []
        self.xmin, self.xmax = 0, 0
        self.ymin, self.ymax = 0, 0
        if positions is not None and data is not None:
            self.calc_lims()
        elif not (positions is None and data is None):
            raise ValueError("Either positions and data must both be given, or neither.")

        # Initialize menus
        self.menu = None
        self.gradientSelectorMenu = None

        # Create LUT item
        self._LUTitem = HistogramLUTItem()
        self._LUTitem.sigLookupTableChanged.connect(self.changedColorScale)
        self._LUTitem.sigLevelChangeFinished.connect(self.updateRGBData)
        if colormap is not None:
            self.changeColorScale(name=colormap)
        else:
            self.changeColorScale(name=DEFAULT_CMAP)

        # And update color and polygon data
        if self.data is not None:
            self.updateRGBData()
            self.calculate_polygons()

        # Attach a signal handler on parent changed
        self._parent = None
Example #2
0
 def populate_spectrogram_widget(self, widget: GraphicsLayoutWidget,
                                 game_name: str, player_name: PlayerName,
                                 electrode_name: str):
     # https://stackoverflow.com/questions/51312923/plotting-the-spectrum-of-a-wavfile-in-pyqtgraph-using-scipy-signal-spectrogram
     f, t, Sxx = self._acquire_spectrogram_signal(game_name, player_name,
                                                  electrode_name)
     plot = widget.addPlot()
     plot.setTitle('Frequency over time for electrode %s' %
                   ELECTRODES[electrode_name])
     img = ImageItem()
     plot.addItem(img)
     hist = HistogramLUTItem()
     hist.setImageItem(img)
     widget.addItem(hist)
     hist.setLevels(np.min(Sxx), np.max(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(Sxx)
     img.scale(t[-1] / np.size(Sxx, axis=1), f[-1] / np.size(Sxx, axis=0))
     plot.setLimits(xMin=0, xMax=t[-1], yMin=0, yMax=f[-1])
     plot.setLabel('bottom', "Time", units='s')
     plot.setLabel('left', "Frequency", units='Hz')
Example #3
0
 def __init_ui__(self):
     self.setWindowTitle('Image Viewer')
     self.image_plot = self.addPlot()
     self.image_plot.vb.setAspectLocked()
     self.image_plot.vb.invertY()
     self.image_item = ImageItem()
     self.image_plot.addItem(self.image_item)
     self.hist = HistogramLUTItem()
     self.hist.setImageItem(self.image_item)
     self.addItem(self.hist)
Example #4
0
 def _init_ui(self, **kwargs):
     self.setWindowTitle('Image Viewer')
     self.image_plot = self.addPlot(**kwargs)
     self.image_plot.vb.setAspectLocked()
     self.image_plot.vb.invertY()
     self.image_item = ImageItem()
     self.image_plot.addItem(self.image_item)
     self.image_plot.setMenuEnabled(False)
     self.hist = HistogramLUTItem()
     self.hist.setImageItem(self.image_item)
     self.addItem(self.hist)
     self.hist.vb.menu = CustomViewBoxMenu(self.hist.vb)
     self.hist.vb.menu.sigSigmaChanged.connect(self.set_sigma_factor)
     self.hist.vb.menu.sigRangeAsDefault.connect(self.set_limit_as_default)
     self.hist.vb.menu.sigUseClahe.connect(self.enable_clahe)
Example #5
0
    def __init__(self, setpoint_x, setpoint_y, *args, colormap=None, **kwargs):
        # Create the attached histogram
        self._LUTitem = HistogramLUTItem()

        # Initialize self
        super().__init__(setpoint_x,
                         setpoint_y,
                         *args,
                         colormap=colormap,
                         **kwargs)

        # Update _LUTitem
        self._LUTitem.setImageItem(self)
        self._LUTitem.autoHistogramRange()  # enable autoscaling

        # Attach a signal handler on parent changed
        self._parent = None
    def _create_color_bar(self,
                          orientation: Optional[Orientation] = None,
                          **kwargs) -> None:

        self._color_bar_orientation = orientation or Orientation.Vertical
        if self._color_bar_orientation == Orientation.Vertical:
            color_bar: HistogramLUTItem = HistogramLUTItem(
                self._image, **kwargs)
            # color_bar: HistogramLUTItem = HistogramLUTItem(**kwargs)
            # for item in self._images:
            #     self._color_bar.setImageItem(item)
        else:
            raise NotImplementedError

        self._view.addItem(color_bar, row=0, col=1)
        # self._raw.addItem(self._color_bar)

        self._color_bar = ColorBar(color_bar, self._figure, self._image)

        if self._data_range is not None:
            self._color_bar.range(self._data_range)
Example #7
0
    def __init__(self, parent=None):
        # initialization of widget
        super(GraphicsWidget, self).__init__(parent)

        # Create a central Graphics Layout Widget
        self.widget = GraphicsLayoutWidget()

        # A plot area (ViewBox + axes) for displaying the image
        self.p1 = self.widget.addPlot()
        # Item for displaying an array of image data stacks
        self.stacks = []
        img = ImageItem()
        self.p1.addItem(img)
        self.stacks.append(img)

        # create a vertical box layout
        self.vbl = QVBoxLayout()
        # add widget to vertical box
        self.vbl.addWidget(self.widget)
        # set the layout to the vertical box
        self.setLayout(self.vbl)

        # Levels/color control with a histogram
        # self.hist = HistogramLUTWidget()
        # self.hist.setImageItem(self.img)
        # parent.horizontalLayout_View.addWidget(self.hist)
        # # self.widget.addWidget(self.hist, 0, 1)
        # self.hist.vb.setMouseEnabled(y=False)  # makes user interaction a little easier

        # Create an array of histograms
        self.histograms = []
        # Levels/color control with a histogram
        hist = HistogramLUTItem()
        hist.vb.setMouseEnabled(
            y=False)  # makes user interaction a little easier
        hist.setImageItem(img)
        self.widget.addItem(hist)
        self.histograms.append(hist)
Example #8
0
    def __init__(self, parent=None):
        # initialization of widget
        super(GraphicsWidget, self).__init__(parent)

        # Create a central Graphics Layout Widget
        self.widget = GraphicsLayoutWidget()

        # A plot area (ViewBox + axes) for displaying the image
        self.p1 = self.widget.addPlot()
        # Item for displaying image data
        self.img_item = ImageItem()
        self.img_item.axisOrder = 'row-major'
        self.p1.addItem(self.img_item)
        self.p1.getViewBox().invertY(True)

        # create a vertical box layout
        self.vbl = QVBoxLayout()
        # add widget to vertical box
        self.vbl.addWidget(self.widget)
        # set the layout to the vertical box
        self.setLayout(self.vbl)

        # Levels/color control with a histogram
        # self.hist = HistogramLUTWidget()
        # self.hist.setImageItem(self.img)
        # parent.horizontalLayout_View.addWidget(self.hist)
        # # self.widget.addWidget(self.hist, 0, 1)
        # self.hist.vb.setMouseEnabled(y=False)  # makes user interaction a little easier

        # Create histogram
        # Levels/color control with a histogram
        self.histogram = HistogramLUTItem()
        # TODO Halve histogram width
        self.histogram.vb.setMouseEnabled(
            y=False)  # makes user interaction a little easier
        self.histogram.setImageItem(self.img_item)
        self.widget.addItem(self.histogram)
 def image_in_vb(name=None) -> Tuple[ImageItem, ViewBox, HistogramLUTItem]:
     im = ImageItem()
     vb = ViewBox(invertY=True, lockAspect=True, name=name)
     vb.addItem(im)
     hist = HistogramLUTItem(im)
     return im, vb, hist