def __init__(self, topLevelOperatorView, shellRequestSignal, predictionSerializer): # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelArray.deleteLabel labelSlots.maxLabelValue = topLevelOperatorView.MaxLabelValue # We provide our own UI file (which adds an extra control for interactive mode) labelingDrawerUiPath = os.path.split( __file__)[0] + '/labelingDrawer.ui' # Base class init super(AutocontextClassificationGui, self).__init__(labelSlots, topLevelOperatorView, labelingDrawerUiPath) self.topLevelOperatorView = topLevelOperatorView self.shellRequestSignal = shellRequestSignal self.predictionSerializer = predictionSerializer self.interactiveModeActive = False self._currentlySavingPredictions = False self.labelingDrawerUi.savePredictionsButton.clicked.connect( self.onSavePredictionsButtonClicked) self.labelingDrawerUi.savePredictionsButton.setIcon( QIcon(ilastikIcons.Save)) self.topLevelOperatorView.MaxLabelValue.notifyDirty( bind(self.handleLabelSelectionChange))
def __init__(self, parentApplet, topLevelOperatorView, labelingDrawerUiPath=None): labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelPipeline.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelPipeline.DeleteLabel labelSlots.labelNames = topLevelOperatorView.LabelNames self.parentApplet = parentApplet if labelingDrawerUiPath is None: localDir = os.path.split(__file__)[0] labelingDrawerUiPath = os.path.join(localDir, "nnClass.ui") super(NNClassGui, self).__init__(parentApplet, labelSlots, topLevelOperatorView, labelingDrawerUiPath) self._initCheckpointActions() self.classifiers = OrderedDict() self.liveTraining = False self.livePrediction = False self.__cleanup_fns = [] self.labelingDrawerUi.liveTraining.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.labelingDrawerUi.liveTraining.toggled.connect(self.toggleLiveTraining) self.labelingDrawerUi.livePrediction.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.set_live_predict_icon(self.livePrediction) self.labelingDrawerUi.livePrediction.toggled.connect(self.toggleLivePrediction) self.labelingDrawerUi.addModel.clicked.connect(self.addModelClicked) self.labelingDrawerUi.closeModel.setIcon(QIcon(ilastikIcons.ProcessStop)) self.labelingDrawerUi.closeModel.clicked.connect(self.closeModelClicked) self.labelingDrawerUi.uploadModel.setIcon(QIcon(ilastikIcons.Upload)) self.labelingDrawerUi.uploadModel.clicked.connect(self.uploadModelClicked) self.initViewerControls() self.initViewerControlUi() self.labelingDrawerUi.labelListView.support_merges = True self.batch_size = self.topLevelOperatorView.Batch_Size.value self.labelingDrawerUi.labelListView.allowDelete = False self.labelingDrawerUi.AddLabelButton.setEnabled(False) self.labelingDrawerUi.AddLabelButton.hide() self.topLevelOperatorView.LabelNames.notifyDirty(bind(self.handleLabelSelectionChange)) self.__cleanup_fns.append( partial(self.topLevelOperatorView.LabelNames.unregisterDirty, bind(self.handleLabelSelectionChange)) ) self.__cleanup_fns.append(self.topLevelOperatorView.cleanUp) self.setLabelingUIEnabled(ALLOW_TRAINING) self.invalidatePredictionsTimer = QTimer() self.invalidatePredictionsTimer.timeout.connect(self.updatePredictions) self.tiktorchModel.registerListener(self._onModelStateChanged)
def gui(self): if self._gui is None: labelingSlots = LabelingGui.LabelingSlots() labelingSlots.labelInput = self.topLevelOperator.opLabeling.LabelInputs labelingSlots.labelOutput = self.topLevelOperator.opLabeling.LabelImages labelingSlots.labelEraserValue = self.topLevelOperator.opLabeling.LabelEraserValue labelingSlots.labelDelete = self.topLevelOperator.opLabeling.LabelDelete labelingSlots.maxLabelValue = self.topLevelOperator.opLabeling.MaxLabelValue labelingSlots.labelsAllowed = self.topLevelOperator.opLabeling.LabelsAllowedFlags self._gui = CarvingGui( labelingSlots, self.topLevelOperator, rawInputSlot=self.topLevelOperator.opCarving.RawData, carvingApplet=self ) return self._gui
def __init__(self, parentApplet, topLevelOperatorView, labelingDrawerUiPath=None ): self.parentApplet = parentApplet # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelPipeline.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelPipeline.DeleteLabel labelSlots.labelNames = topLevelOperatorView.LabelNames self.__cleanup_fns = [] # We provide our own UI file (which adds an extra control for interactive mode) if labelingDrawerUiPath is None: labelingDrawerUiPath = os.path.split(__file__)[0] + '/labelingDrawer.ui' # Base class init super(PixelClassificationGui, self).__init__( parentApplet, labelSlots, topLevelOperatorView, labelingDrawerUiPath ) self.topLevelOperatorView = topLevelOperatorView self.interactiveModeActive = False # Immediately update our interactive state self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value ) self._currentlySavingPredictions = False self.labelingDrawerUi.labelListView.support_merges = True self.labelingDrawerUi.liveUpdateButton.setEnabled(False) self.labelingDrawerUi.liveUpdateButton.setIcon( QIcon(ilastikIcons.Play) ) self.labelingDrawerUi.liveUpdateButton.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.labelingDrawerUi.liveUpdateButton.toggled.connect( self.toggleInteractive ) self.initFeatSelDlg() self.labelingDrawerUi.suggestFeaturesButton.clicked.connect(self.show_feature_selection_dialog) self.featSelDlg.accepted.connect(self.update_features_from_dialog) self.labelingDrawerUi.suggestFeaturesButton.setEnabled(False) self.topLevelOperatorView.LabelNames.notifyDirty( bind(self.handleLabelSelectionChange) ) self.__cleanup_fns.append( partial( self.topLevelOperatorView.LabelNames.unregisterDirty, bind(self.handleLabelSelectionChange) ) ) self._initShortcuts() self._bookmarks_window = BookmarksWindow(self, self.topLevelOperatorView) # FIXME: We MUST NOT enable the render manager by default, # since it will drastically slow down the app for large volumes. # For now, we leave it off by default. # To re-enable rendering, we need to allow the user to render a segmentation # and then initialize the render manager on-the-fly. # (We might want to warn the user if her volume is not small.) self.render = False self._renderMgr = None self._renderedLayers = {} # (layer name, label number) # Always off for now (see note above) if self.render: try: self._renderMgr = RenderingManager( self.editor.view3d ) except: self.render = False # toggle interactive mode according to freezePredictions.value self.toggleInteractive(not self.topLevelOperatorView.FreezePredictions.value) def FreezePredDirty(): self.toggleInteractive(not self.topLevelOperatorView.FreezePredictions.value) # listen to freezePrediction changes self.topLevelOperatorView.FreezePredictions.notifyDirty( bind(FreezePredDirty) ) self.__cleanup_fns.append( partial( self.topLevelOperatorView.FreezePredictions.unregisterDirty, bind(FreezePredDirty) ) )
def __init__(self, parentApplet, topLevelOperatorView, drawerUiPath=None): self.topLevelOperatorView = topLevelOperatorView self.isInitialized = ( False ) # Need this flag in carvingApplet where initialization is terminated with label selection # members self._doneSegmentationLayer = None self._showSegmentationIn3D = False # self._showUncertaintyLayer = False # end: members labelingSlots = LabelingGui.LabelingSlots() labelingSlots.labelInput = topLevelOperatorView.WriteSeeds labelingSlots.labelOutput = topLevelOperatorView.opLabelArray.Output labelingSlots.labelEraserValue = topLevelOperatorView.opLabelArray.EraserLabelValue labelingSlots.labelNames = topLevelOperatorView.LabelNames labelingSlots.labelDelete = topLevelOperatorView.opLabelArray.DeleteLabel labelingSlots.maxLabelValue = topLevelOperatorView.opLabelArray.MaxLabelValue # We provide our own UI file (which adds an extra control for interactive mode) directory = os.path.split(__file__)[0] if drawerUiPath is None: drawerUiPath = os.path.join(directory, "carvingDrawer.ui") self.dialogdirCOM = os.path.join(directory, "carvingObjectManagement.ui") self.dialogdirSAD = os.path.join(directory, "saveAsDialog.ui") # Add 3DWidget only if the data is 3D is_3d = self._is_3d() super(CarvingGui, self).__init__(parentApplet, labelingSlots, topLevelOperatorView, drawerUiPath, is_3d_widget_visible=is_3d) self.parentApplet = parentApplet self.labelingDrawerUi.currentObjectLabel.setText("<not saved yet>") # Init special base class members self.minLabelNumber = 2 self.maxLabelNumber = 2 mgr = ShortcutManager() ActionInfo = ShortcutManager.ActionInfo # set up keyboard shortcuts mgr.register( "3", ActionInfo( "Carving", "Run interactive segmentation", "Run interactive segmentation", self.labelingDrawerUi.segment.click, self.labelingDrawerUi.segment, self.labelingDrawerUi.segment, ), ) # Disable 3D view by default self.render = False if is_3d: try: self._renderMgr = RenderingManager(self.editor.view3d) self._shownObjects3D = {} self.render = True except: self.render = False # Segmentation is toggled on by default in _after_init, below. # (We can't enable it until the layers are all present.) self._showSegmentationIn3D = False self._segmentation_3d_label = None self.labelingDrawerUi.segment.clicked.connect(self.onSegmentButton) self.labelingDrawerUi.segment.setEnabled(True) self.topLevelOperatorView.Segmentation.notifyDirty( bind(self._segmentation_dirty)) self.topLevelOperatorView.HasSegmentation.notifyValueChanged( bind(self._updateGui)) ## uncertainty # self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) # self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) # def onUncertaintyFGButton(): # logger.debug( "uncertFG button clicked" ) # pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=2) # self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) # self.labelingDrawerUi.pushButtonUncertaintyFG.clicked.connect(onUncertaintyFGButton) # def onUncertaintyBGButton(): # logger.debug( "uncertBG button clicked" ) # pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=1) # self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) # self.labelingDrawerUi.pushButtonUncertaintyBG.clicked.connect(onUncertaintyBGButton) # def onUncertaintyCombo(value): # if value == 0: # value = "none" # self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) # self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) # self._showUncertaintyLayer = False # else: # if value == 1: # value = "localMargin" # elif value == 2: # value = "exchangeCount" # elif value == 3: # value = "gabow" # else: # raise RuntimeError("unhandled case '%r'" % value) # self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(True) # self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(True) # self._showUncertaintyLayer = True # logger.debug( "uncertainty changed to %r" % value ) # self.topLevelOperatorView.UncertaintyType.setValue(value) # self.updateAllLayers() #make sure that an added/deleted uncertainty layer is recognized # self.labelingDrawerUi.uncertaintyCombo.currentIndexChanged.connect(onUncertaintyCombo) self.labelingDrawerUi.objPrefix.setText(self.objectPrefix) self.labelingDrawerUi.objPrefix.textChanged.connect( self.setObjectPrefix) ## save self.labelingDrawerUi.save.clicked.connect(self.onSaveButton) ## clear self.labelingDrawerUi.clear.clicked.connect(self._onClearAction) ## object names self.labelingDrawerUi.namesButton.clicked.connect( self.onShowObjectNames) if hasattr(self.labelingDrawerUi, "exportAllMeshesButton"): self.labelingDrawerUi.exportAllMeshesButton.clicked.connect( self._exportAllObjectMeshes) self.labelingDrawerUi.labelListView.allowDelete = False self._labelControlUi.labelListModel.allowRemove(False) def layerIndexForName(name): return self.layerstack.findMatchingIndex(lambda x: x.name == name) def addLayerToggleShortcut(layername, shortcut): def toggle(): row = layerIndexForName(layername) self.layerstack.selectRow(row) layer = self.layerstack[row] layer.visible = not layer.visible self.viewerControlWidget().layerWidget.setFocus() mgr.register( shortcut, ActionInfo( "Carving", "Toggle layer %s" % layername, "Toggle layer %s" % layername, toggle, self.viewerControlWidget(), None, ), ) # TODO addLayerToggleShortcut("Completed segments (unicolor)", "d") addLayerToggleShortcut("Segmentation", "s") addLayerToggleShortcut("Input Data", "r") def makeColortable(): self._doneSegmentationColortable = [QColor(0, 0, 0, 0).rgba()] for i in range(254): r, g, b = numpy.random.randint(0, 255), numpy.random.randint( 0, 255), numpy.random.randint(0, 255) # ensure colors have sufficient distance to pure red and pure green while (255 - r) + g + b < 128 or r + (255 - g) + b < 128: r, g, b = numpy.random.randint( 0, 255), numpy.random.randint( 0, 255), numpy.random.randint(0, 255) self._doneSegmentationColortable.append(QColor(r, g, b).rgba()) self._doneSegmentationColortable.append(QColor(0, 255, 0).rgba()) makeColortable() self._updateGui()
def __init__(self, parentApplet, op): self.isInitialized = False # Need this flag in objectClassificationApplet where initialization is terminated with label selection self.__cleanup_fns = [] # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = op.LabelInputs labelSlots.labelOutput = op.LabelImages labelSlots.labelEraserValue = op.Eraser labelSlots.labelDelete = op.DeleteLabel labelSlots.maxLabelValue = op.NumLabels labelSlots.labelNames = op.LabelNames # We provide our own UI file (which adds an extra control for # interactive mode) This UI file is copied from # pixelClassification pipeline # labelingDrawerUiPath = os.path.split( __file__)[0] + '/labelingDrawer.ui' # Base class init super(ObjectClassificationGui, self).__init__(parentApplet, labelSlots, op, labelingDrawerUiPath, op.RawImages, crosshair=False) self.op = op self.applet = parentApplet self.threadRouter = ThreadRouter(self) op.Warnings.notifyDirty(self.handleWarnings) self.__cleanup_fns.append( partial(op.Warnings.unregisterDirty, self.handleWarnings)) self._retained_weakrefs = [] # unused self.labelingDrawerUi.savePredictionsButton.setEnabled(False) self.labelingDrawerUi.savePredictionsButton.setVisible(False) self.labelingDrawerUi.brushSizeComboBox.setEnabled(False) self.labelingDrawerUi.brushSizeComboBox.setVisible(False) self.labelingDrawerUi.brushSizeCaption.setVisible(False) self._colorTable16_forpmaps = list(colortables.default16_new) self._colorTable16_forpmaps[15] = QColor( Qt.black).rgba() #for objects with NaNs in features # button handlers self._interactiveMode = False self.interactiveMode = False # This calls the setter function: interactiveMode(self, val) self._showPredictions = False self._labelMode = True self.labelingDrawerUi.subsetFeaturesButton.clicked.connect( self.handleSubsetFeaturesClicked) self.labelingDrawerUi.labelAssistButton.clicked.connect( self.handleLabelAssistClicked) self.labelingDrawerUi.liveUpdateButton.setEnabled(False) self.labelingDrawerUi.liveUpdateButton.setIcon(QIcon( ilastikIcons.Play)) self.labelingDrawerUi.liveUpdateButton.setToolButtonStyle( Qt.ToolButtonTextBesideIcon) self.labelingDrawerUi.liveUpdateButton.toggled.connect( self.handleInteractiveModeClicked) # Always force at least two labels because it makes no sense to have less here self.forceAtLeastTwoLabels(True) # select all the features in the beginning cfn = None already_selected = None if self.op.ComputedFeatureNames.ready(): cfn = self.op.ComputedFeatureNames[:].wait() if self.op.SelectedFeatures.ready(): already_selected = self.op.SelectedFeatures[:].wait() if already_selected is None or len(already_selected) == 0: if cfn is not None: already_selected = cfn self.op.SelectedFeatures.setValue(already_selected) nfeatures = 0 if already_selected is not None: for plugin_features in already_selected.values(): nfeatures += len(plugin_features) self.labelingDrawerUi.featuresSubset.setText( "{} features selected,\nsome may have multiple channels".format( nfeatures)) # enable/disable buttons logic self.op.ObjectFeatures.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.ObjectFeatures.unregisterDirty, bind(self.checkEnableButtons))) self.op.NumLabels.notifyReady(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.NumLabels.unregisterReady, bind(self.checkEnableButtons))) self.op.NumLabels.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.NumLabels.unregisterDirty, bind(self.checkEnableButtons))) self.op.SelectedFeatures.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.SelectedFeatures.unregisterDirty, bind(self.checkEnableButtons))) if not self.op.AllowAddLabel([]).wait()[0]: self.labelingDrawerUi.AddLabelButton.hide() self.labelingDrawerUi.AddLabelButton.clicked.disconnect() self.badObjectBox = None self.checkEnableButtons() self._labelAssistDialog = None
def __init__(self, parentApplet, topLevelOperatorView, labelingDrawerUiPath=None): self.parentApplet = parentApplet self.isInitialized = ( False ) # need this flag in pixelClassificationApplet where initialization is terminated with label selection # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelPipeline.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelPipeline.DeleteLabel labelSlots.labelNames = topLevelOperatorView.LabelNames self.__cleanup_fns = [] # We provide our own UI file (which adds an extra control for interactive mode) if labelingDrawerUiPath is None: labelingDrawerUiPath = os.path.split( __file__)[0] + "/labelingDrawer.ui" # Base class init super(PixelClassificationGui, self).__init__(parentApplet, labelSlots, topLevelOperatorView, labelingDrawerUiPath, topLevelOperatorView.InputImages) self.topLevelOperatorView = topLevelOperatorView self._currentlySavingPredictions = False self.labelingDrawerUi.labelListView.support_merges = True self.labelingDrawerUi.liveUpdateButton.toggled.connect( self.setLiveUpdateEnabled) self.initFeatSelDlg() self.labelingDrawerUi.suggestFeaturesButton.clicked.connect( self.show_feature_selection_dialog) self.featSelDlg.accepted.connect(self.update_features_from_dialog) self.labelingDrawerUi.suggestFeaturesButton.setEnabled(False) # Always force at least two labels because it makes no sense to have less here self.forceAtLeastTwoLabels(True) self._initShortcuts() self._bookmarks_window = BookmarksWindow(self, self.topLevelOperatorView) # FIXME: We MUST NOT enable the render manager by default, # since it will drastically slow down the app for large volumes. # For now, we leave it off by default. # To re-enable rendering, we need to allow the user to render a segmentation # and then initialize the render manager on-the-fly. # (We might want to warn the user if her volume is not small.) self.render = False self._renderMgr = None self._renderedLayers = {} # (layer name, label number) # Always off for now (see note above) if self.render: try: self._renderMgr = RenderingManager(self.editor.view3d) except: self.render = False # listen to freezePrediction changes unsub_callback = self.topLevelOperatorView.FreezePredictions.notifyDirty( lambda *args: self.setLiveUpdateEnabled()) self.__cleanup_fns.append(unsub_callback) self.setLiveUpdateEnabled()
def __init__(self, parentApplet, topLevelOperatorView, labelingDrawerUiPath=None): self.parentApplet = parentApplet # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelPipeline.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelPipeline.DeleteLabel labelSlots.labelNames = topLevelOperatorView.LabelNames self.__cleanup_fns = [] # We provide our own UI file (which adds an extra control for interactive mode) if labelingDrawerUiPath is None: labelingDrawerUiPath = os.path.dirname( __file__) + "/labelingDrawer.ui" # Base class init super(VoxelSegmentationGui, self).__init__(parentApplet, labelSlots, topLevelOperatorView, labelingDrawerUiPath) self.topLevelOperatorView = topLevelOperatorView self.interactiveModeActive = False # Immediately update our interactive state self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) self._currentlySavingPredictions = False self._showSegmentationIn3D = False self.labelingDrawerUi.labelListView.support_merges = True self.labelingDrawerUi.liveUpdateButton.setEnabled(False) self.labelingDrawerUi.liveUpdateButton.setIcon(QIcon( ilastikIcons.Play)) self.labelingDrawerUi.liveUpdateButton.setToolButtonStyle( Qt.ToolButtonTextBesideIcon) self.labelingDrawerUi.liveUpdateButton.toggled.connect( self.toggleInteractive) self.initFeatSelDlg() self.labelingDrawerUi.suggestFeaturesButton.clicked.connect( self.show_feature_selection_dialog) self.featSelDlg.accepted.connect(self.update_features_from_dialog) self.labelingDrawerUi.suggestFeaturesButton.setEnabled(False) # Always force at least two labels because it makes no sense to have less here self.forceAtLeastTwoLabels(True) self.topLevelOperatorView.LabelNames.notifyDirty( bind(self.handleLabelSelectionChange)) self.__cleanup_fns.append( partial(self.topLevelOperatorView.LabelNames.unregisterDirty, bind(self.handleLabelSelectionChange))) self._initShortcuts() self._bookmarks_window = pixelClassificationGui.BookmarksWindow( self, self.topLevelOperatorView) # FIXME: We MUST NOT enable the render manager by default, # since it will drastically slow down the app for large volumes. # For now, we leave it off by default. # To re-enable rendering, we need to allow the user to render a segmentation # and then initialize the render manager on-the-fly. # (We might want to warn the user if her volume is not small.) self.render = False self._renderMgr = None self._renderedLayers = {} # (layer name, label number) # Always off for now (see note above) if self.render: # try: self._renderMgr = RenderingManager(self.editor.view3d) # except: # self.render = False # toggle interactive mode according to freezePredictions.value self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) def FreezePredDirty(): self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) # listen to freezePrediction changes # self.topLevelOperatorView.FreezePredictions.notifyDirty(bind(FreezePredDirty)) self.__cleanup_fns.append( partial( self.topLevelOperatorView.FreezePredictions.unregisterDirty, bind(FreezePredDirty))) def SelectBestAnnotationPlane(): if self.mostUncertainPlanes is None and self.mostUncertainAxis is None: axis, indices = self.topLevelOperatorView.BestAnnotationPlane.value # Axes from the classifiation operator are in the order z y x while volumina has x y z axis = [2, 1, 0][axis] self.mostUncertainAxis = axis self.mostUncertainPlanes = indices # Pop most uncertain plane from list index, self.mostUncertainPlanes = self.mostUncertainPlanes[ -1], self.mostUncertainPlanes[:-1] # Display the plane self.editor.navCtrl.changeSliceAbsolute(index, self.mostUncertainAxis) def resetBestPlanes(): logger.info("resetting planes") self.mostUncertainPlanes = None self.mostUncertainAxis = None resetBestPlanes() self.topLevelOperatorView.FreezePredictions.notifyDirty( bind(resetBestPlanes)) self.topLevelOperatorView.LabelImages.notifyDirty( bind(resetBestPlanes)) self.labelingDrawerUi.bestAnnotationPlaneButton.clicked.connect( SelectBestAnnotationPlane)
def __init__(self, op, shellRequestSignal, guiControlSignal): self.__cleanup_fns = [] # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = op.LabelInputs labelSlots.labelOutput = op.LabelImages labelSlots.labelEraserValue = op.Eraser labelSlots.labelDelete = op.DeleteLabel labelSlots.maxLabelValue = op.NumLabels labelSlots.labelsAllowed = op.LabelsAllowedFlags labelSlots.LabelNames = op.LabelNames # We provide our own UI file (which adds an extra control for # interactive mode) This UI file is copied from # pixelClassification pipeline # labelingDrawerUiPath = os.path.split( __file__)[0] + '/labelingDrawer.ui' # Base class init super(ObjectClassificationGui, self).__init__(labelSlots, op, labelingDrawerUiPath, crosshair=False) self.op = op self.guiControlSignal = guiControlSignal self.shellRequestSignal = shellRequestSignal self.threadRouter = ThreadRouter(self) op.Warnings.notifyDirty(self.handleWarnings) self.__cleanup_fns.append( partial(op.Warnings.unregisterDirty, self.handleWarnings)) self._retained_weakrefs = [] # unused self.labelingDrawerUi.savePredictionsButton.setEnabled(False) self.labelingDrawerUi.savePredictionsButton.setVisible(False) self.labelingDrawerUi.brushSizeComboBox.setEnabled(False) self.labelingDrawerUi.brushSizeComboBox.setVisible(False) self.labelingDrawerUi.brushSizeCaption.setVisible(False) self._colorTable16_forpmaps = self._createDefault16ColorColorTable() self._colorTable16_forpmaps[15] = QColor( Qt.black).rgba() #for objects with NaNs in features # button handlers self._interactiveMode = False self._showPredictions = False self._labelMode = True self.labelingDrawerUi.subsetFeaturesButton.clicked.connect( self.handleSubsetFeaturesClicked) self.labelingDrawerUi.checkInteractive.toggled.connect( self.handleInteractiveModeClicked) self.labelingDrawerUi.checkShowPredictions.toggled.connect( self.handleShowPredictionsClicked) #select all the features in the beginning cfn = None already_selected = None if self.op.ComputedFeatureNames.ready(): cfn = self.op.ComputedFeatureNames[:].wait() if self.op.SelectedFeatures.ready(): already_selected = self.op.SelectedFeatures[:].wait() if already_selected is None or len(already_selected) == 0: if cfn is not None: already_selected = cfn self.op.SelectedFeatures.setValue(already_selected) nfeatures = 0 if already_selected is not None: for plugin_features in already_selected.itervalues(): nfeatures += len(plugin_features) self.labelingDrawerUi.featuresSubset.setText( "{} features selected,\nsome may have multiple channels".format( nfeatures)) # enable/disable buttons logic self.op.ObjectFeatures.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.ObjectFeatures.unregisterDirty, bind(self.checkEnableButtons))) self.op.NumLabels.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.NumLabels.unregisterDirty, bind(self.checkEnableButtons))) self.op.SelectedFeatures.notifyDirty(bind(self.checkEnableButtons)) self.__cleanup_fns.append( partial(op.SelectedFeatures.unregisterDirty, bind(self.checkEnableButtons))) self.checkEnableButtons()
def __init__(self, parentApplet, topLevelOperatorView, drawerUiPath=None ): self.topLevelOperatorView = topLevelOperatorView #members self._doneSegmentationLayer = None self._showSegmentationIn3D = False self._showUncertaintyLayer = False #end: members labelingSlots = LabelingGui.LabelingSlots() labelingSlots.labelInput = topLevelOperatorView.WriteSeeds labelingSlots.labelOutput = topLevelOperatorView.opLabelArray.Output labelingSlots.labelEraserValue = topLevelOperatorView.opLabelArray.EraserLabelValue labelingSlots.labelNames = topLevelOperatorView.LabelNames labelingSlots.labelDelete = topLevelOperatorView.opLabelArray.DeleteLabel labelingSlots.maxLabelValue = topLevelOperatorView.opLabelArray.MaxLabelValue labelingSlots.labelsAllowed = topLevelOperatorView.LabelsAllowed # We provide our own UI file (which adds an extra control for interactive mode) directory = os.path.split(__file__)[0] if drawerUiPath is None: drawerUiPath = os.path.join(directory, 'carvingDrawer.ui') self.dialogdirCOM = os.path.join(directory, 'carvingObjectManagement.ui') self.dialogdirSAD = os.path.join(directory, 'saveAsDialog.ui') rawInputSlot = topLevelOperatorView.RawData super(CarvingGui, self).__init__(parentApplet, labelingSlots, topLevelOperatorView, drawerUiPath, rawInputSlot) self.labelingDrawerUi.currentObjectLabel.setText("<not saved yet>") # Init special base class members self.minLabelNumber = 2 self.maxLabelNumber = 2 mgr = ShortcutManager() ActionInfo = ShortcutManager.ActionInfo #set up keyboard shortcuts mgr.register( "3", ActionInfo( "Carving", "Run interactive segmentation", "Run interactive segmentation", self.labelingDrawerUi.segment.click, self.labelingDrawerUi.segment, self.labelingDrawerUi.segment ) ) try: self.render = True self._shownObjects3D = {} self._renderMgr = RenderingManager( self.editor.view3d ) except: self.render = False # Segmentation is toggled on by default in _after_init, below. # (We can't enable it until the layers are all present.) self._showSegmentationIn3D = False self._segmentation_3d_label = None self.labelingDrawerUi.segment.clicked.connect(self.onSegmentButton) self.labelingDrawerUi.segment.setEnabled(True) self.topLevelOperatorView.Segmentation.notifyDirty( bind( self._update_rendering ) ) self.topLevelOperatorView.HasSegmentation.notifyValueChanged( bind( self._updateGui ) ) ## uncertainty self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) def onUncertaintyFGButton(): logger.debug( "uncertFG button clicked" ) pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=2) self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) self.labelingDrawerUi.pushButtonUncertaintyFG.clicked.connect(onUncertaintyFGButton) def onUncertaintyBGButton(): logger.debug( "uncertBG button clicked" ) pos = self.topLevelOperatorView.getMaxUncertaintyPos(label=1) self.editor.posModel.slicingPos = (pos[0], pos[1], pos[2]) self.labelingDrawerUi.pushButtonUncertaintyBG.clicked.connect(onUncertaintyBGButton) def onUncertaintyCombo(value): if value == 0: value = "none" self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(False) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(False) self._showUncertaintyLayer = False else: if value == 1: value = "localMargin" elif value == 2: value = "exchangeCount" elif value == 3: value = "gabow" else: raise RuntimeError("unhandled case '%r'" % value) self.labelingDrawerUi.pushButtonUncertaintyFG.setEnabled(True) self.labelingDrawerUi.pushButtonUncertaintyBG.setEnabled(True) self._showUncertaintyLayer = True logger.debug( "uncertainty changed to %r" % value ) self.topLevelOperatorView.UncertaintyType.setValue(value) self.updateAllLayers() #make sure that an added/deleted uncertainty layer is recognized self.labelingDrawerUi.uncertaintyCombo.currentIndexChanged.connect(onUncertaintyCombo) ## background priority def onBackgroundPrioritySpin(value): logger.debug( "background priority changed to %f" % value ) self.topLevelOperatorView.BackgroundPriority.setValue(value) self.labelingDrawerUi.backgroundPrioritySpin.valueChanged.connect(onBackgroundPrioritySpin) def onBackgroundPriorityDirty(slot, roi): oldValue = self.labelingDrawerUi.backgroundPrioritySpin.value() newValue = self.topLevelOperatorView.BackgroundPriority.value if newValue != oldValue: self.labelingDrawerUi.backgroundPrioritySpin.setValue(newValue) self.topLevelOperatorView.BackgroundPriority.notifyDirty(onBackgroundPriorityDirty) ## bias def onNoBiasBelowDirty(slot, roi): oldValue = self.labelingDrawerUi.noBiasBelowSpin.value() newValue = self.topLevelOperatorView.NoBiasBelow.value if newValue != oldValue: self.labelingDrawerUi.noBiasBelowSpin.setValue(newValue) self.topLevelOperatorView.NoBiasBelow.notifyDirty(onNoBiasBelowDirty) def onNoBiasBelowSpin(value): logger.debug( "background priority changed to %f" % value ) self.topLevelOperatorView.NoBiasBelow.setValue(value) self.labelingDrawerUi.noBiasBelowSpin.valueChanged.connect(onNoBiasBelowSpin) ## save self.labelingDrawerUi.save.clicked.connect(self.onSaveButton) ## clear self.labelingDrawerUi.clear.clicked.connect(self._onClearAction) ## object names self.labelingDrawerUi.namesButton.clicked.connect(self.onShowObjectNames) if hasattr( self.labelingDrawerUi, 'exportAllMeshesButton' ): self.labelingDrawerUi.exportAllMeshesButton.clicked.connect(self._exportAllObjectMeshes) def labelBackground(): self.selectLabel(0) def labelObject(): self.selectLabel(1) self._labelControlUi.labelListModel.allowRemove(False) bgToolTipObject = LabelListModel.EntryToolTipAdapter(self._labelControlUi.labelListModel, 0) mgr.register( "1", ActionInfo( "Carving", "Select background label", "Select background label", labelBackground, self.viewerControlWidget(), bgToolTipObject ) ) fgToolTipObject = LabelListModel.EntryToolTipAdapter(self._labelControlUi.labelListModel, 1) mgr.register( "2", ActionInfo( "Carving", "Select object label", "Select object label", labelObject, self.viewerControlWidget(), fgToolTipObject ) ) def layerIndexForName(name): return self.layerstack.findMatchingIndex(lambda x: x.name == name) def addLayerToggleShortcut(layername, shortcut): def toggle(): row = layerIndexForName(layername) self.layerstack.selectRow(row) layer = self.layerstack[row] layer.visible = not layer.visible self.viewerControlWidget().layerWidget.setFocus() mgr.register(shortcut, ActionInfo( "Carving", "Toggle layer %s" % layername, "Toggle layer %s" % layername, toggle, self.viewerControlWidget(), None ) ) #TODO addLayerToggleShortcut("Completed segments (unicolor)", "d") addLayerToggleShortcut("Segmentation", "s") addLayerToggleShortcut("Input Data", "r") ''' def updateLayerTimings(): s = "Layer timings:\n" for l in self.layerstack: s += "%s: %f sec.\n" % (l.name, l.averageTimePerTile) self.labelingDrawerUi.layerTimings.setText(s) t = QTimer(self) t.setInterval(1*1000) # 10 seconds t.start() t.timeout.connect(updateLayerTimings) ''' def makeColortable(): self._doneSegmentationColortable = [QColor(0,0,0,0).rgba()] for i in range(254): r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) # ensure colors have sufficient distance to pure red and pure green while (255 - r)+g+b<128 or r+(255-g)+b<128: r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) self._doneSegmentationColortable.append(QColor(r,g,b).rgba()) self._doneSegmentationColortable.append(QColor(0,255,0).rgba()) makeColortable() def onRandomizeColors(): if self._doneSegmentationLayer is not None: logger.debug( "randomizing colors ..." ) makeColortable() self._doneSegmentationLayer.colorTable = self._doneSegmentationColortable if self.render and self._renderMgr.ready: self._update_rendering() #self.labelingDrawerUi.randomizeColors.clicked.connect(onRandomizeColors) self._updateGui()
def __init__(self, topLevelOperatorView, shellRequestSignal, guiControlSignal, predictionSerializer): # Tell our base class which slots to monitor labelSlots = LabelingGui.LabelingSlots() labelSlots.labelInput = topLevelOperatorView.LabelInputs labelSlots.labelOutput = topLevelOperatorView.LabelImages labelSlots.labelEraserValue = topLevelOperatorView.opLabelPipeline.opLabelArray.eraser labelSlots.labelDelete = topLevelOperatorView.opLabelPipeline.opLabelArray.deleteLabel labelSlots.maxLabelValue = topLevelOperatorView.MaxLabelValue labelSlots.labelsAllowed = topLevelOperatorView.LabelsAllowedFlags labelSlots.LabelNames = topLevelOperatorView.LabelNames self.__cleanup_fns = [] # We provide our own UI file (which adds an extra control for interactive mode) labelingDrawerUiPath = os.path.split( __file__)[0] + '/labelingDrawer.ui' # Base class init super(PixelClassificationGui, self).__init__(labelSlots, topLevelOperatorView, labelingDrawerUiPath) self.topLevelOperatorView = topLevelOperatorView self.shellRequestSignal = shellRequestSignal self.guiControlSignal = guiControlSignal self.predictionSerializer = predictionSerializer self.interactiveModeActive = False # Immediately update our interactive state self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) self._currentlySavingPredictions = False self.labelingDrawerUi.liveUpdateButton.setEnabled(False) self.labelingDrawerUi.liveUpdateButton.setIcon(QIcon( ilastikIcons.Play)) self.labelingDrawerUi.liveUpdateButton.setToolButtonStyle( Qt.ToolButtonTextBesideIcon) self.labelingDrawerUi.liveUpdateButton.toggled.connect( self.toggleInteractive) self.topLevelOperatorView.MaxLabelValue.notifyDirty( bind(self.handleLabelSelectionChange)) self.__cleanup_fns.append( partial(self.topLevelOperatorView.MaxLabelValue.unregisterDirty, bind(self.handleLabelSelectionChange))) self._initShortcuts() try: self.render = True self._renderedLayers = {} # (layer name, label number) self._renderMgr = RenderingManager( renderer=self.editor.view3d.qvtk.renderer, qvtk=self.editor.view3d.qvtk) except: self.render = False # toggle interactive mode according to freezePredictions.value self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) def FreezePredDirty(): self.toggleInteractive( not self.topLevelOperatorView.FreezePredictions.value) # listen to freezePrediction changes self.topLevelOperatorView.FreezePredictions.notifyDirty( bind(FreezePredDirty)) self.__cleanup_fns.append( partial( self.topLevelOperatorView.FreezePredictions.unregisterDirty, bind(FreezePredDirty)))