Python pyqtgraph.ROI Examples
The following are 19
code examples of pyqtgraph.ROI().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pyqtgraph
, or try the search function
.
Example #1
Source File: test_ROI.py From tf-pose with Apache License 2.0 | 7 votes |
def test_getArrayRegion(transpose=False): pr = pg.PolyLineROI([[0, 0], [27, 0], [0, 28]], closed=True) pr.setPos(1, 1) rois = [ (pg.ROI([1, 1], [27, 28], pen='y'), 'baseroi'), (pg.RectROI([1, 1], [27, 28], pen='y'), 'rectroi'), (pg.EllipseROI([1, 1], [27, 28], pen='y'), 'ellipseroi'), (pr, 'polylineroi'), ] for roi, name in rois: # For some ROIs, resize should not be used. testResize = not isinstance(roi, pg.PolyLineROI) origMode = pg.getConfigOption('imageAxisOrder') try: if transpose: pg.setConfigOptions(imageAxisOrder='row-major') check_getArrayRegion(roi, 'roi/'+name, testResize, transpose=True) else: pg.setConfigOptions(imageAxisOrder='col-major') check_getArrayRegion(roi, 'roi/'+name, testResize) finally: pg.setConfigOptions(imageAxisOrder=origMode)
Example #2
Source File: pyoptic.py From tf-pose with Apache License 2.0 | 6 votes |
def paramStateChanged(self): """Some parameters of the optic have changed.""" # Move graphics item self.gitem.setPos(Point(self['pos'])) self.gitem.resetTransform() self.gitem.rotate(self['angle']) # Move ROI to match try: self.roi.sigRegionChanged.disconnect(self.roiChanged) br = self.gitem.boundingRect() o = self.gitem.mapToParent(br.topLeft()) self.roi.setAngle(self['angle']) self.roi.setPos(o) self.roi.setSize([br.width(), br.height()]) finally: self.roi.sigRegionChanged.connect(self.roiChanged) self.sigStateChanged.emit()
Example #3
Source File: pyoptic.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
def paramStateChanged(self): """Some parameters of the optic have changed.""" # Move graphics item self.gitem.setPos(Point(self['pos'])) self.gitem.resetTransform() self.gitem.rotate(self['angle']) # Move ROI to match try: self.roi.sigRegionChanged.disconnect(self.roiChanged) br = self.gitem.boundingRect() o = self.gitem.mapToParent(br.topLeft()) self.roi.setAngle(self['angle']) self.roi.setPos(o) self.roi.setSize([br.width(), br.height()]) finally: self.roi.sigRegionChanged.connect(self.roiChanged) self.sigStateChanged.emit()
Example #4
Source File: pyoptic.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 6 votes |
def __init__(self, gitem, **params): ParamObj.__init__(self) pg.GraphicsObject.__init__(self) #, [0,0], [1,1]) self.gitem = gitem self.surfaces = gitem.surfaces gitem.setParentItem(self) self.roi = pg.ROI([0,0], [1,1]) self.roi.addRotateHandle([1, 1], [0.5, 0.5]) self.roi.setParentItem(self) defaults = { 'pos': Point(0,0), 'angle': 0, } defaults.update(params) self._ior_cache = {} self.roi.sigRegionChanged.connect(self.roiChanged) self.setParams(**defaults)
Example #5
Source File: test_ROI.py From soapy with GNU General Public License v3.0 | 6 votes |
def test_getArrayRegion(transpose=False): pr = pg.PolyLineROI([[0, 0], [27, 0], [0, 28]], closed=True) pr.setPos(1, 1) rois = [ (pg.ROI([1, 1], [27, 28], pen='y'), 'baseroi'), (pg.RectROI([1, 1], [27, 28], pen='y'), 'rectroi'), (pg.EllipseROI([1, 1], [27, 28], pen='y'), 'ellipseroi'), (pr, 'polylineroi'), ] for roi, name in rois: # For some ROIs, resize should not be used. testResize = not isinstance(roi, pg.PolyLineROI) origMode = pg.getConfigOption('imageAxisOrder') try: if transpose: pg.setConfigOptions(imageAxisOrder='row-major') check_getArrayRegion(roi, 'roi/'+name, testResize, transpose=True) else: pg.setConfigOptions(imageAxisOrder='col-major') check_getArrayRegion(roi, 'roi/'+name, testResize) finally: pg.setConfigOptions(imageAxisOrder=origMode)
Example #6
Source File: camera_display.py From stytra with GNU General Public License v3.0 | 6 votes |
def __init__(self, **kwargs): """ """ super().__init__(**kwargs) # Draw ROI for tail selection: self.tail_params = self.experiment.pipeline.tailtrack._params self.roi_tail = SingleLineROI( self.tail_points(), pen=dict(color=(40, 5, 200), width=3) ) # Prepare curve for plotting tracked tail position: self.curve_tail = pg.PlotCurveItem(pen=dict(color=(230, 40, 5), width=3)) self.display_area.addItem(self.curve_tail) self.initialise_roi(self.roi_tail) self.setting_param_val = False
Example #7
Source File: timeserieswidget.py From dunya-desktop with GNU General Public License v3.0 | 6 votes |
def update_notes(self, xmin, xmax): """ Plots the note squares on the time series widget according to the given region. :param xmin: (int) Minimum value of the region selector item :param xmax: (int) Maximum value of the region selector item """ pen=(225, 224, 181, 175) start_ind = self.find_nearest_index(self.notes_start, xmin) end_ind = self.find_nearest_index(self.notes_end, xmax) self.remove_given_items(self.zoom_selection, self.rois) self.rois = [] for i in range(start_ind, end_ind): temp_note = self.notes[i] roi = pg.ROI(pos=[temp_note[0], temp_note[2]], size=[temp_note[1] - temp_note[0], 5], pen=pen) roi.addScaleHandle(pos=[0, 0], center=[0.5, 0.5]) roi.addScaleHandle(pos=[1, 1], center=[0.5, 0.5]) self.zoom_selection.addItem(roi) self.rois.append(roi)
Example #8
Source File: timeserieswidget.py From dunya-desktop with GNU General Public License v3.0 | 6 votes |
def plot_histogram_raxis(self, vals, bins): """ Plots histogram to the right axis. :param vals: (list or numpy array) List of valley values of histogram. :param bins: (list or numpy array) List of bins values of histogram in Hz """ # shadow pen is the properties of shadow around the lines self.right_axis.plot(x=vals, y=bins, shadowPen=SHADOW_PEN) self.right_axis.setXRange(0, np.max(vals), padding=0) # cursor in the histogram plot. self.hline_histogram = pg.ROI(pos=[0, 0], size=[0, 1], angle=-90, pen=CURSOR_PEN) self.right_axis.addItem(self.hline_histogram) # Link the y-axises of pitch and histogram plots self.zoom_selection.setYLink(self.right_axis)
Example #9
Source File: waveformwidget.py From dunya-desktop with GNU General Public License v3.0 | 6 votes |
def __add_items_to_plot(self, len_plot, min_audio, max_audio): """ Adds a region selector item and vertical line for to the waveform plot. :param len_plot: (int) Number of samples in plotted waveform array. :param min_audio: (float) The minimum value of plotted waveform array. :param max_audio: (float) The maximum value of plotted waveform array. """ # Create a waveform region item and add it to waveform plot pos_wf_x_max = len_plot * 0.05 # Region item focuses on the 5% of # waveform plot. self.region_wf = WaveformRegionItem(values=[0, pos_wf_x_max], brush=WAVEFORM_BRUSH, bounds=[0., len_plot]) # Creating a cursor with pyqtgraph.ROI self.vline_wf = pg.ROI(pos=[0, min_audio], size=[0, max_audio - min_audio], angle=0, pen=WAVEFORM_VLINE) # add items to waveform plot self.waveform.addItem(self.region_wf) self.waveform.addItem(self.vline_wf) # text item self.section_label = pg.TextItem(text='') self.waveform.addItem(self.section_label)
Example #10
Source File: pyoptic.py From tf-pose with Apache License 2.0 | 6 votes |
def __init__(self, gitem, **params): ParamObj.__init__(self) pg.GraphicsObject.__init__(self) #, [0,0], [1,1]) self.gitem = gitem self.surfaces = gitem.surfaces gitem.setParentItem(self) self.roi = pg.ROI([0,0], [1,1]) self.roi.addRotateHandle([1, 1], [0.5, 0.5]) self.roi.setParentItem(self) defaults = { 'pos': Point(0,0), 'angle': 0, } defaults.update(params) self._ior_cache = {} self.roi.sigRegionChanged.connect(self.roiChanged) self.setParams(**defaults)
Example #11
Source File: base.py From kite with GNU General Public License v3.0 | 5 votes |
def __init__(self, delegate): self.delegate = delegate self.source = self.delegate.source source = self.source pg.ROI.__init__( self, pos=pg.Point(source.outline()[1]), size=pg.Point(source.width, source.length), angle=-source.strike, invertible=False, pen=self.pen_outline) self.handlePen = self.pen_handle self.addScaleRotateHandle([0, 0], [0, 1]) self.addScaleRotateHandle([0, 1], [0, 0]) self.addScaleHandle([1, .5], [0, .5], lockAspect=False) for h in self.handles: h['item'].sigClicked.connect(self.sigRegionChangeStarted.emit) self.delegate.sourceParametersChanged.connect( self.updateROIPosition) self.sigRegionChangeFinished.connect( self.setSourceParametersFromROI) self.setAcceptedMouseButtons(QtCore.Qt.RightButton) self.sigClicked.connect(self.showEditingDialog)
Example #12
Source File: base.py From kite with GNU General Public License v3.0 | 5 votes |
def _makePen(self): # Generate the pen color for this ROI based on its current state. if self.mouseHovering: return self.pen_highlight else: return self.pen
Example #13
Source File: base.py From kite with GNU General Public License v3.0 | 5 votes |
def _makePen(self): # Generate the pen color for this ROI based on its current state. if self.mouseHovering: return self.pen_highlight else: return self.pen
Example #14
Source File: camera_display.py From stytra with GNU General Public License v3.0 | 5 votes |
def initialise_roi(self, roi): """ROI is initialised separately, so it can first be defined in the child __init__. Parameters ---------- Returns ------- """ # Add ROI to image and connect it to the function for updating # the relative params: self.display_area.addItem(roi) roi.sigRegionChanged.connect(self.set_pos_from_roi)
Example #15
Source File: camera_display.py From stytra with GNU General Public License v3.0 | 5 votes |
def set_pos_from_tree(self): """Called when ROI position values are changed in the ParameterTree. Change the position of the displayed ROI. Parameters ---------- Returns ------- """ pass
Example #16
Source File: camera_display.py From stytra with GNU General Public License v3.0 | 5 votes |
def set_pos_from_roi(self): """Called when ROI position values are changed in the displayed ROI. Change the position in the ParameterTree values. Parameters ---------- Returns ------- """ pass
Example #17
Source File: histogram.py From dunya-desktop with GNU General Public License v3.0 | 5 votes |
def __set_plot(self): self.hist_widget.setMouseEnabled(x=False, y=False) self.hist_widget.setMenuEnabled(False) self.hline_histogram = pg.ROI(pos=[0, 0], size=[0, self.max_val], angle=0, pen=CURSOR_PEN) self.hist_widget.addItem(self.hline_histogram)
Example #18
Source File: monitor_control.py From stytra with GNU General Public License v3.0 | 4 votes |
def __init__(self, *args, display_size=(1280, 800), display, **kwargs): super().__init__(*args, **kwargs) self.display = display self.view_box = pg.ViewBox(invertY=True, lockAspect=1, enableMouse=False) self.addItem(self.view_box) self.roi_box = pg.ROI( maxBounds=QRectF(0, 0, display_size[0], display_size[1]), size=display.size, pos=display.pos, ) self.roi_box.addScaleHandle([0, 0], [1, 1]) self.roi_box.addScaleHandle([1, 1], [0, 0]) self.roi_box.sigRegionChanged.connect(self.set_param_val) self.display.sig_param_changed.connect(self.set_roi) self.view_box.addItem(self.roi_box) self.view_box.setRange( QRectF(0, 0, display_size[0], display_size[1]), update=True, disableAutoRange=True, ) self.view_box.addItem( pg.ROI( pos=(1, 1), size=(display_size[0] - 1, display_size[1] - 1), movable=False, pen=(80, 80, 80), ) ) self.calibration_points = pg.ScatterPlotItem(pen=(255, 0, 0), brush=None) self.calibration_frame = pg.PlotCurveItem( brush=(120, 10, 10), pen=(200, 10, 10), fill_level=1 ) self.camera_image = pg.ImageItem() self.view_box.addItem(self.calibration_frame) self.view_box.addItem(self.camera_image) self.view_box.addItem(self.calibration_points) self.setting_param_val = False self.set_param_val()
Example #19
Source File: timeserieswidget.py From dunya-desktop with GNU General Public License v3.0 | 4 votes |
def add_1d_view(self): """ Adds a 1d view to TimeSeriesWidget where you can plot and add items on it. """ # To customize the plot axises, create new ones. x_axis = pg.AxisItem('bottom') # x-axis x_axis.enableAutoSIPrefix(enable=False) # Prevent automatic SI # prefix scaling on this axis. x_axis.setGrid(100) # the alpha value of grids on x-axis y_axis = pg.AxisItem('left') # x-axis y_axis.enableAutoSIPrefix(enable=False) # Prevent automatic SI # prefix scaling on this axis. axis_items = {'left': y_axis, 'bottom': x_axis} # add plot self.zoom_selection = self.centralWidget.addPlot(axisItems=axis_items) # disable the mouse events and menu events self.zoom_selection.setMouseEnabled(x=False, y=False) self.zoom_selection.setMenuEnabled(False) # initialize a cursor object. Height of cursor is 20000. self.vline = pg.ROI(pos=[0, 0], size=[0, 20000], angle=0, pen=CURSOR_PEN) self.zoom_selection.addItem(self.vline) # add item to plot area # add y-axis region self.right_axis = self.centralWidget.addPlot(row=0, col=1) # disable the mouse events and menu events self.right_axis.setMouseEnabled(x=False, y=False) self.right_axis.setMenuEnabled(False) self.right_axis.setMaximumWidth(125) # maximum width 125 self.right_axis.setContentsMargins(0, 0, 0, 40) # set 40 left margin self.right_axis.hideAxis(axis="left") # hide left-axis self.right_axis.hideAxis(axis="bottom") # hide botton-axis self.right_axis.setYRange(0, 20000, padding=0) # show right axis self.right_axis.setLabel(axis="right", text="Frequency (Hz)") # initialize a linear region item orientation = pg.LinearRegionItem.Horizontal # set the item horizontal self.region_yaxis = pg.LinearRegionItem(values=[0, 20000], brush=YAXIS_BRUSH, orientation=orientation, bounds=[0, 20000]) self.right_axis.addItem(self.region_yaxis) # add item to right axis # set region changed signal to set y axis range in the plot self.region_yaxis.sigRegionChangeFinished.connect( self.change_yaxis_range)