def read_features(self): config = self.config_dict['build_atlas'] roi = config['roi'] w = [config['window'], config['window']] features = {} f = h5py.File(self.filename, 'r') if config['features'] in f : fes = np.rint(f[config['features']][()]).astype(np.int) f.close() for fe in fes : if fe[0] not in features : features[fe[0]] = {fe[3] : []} if fe[3] not in features[fe[0]] : features[fe[0]][fe[3]] = [] pos1 = (fe[1] + (1-w[0])//2-roi[0], fe[2] + (1-w[1])//2-roi[2]) pos2 = (fe[4] + (1-w[0])//2-roi[0], fe[5] + (1-w[1])//2-roi[2]) pen = self.get_pen() features[fe[0]][fe[3]].append([pg.RectROI(pos1, w, translateSnap=True, pen = pen), pg.RectROI(pos2, w, translateSnap=True, pen = pen)]) return features
def __init__(self, header: NonDBHeader = None, field: str = 'primary', toolbar: QToolBar = None, *args, **kwargs): super(FourDImageView, self).__init__(*args, *kwargs) # Using DynImageView rotates the data and the ROI does not work correctly. self.DPimageview = DynImageView() self.RSimageview = DynImageView() # Keep Y-axis as is self.DPimageview.view.invertY(True) self.RSimageview.view.invertY(True) self.DPimageview.imageItem.setOpts(axisOrder='col-major') self.RSimageview.imageItem.setOpts(axisOrder='col-major') self.setLayout(QHBoxLayout()) self.layout().addWidget(self.DPimageview) self.layout().addWidget(self.RSimageview) self.DProi = pg.RectROI(pos=(0, 0), size=(10, 10), translateSnap=True, snapSize=1, scaleSnap=True) self.RSroi = pg.RectROI(pos=(0, 0), size=(2, 2), translateSnap=True, snapSize=1, scaleSnap=True) self.DProi.sigRegionChanged.connect(self.updateRS) self.RSroi.sigRegionChanged.connect(self.updateDP) DPview = self.DPimageview.view # type: pg.ViewBox DPview.addItem(self.DProi) RSview = self.RSimageview.view # type: pg.ViewBox RSview.addItem(self.RSroi) # Set header if header: self.setHeader(header, field)
def add_feature(self, i1=0, j1=0, i2=0, j2=0): w = [self.config['window'], self.config['window']] pen = self.get_pen() fe1 = pg.RectROI([i1 + ((1 - w[0]) // 2), j1 + ((1 - w[0]) // 2)], w, translateSnap=True, pen=pen) fe2 = pg.RectROI([i2 + ((1 - w[0]) // 2), j2 + ((1 - w[0]) // 2)], w, translateSnap=True, pen=pen) self.frame1_imageView.addItem(fe1) self.frame2_imageView.addItem(fe2) fe1.removeHandle(0) fe1.setZValue(10) fe2.removeHandle(0) fe2.setZValue(10) # add an roi to frame1 and frame2 if self.frame1_index not in self.features: self.features[self.frame1_index] = {self.frame2_index: []} if self.frame2_index not in self.features[self.frame1_index]: self.features[self.frame1_index][self.frame2_index] = [] self.features[self.frame1_index][self.frame2_index].append([fe1, fe2])
def onGate(self): on = self.sender().isChecked() UIIndex = self.UIDic["GateCheckBoxes"].index(self.sender()) #Check if ROI holds -1 and thus is first time this ROI has been interacted with if self.UIDic["ROIs"][UIIndex] == -1: self.UIDic["ROIs"][UIIndex] = pg.RectROI([1,1],[1,1], pen=(0,9),centered=False) #Turn off all check boxes remove ROIS for i,checkBox in enumerate(self.UIDic["GateCheckBoxes"]): checkBox.setChecked(False) try: self.UIDic["Plots"][i].removeItem(self.UIDic["ROIs"][i]) except: pass #Then replot each graph for i in range(len(self.UIDic["Plots"])): fIndex = self.dataDic["FileNames"].index(str(self.UIDic["FileSelectors"][i].currentText())) self.rePlot(i,fIndex) #If we meant to turn a gate on if on: self.sender().setChecked(True) plot = self.UIDic["Plots"][UIIndex] plotData = self.UIDic["PlotData"][UIIndex] #ROIS? xData = plotData[str(self.UIDic["XAxisSelectors"][UIIndex].currentText())] yData = plotData[str(self.UIDic["YAxisSelectors"][UIIndex].currentText())] minX = min(xData) maxX = max(xData) minY = min(yData) maxY = max(yData) ix = minX iy = minY xSpan = abs(maxX-minX) ySpan = abs(maxY-minY) bounds = QtCore.QRectF(ix,iy,xSpan,ySpan) self.UIDic["ROIs"][UIIndex] = pg.RectROI([ix,iy], [xSpan,ySpan], pen=(0,9),centered=False,maxBounds=bounds) self.UIDic["ROIs"][UIIndex].addScaleHandle((0,0),(1,1)) self.UIDic["ROIs"][UIIndex].addScaleHandle((0,1),(1,0)) self.UIDic["ROIs"][UIIndex].addScaleHandle((1,0),(0,1)) self.UIDic["ROIs"][UIIndex].addScaleHandle((0,0.5),(1,0.5)) self.UIDic["ROIs"][UIIndex].addScaleHandle((0.5,0),(0.5,1)) self.UIDic["ROIs"][UIIndex].addScaleHandle((1,0.5),(0,0.5)) self.UIDic["ROIs"][UIIndex].addScaleHandle((0.5,1),(0.5,0)) self.UIDic["ROIs"][UIIndex].sigRegionChangeFinished.connect(self.onROIMove) plot.addItem(self.UIDic["ROIs"][UIIndex]) self.onROIMove()
def add_plot_roi(self): roi_logic = self.roi_logic size = (9, 150) plot_roi = pg.RectROI(roi_logic.plot_roi_pos, size, centered=True, pen=(4, 9)) self.view.addItem(plot_roi) return plot_roi
def __init__(self, rind, rtype, iROI, parent=None): # what type of ROI it is self.iROI = iROI self.rind = rind self.rtype = rtype self.saturation = 0 self.pupil_sigma = 0 colors = ['g', 'r', 'b'] rind = 0 roipen = pg.mkPen(colors[rind], width=3, style=QtCore.Qt.SolidLine) view = parent.p0.viewRange() imx = (view[0][1] + view[0][0]) / 2 imy = (view[1][1] + view[1][0]) / 2 dx = (view[0][1] - view[0][0]) / 4 dy = (view[1][1] - view[1][0]) / 4 dx = np.minimum(dx, parent.Ly * 0.4) dy = np.minimum(dy, parent.Lx * 0.4) imx = imx - dx / 2 imy = imy - dy / 2 self.ROI = pg.RectROI([imx, imy], [dx, dy], pen=roipen, sideScalers=True) self.ROI.handleSize = 8 self.ROI.handlePen = roipen self.ROI.addScaleHandle([1, 0.5], [0., 0.5]) self.ROI.addScaleHandle([0.5, 0], [0.5, 1]) parent.p0.addItem(self.ROI) self.ROI.sigRegionChangeFinished.connect(lambda: self.position(parent)) self.position(parent)
def mouseDragEvent(self, ev): if self.square_roi_on == 0 and self.freeform_roi_on == 0: if ev.button() == QtCore.Qt.RightButton: ev.ignore() else: pg.ViewBox.mouseDragEvent(self, ev) elif self.square_roi_on > 0 and self.freeform_roi_on == 0: start = self.mapToView(ev.buttonDownPos()) if self.square_roi_on == 1: if len(self.all_rois) == self.number_of_rois: self.delete_square_roi() self.all_rois.append(pg.RectROI(start, [0, 0])) self.addItem(self.all_rois[-1]) self.square_roi_on = 2 if not ev.isStart(): current = self.mapToView(ev.pos()) self.all_rois[-1].setSize(current - start) if ev.isFinish(): self.square_roi_on = 1 self.connect_on_roi_select(self.all_rois, freeform=False) ev.ignore() return ev.accept()
def _draw_rect(self, quad): """Draw rectangle around quadrant.""" if self.rect is not None: self.imv.getView().removeItem(self.rect) if quad is None: return self.quad = quad P, dx, dy =\ self.geom_obj.get_quad_corners(quad, np.array(self.data.shape, dtype='i')//2) pen = QtGui.QPen(QtCore.Qt.red, 0.002) Y, X = self.data.shape if self.frontview: P = (X - P[0] - dx, Y - P[1] - dy) else: P = (P[0], Y - P[1] - dy) self.rect = pg.RectROI( pos=P, size=(dx, dy), movable=False, removable=False, pen=pen, invertible=False, parent=self.imv, ) self.rect.handleSize = 0 self.imv.getView().addItem(self.rect) _ = [ self.rect.removeHandle(handle) for handle in self.rect.getHandles() ]
def setup_charts(app): app.next_row() # app.plot(['nx', 'ny'], [-1, 1], colspan=2, title='normal') app.plot(['posx', 'posy'], [0, 300], colspan=2, title='pos') app.plot(['rawx', 'rx'], [0, 4000], colspan=2, title='X') app.plot(['rawy', 'ry'], [0, 4000], colspan=2, title='Y') #app.plot(['vx', 'vy'], [-20, 20], colspan=2, title='speed') #app.plot(['rax', 'ray'], [-2, 2], colspan=2, title='acceleration') #p3 = app.win.addPlot(colspan=1, title="Normal") #p3.setXRange(-0.3, 0.3) #p3.setYRange(-0.3, 0.3) #app.charts.append(Touch(p3, ['nx', 'ny'], lastPoints=10)) p3 = app.win.addPlot(colspan=1, title="resistence") p3.setXRange(0, 4500) p3.setYRange(0, 4500) app.charts.append(Touch(p3, ['rx', 'ry'], lastPoints=10)) app.next_row() app.plot(['rawx', 'rawy'], [0, 4000], colspan=2, title='raw') app.plot(['cx', 'cy'], [-1, 1], colspan=2, title='change') app.plot(['usx', 'usy'], [900, 2100], colspan=2, title='USX/USY') p3 = app.win.addPlot(colspan=1, title="position") p3.setXRange(0, 300) p3.setYRange(0, 300) app.charts.append(Touch(p3, ['posx', 'posy'])) roi = pg.RectROI([0, 0], [170, 230], pen=(0, 9)) p3.addItem(roi)
def addMTROI(self, rData, roi=None): logger.debug(' ImageDisplay::addMTROI()') if roi is None: roi = pg.RectROI(rData.startPos, rData.startSize, pen=rData.pen) self.vblist.append(roi) rData.updateROI(roi) self.addDisplayItem(rData.roiType, roi)
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)
def __init__(self, model): sp = model _, _, sizeE, sizeN = sp.covariance.noise_coord self.patch_size_roi = pg.RectROI( pos=(0.0, 0.0), size=(sizeE, sizeN), sideScalers=True, movable=False, pen=pen_roi, ) self._anisotropic = False self.components_available = { "synthetic_noise": [ "Noise", lambda sp: sp.covariance.syntheticNoise( self.sizePatchPx(), anisotropic=self.anisotropic), ] } self._component = "synthetic_noise" KitePlot.__init__(self, model=model) self.patch_size_roi.sigRegionChangeFinished.connect(self.update) self.addItem(self.patch_size_roi)
def __init__(self,parent): self.parent = parent self.tof_inds1 = [] self.tof_inds2 = [] self.roi = pg.RectROI(pos=[0,0],size = [1,1]) # self.roiState = 0 self.roi.sigRegionChangeFinished.connect(lambda: self.sum_under_2d_roi()) self.roi.sigRegionChangeStarted.connect(lambda: self.disableMouse()) self.roi.sigRegionChangeFinished.connect(lambda: self.enableMouse()) self.roi.sigRegionChangeFinished.connect(lambda: self.gate_move_finished()) self.roiName = 'RectGate1' self.num_shots = 0 self.initialize_variables() self.initialize_plots() self.P1 = 0 self.P2 = 0 self.P12 = 0
def initROIs(self, img_shape): """Initialize the ROI markers""" # # Mask ROI # angles = np.linspace(0, 2 * np.pi, MASK_INIT_RESOLUTION) xs = img_shape[0] * (1 + 0.9 * np.cos(angles)) / 2 ys = img_shape[1] * (1 + 0.9 * np.sin(angles)) / 2 mask_positions = np.vstack((xs, ys)).T self.mask_ROI = pg.PolyLineROI(mask_positions, closed=True, pen=dict(color=(255, 0, 0), width=2)) self.mask_ROI.setVisible(False) self.plot_area.vb.addItem(self.mask_ROI) # # Reconstruction ROI # self.ROI = pg.RectROI([20, 20], [20, 20], pen=(0, 9)) self.ROI.addRotateHandle([1, 0], [0.5, 0.5]) self.ROI.setVisible(False) # # Callback when the user stops moving a ROI. # self.ROI.sigRegionChangeFinished.connect(self._ROI_updated) self.mask_ROI.sigRegionChangeFinished.connect(self._mask_ROI_updated) self.plot_area.vb.addItem(self.ROI)
def update_roi_display(self): if hasattr(self, 'rect_roi'): self.original_view.removeItem(self.rect_roi) del self.rect_roi if gv.h5f is None: return image_size = gv.h5f[gv.KEY_ORIGINAL].shape[1:3] self.rect_roi = pg.RectROI([0, 0], [1, 1], pen=pg.mkPen((255, 0, 0)), maxBounds=QtCore.QRectF(0, 0, *image_size)) self.rect_roi.sigRegionChangeFinished.connect(self.update_roi_params) self.original_view.addItem(self.rect_roi) if gv.KEY_ATTR_FILT_ROI_POS in gv.h5f.attrs and gv.KEY_ATTR_FILT_ROI_SIZE in gv.h5f.attrs: pos_ = gv.h5f.attrs[gv.KEY_ATTR_FILT_ROI_POS] size_ = gv.h5f.attrs[gv.KEY_ATTR_FILT_ROI_SIZE] else: pos_ = [0, 0] size_ = image_size self.rect_roi.setPos(pg.Point(pos_)) self.rect_roi.setSize(pg.Point(size_))
def ROI_selection(self): draw = False if self.sizebtns.button(0).isChecked(): wplot = 0 view = self.p1.viewRange() draw = True elif self.sizebtns.button(2).isChecked(): wplot = 1 view = self.p2.viewRange() draw = True if draw: self.ROI_remove() self.topbtns.button(0).setStyleSheet(self.stylePressed) self.ROIplot = wplot imx = (view[0][1] + view[0][0]) / 2 imy = (view[1][1] + view[1][0]) / 2 dx = (view[0][1] - view[0][0]) / 4 dy = (view[1][1] - view[1][0]) / 4 dx = np.minimum(dx, 300) dy = np.minimum(dy, 300) imx = imx - dx / 2 imy = imy - dy / 2 self.ROI = pg.RectROI([imx, imy], [dx, dy], pen="w", sideScalers=True) if wplot == 0: self.p1.addItem(self.ROI) else: self.p2.addItem(self.ROI) self.ROI_position() self.ROI.sigRegionChangeFinished.connect(self.ROI_position) self.isROI = True
def __init__(self, parent): pg.PlotWidget.__init__(self, parent) self.setXRange(0, 1000) x = np.random.normal(size=1000) y = np.random.normal(size=1000) yy = np.random.normal(size=1000) self.plot(x, y, pen=(0, 3), symbol='+') ## setting pen=None disables line drawing self.plot(x, yy, pen=(1, 3), symbol='+') self.autoFlag = False self.roi_disp = False #rois =[] #self.myroi = [(pg.RectROI([0,0],[1,1],pen=(0,9), movable=True, invertible=True, maxBounds=[0,0,1200,16000]))] self.myroi = [(pg.RectROI([0, 0], [20, 20], invertible=True, pen=(0, 9)))] self.setMouseEnabled(x=False, y=False) self.box_mode = -1 self.setXRange(630, 750) self.setYRange(0, 1000) self.scene().sigMouseMoved.connect(self.mouseMoved) self.scene().sigMouseClicked.connect(self.mousePressed) self.myroi[0].sigRegionChangeFinished.connect(self.roi_done) #self.myroi[0].sigRegionChangeStarted.connect(self.roi_flux) self.maxLinePos = 700 self.startX = 670 self.endX = 750 # first data if the flag to see if the spectrum has been displayed before or not, # if not use the data's x range to set the plot x axis self.first_data = True
def draw(self, detections): rois = [] for detection in detections: x, y, w, h = detection['bbox'] roi = pg.RectROI([x - w // 2, y - h // 2], [w, h], pen=self.pen) self.jansen.screen.addOverlay(roi) rois.append(roi) return rois
def setRectRegionROI(self): ''' Rectangular selection region ''' self.rect = pg.RectROI([300, 300], [1500, 100], pen=pg.mkPen(color='y', width=2)) self.p1.addItem(self.rect) self.rect.sigRegionChanged.connect(self.updatePlot)
def set_rect_region_ROI(self): ''' Rectangular selection region ''' self.rect = pg.RectROI([300, 5], [1500, 10], pen=pg.mkPen(color='y', width=2)) self.plotsScroll.addItem(self.rect) self.rect.sigRegionChanged.connect(self.update_plot)
def initRectROI(self, imv, pos, size, pen, updateFunc=None, releaseFunc=None): """Add a rectangular ROI to an ImageView""" roi = pg.RectROI(pos, size, pen=pen) if updateFunc is not None: roi.sigRegionChanged.connect(updateFunc) if releaseFunc is not None: roi.sigRegionChangeFinished.connect(releaseFunc) if updateFunc is None and releaseFunc is None: roi = pg.RectROI(pos, size, pen=pen, movable=False) imv.getView().addItem(roi) self.param_gui['rect_roi'] = roi return roi
def activate(self): if self._item is None: self._item = pg.RectROI((0, 0), (0, 0), pen=(25, 25, 25)) self._item.setAcceptedMouseButtons(Qt.LeftButton) self._item.setVisible(False) self._item.setCursor(Qt.OpenHandCursor) self._plot.addItem(self._item) self._plot.addAction(self._delete_action)
def ROI_clicked(self, *args, **kwargs): if not self.selector: self.selector = pg.RectROI((5, 5), size=(640, 480)) self.ROI_button.setChecked(True) self.camera_view.addItem(self.selector) else: self.camera_view.removeItem(self.selector) self.ROI_button.setChecked(False) self.selector = None
def make_dot(self, plot): x = self.dataview.x y = self.dataview.y dot = pg.RectROI(pos=(x, y), size=(1, 1)) plot.addItem(dot) h = dot.getHandles() dot.removeHandle(h[0]) return dot
def update_virtual_detector_shape(self): """ Virtual detector shapes are mapped to integers, following the IDs assigned to the radio buttons in VirtualDetectorWidget in dialogs.py. They are as follows: 1: Rectangular 2: Circular 3: Annular """ detector_shape = self.settings.virtual_detector_shape.val x,y = self.diffraction_space_view.shape x0,y0 = x/2, y/2 xr,yr = x/10,y/10 # Remove existing detector if hasattr(self,'virtual_detector_roi'): self.diffraction_space_widget.view.scene().removeItem(self.virtual_detector_roi) if hasattr(self,'virtual_detector_roi_inner'): self.diffraction_space_widget.view.scene().removeItem(self.virtual_detector_roi_inner) if hasattr(self,'virtual_detector_roi_outer'): self.diffraction_space_widget.view.scene().removeItem(self.virtual_detector_roi_outer) # Rectangular detector if detector_shape==0: self.virtual_detector_roi = pg.RectROI([int(x0-xr/2),int(y0-yr/2)], [int(xr),int(yr)], pen=(3,9)) self.diffraction_space_widget.getView().addItem(self.virtual_detector_roi) self.virtual_detector_roi.sigRegionChangeFinished.connect(self.update_real_space_view) # Circular detector elif detector_shape==1: self.virtual_detector_roi = pg.CircleROI([int(x0-xr/2),int(y0-yr/2)], [int(xr),int(yr)], pen=(3,9)) self.diffraction_space_widget.getView().addItem(self.virtual_detector_roi) self.virtual_detector_roi.sigRegionChangeFinished.connect(self.update_real_space_view) # Annular dector elif detector_shape==2: # Make outer detector self.virtual_detector_roi_outer = pg.CircleROI([int(x0-xr),int(y0-yr)], [int(2*xr),int(2*yr)], pen=(3,9)) self.diffraction_space_widget.getView().addItem(self.virtual_detector_roi_outer) # Make inner detector self.virtual_detector_roi_inner = pg.CircleROI([int(x0-xr/2),int(y0-yr/2)], [int(xr),int(yr)], pen=(4,9), movable=False) self.diffraction_space_widget.getView().addItem(self.virtual_detector_roi_inner) # Connect size/position of inner and outer detectors self.virtual_detector_roi_outer.sigRegionChangeFinished.connect(self.update_annulus_pos) self.virtual_detector_roi_outer.sigRegionChangeFinished.connect(self.update_annulus_radii) self.virtual_detector_roi_inner.sigRegionChangeFinished.connect(self.update_annulus_radii) # Connect to real space view update function self.virtual_detector_roi_outer.sigRegionChangeFinished.connect(self.update_real_space_view) self.virtual_detector_roi_inner.sigRegionChangeFinished.connect(self.update_real_space_view) else: raise ValueError("Unknown detector shape value {}. Must be 0, 1, or 2.".format(detector_shape)) self.update_virtual_detector_mode() self.update_real_space_view()
def next_pair(self): """ increment the frame indices if there are no features for this pair then copy them from the last pair """ any_features_current = False if self.frame1_index in self.features : if self.frame2_index in self.features[self.frame1_index] : any_features_current = True pos = [] for fe in self.features[self.frame1_index][self.frame2_index]: pos.append([[fe[-2].pos()[0],fe[-2].pos()[1]], [fe[-1].pos()[0],fe[-1].pos()[1]]]) frame1_index = self.frame1_index + 1 frame2_index = self.frame2_index + 1 if frame1_index >= self.N or self.frame2_index >= self.N : print('end of file...') return any_features_next = False if frame1_index in self.features : if frame2_index in self.features[frame1_index] : any_features_next = True if any_features_current is True and any_features_next is False : config = self.config_dict['build_atlas'] w = [config['window'], config['window']] for p in pos: # add an roi to frame1 and frame2 if frame1_index not in self.features : self.features[frame1_index] = {frame2_index : []} if frame2_index not in self.features[frame1_index] : self.features[frame1_index][frame2_index] = [] pen = self.get_pen() self.features[frame1_index][frame2_index].append(\ [pg.RectROI([int(p[0][0]),int(p[0][1])], w, translateSnap=True, pen = pen), \ pg.RectROI([int(p[1][0]),int(p[1][1])], w, translateSnap=True, pen = pen)]) self.update_display(frame1_index, frame2_index)
def setup_layout(self): self.setWindowTitle("Andor Image Display") #layout layout = QtGui.QGridLayout() pg.mkQApp() main_win = pg.GraphicsLayoutWidget() self.p1 = main_win.addPlot() self.img_view = pg.ImageItem() self.p1.addItem(self.img_view) ### add ROI self.roi = pg.RectROI([268, 224], [6, 5]) self.roi.addScaleHandle([0.5, 1], [0.5, 0.5]) self.roi.addScaleHandle([0, 0.5], [0.5, 0.5]) self.p1.addItem(self.roi) self.roi.setZValue(10) layout.addWidget(main_win, 0, 0, 1, 6) ### add aux display for CCD images win_0 = pg.GraphicsLayoutWidget() self.p_sub_0 = win_0.addPlot() self.ccd_view_0 = pg.ImageItem() self.p_sub_0.addItem(self.ccd_view_0) self.label_s = win_0.addLabel('', 1, 0) # add label below the plot layout.addWidget(win_0, 1, 0, 1, 2) win_1 = pg.GraphicsLayoutWidget() self.p_sub_1 = win_1.addPlot() self.ccd_view_1 = pg.ImageItem() self.p_sub_1.addItem(self.ccd_view_1) self.label_p = win_1.addLabel('', 1, 0) layout.addWidget(win_1, 1, 2, 1, 2) win_2 = pg.GraphicsLayoutWidget() self.p_sub_2 = win_2.addPlot() self.ccd_view_2 = pg.ImageItem() self.p_sub_2.addItem(self.ccd_view_2) self.label_bg = win_2.addLabel('', 1, 0) layout.addWidget(win_2, 1, 4, 1, 2) #add lines for the cross self.vLine = pg.InfiniteLine(angle=90, movable=False) self.hLine = pg.InfiniteLine(angle=0, movable=False) self.vLine.setZValue(11) self.hLine.setZValue(11) self.p1.addItem(self.vLine, ignoreBounds=True) self.p1.addItem(self.hLine, ignoreBounds=True) #set the layout and show self.setLayout(layout) self.show() #self.roi.sigRegionChanged.connect(self.updateROI) self.roi.sigRegionChangeFinished.connect(self.updateROI)
def addROI( self, roi_name="ROI", roi_style=None, roi_hover_style=None, handle_style=None, handle_hover_style=None, label_color="#000000FF", ): """adds an roi""" # check that plot is initialized if self.image_plot is None: # no 'image plot' initialized, return ! return # check that roi name is unique if roi_name in self.roi_list: msg = "'%s' roi name is already used." logger.warning(msg % roi_name) return # create roi object new_roi = pg.RectROI( pos=[0, 0], size=[50, 50], rotatable=False, pen=roi_style, hoverPen=roi_hover_style, handlePen=handle_style, handleHoverPen=handle_hover_style, ) # add scale handles for pos in ([1, 0.5], [0, 0.5], [0.5, 0], [0.5, 1]): new_roi.addScaleHandle(pos=pos, center=[0.5, 0.5]) for pos, center in zip( ([0, 0], [1, 0], [1, 1], [0, 1]), ([1, 1], [0, 1], [0, 0], [1, 0]) ): new_roi.addScaleHandle(pos=pos, center=center) # add a label new_roi.label_color = label_color roi_label = pg.TextItem(roi_name, color=label_color) roi_label.setPos(0, 0) new_roi.label = roi_label # link to roi !! new_roi.name = roi_name # make it such that the label follows the ROI ! # using sigRegionChanged new_roi.sigRegionChanged.connect(_roi_changed) # add to current plot self.image_plot.addItem(new_roi) self.image_plot.addItem(roi_label) self.roi_list[roi_name] = new_roi
def _define_guide(self): """define the guide""" guide_roi = pg.RectROI([self.parent.default_guide_roi['x0'], self.parent.default_guide_roi['y0']], [self.parent.default_guide_roi['width'], self.parent.default_guide_roi['height']], pen=self.parent.default_guide_roi['color_activated']) guide_roi.addScaleHandle([1, 1], [0, 0]) guide_roi.addScaleHandle([0, 0], [1, 1]) guide_roi.sigRegionChanged.connect(self.parent.guide_changed) self.parent.ui.image_view.addItem(guide_roi) self.parent.list_guide_pyqt_roi.insert(self.row, guide_roi)
def add_rect_mask(self): new_roi = pg.RectROI( pos=self.resolution / 2, size=self.resolution / 10, pen=pg.mkPen("r", width=4), ) new_roi.addScaleHandle([1, 1], [0, 0]) new_roi.addScaleHandle([0, 0], [1, 1]) self.viewer.addItem(new_roi) self.rect_masks.append(new_roi)