def createLabelLayer(self, direct=False): """ Return a colortable layer that displays the label slot data, along with its associated label source. direct: whether this layer is drawn synchronously by volumina """ labelOutput = self._labelingSlots.labelOutput if not labelOutput.ready(): return (None, None) else: # Add the layer to draw the labels, but don't add any labels labelsrc = LazyflowSinkSource(self._labelingSlots.labelOutput, self._labelingSlots.labelInput) labellayer = ColortableLayer(labelsrc, colorTable=self._colorTable16, direct=direct) labellayer.name = "Labels" labellayer.ref_object = None labellayer.contexts.append( QAction("Import...", None, triggered=partial(import_labeling_layer, labellayer, self._labelingSlots, self))) labellayer.shortcutRegistration = ("0", ShortcutManager.ActionInfo( "Labeling", "LabelVisibility", "Show/Hide Labels", labellayer.toggleVisible, self.viewerControlWidget(), labellayer)) return labellayer, labelsrc
def setupLayers(self): """ Sets up the label layer for display by our base class (LayerViewerGui). If our subclass overrides this function to add his own layers, he **must** call this function explicitly. """ layers = [] # Labels labellayer, labelsrc = self.createLabelLayer() if labellayer is not None: layers.append(labellayer) # Tell the editor where to draw label data self.editor.setLabelSink(labelsrc) # Side effect 1: We want to guarantee that the label list # is up-to-date before our subclass adds his layers self._updateLabelList() # Raw Input Layer if self._rawInputSlot is not None and self._rawInputSlot.ready(): layer = self.createStandardLayerFromSlot(self._rawInputSlot) layer.name = "Raw Input" layer.visible = True layer.opacity = 1.0 # the flag window_leveling is used to determine if the contrast # of the layer is adjustable if isinstance(layer, GrayscaleLayer): layer.window_leveling = True else: layer.window_leveling = False layers.append(layer) # The thresholding button can only be used if the data is displayed as grayscale. if layer.window_leveling: self.labelingDrawerUi.thresToolButton.show() else: self.labelingDrawerUi.thresToolButton.hide() def toggleTopToBottom(): index = self.layerstack.layerIndex(layer) self.layerstack.selectRow(index) if index == 0: self.layerstack.moveSelectedToBottom() else: self.layerstack.moveSelectedToTop() layer.shortcutRegistration = ("i", ShortcutManager.ActionInfo( "Prediction Layers", "Bring Input To Top/Bottom", "Bring Input To Top/Bottom", toggleTopToBottom, self.viewerControlWidget(), layer)) return layers
def setupLayers(self): """ Sets up the label layer for display by our base class (LayerViewerGui). If our subclass overrides this function to add his own layers, he **must** call this function explicitly. """ layers = [] # Labels labellayer, labelsrc = self.createLabelLayer() if labellayer is not None: layers.append(labellayer) # Side effect 1: We want to guarantee that the label list # is up-to-date before our subclass adds his layers self._updateLabelList() # Raw Input Layer if self._rawInputSlot is not None and self._rawInputSlot.ready(): layer = self.createStandardLayerFromSlot(self._rawInputSlot, name="Raw Input") layers.append(layer) if isinstance(layer, GrayscaleLayer): self.labelingDrawerUi.thresToolButton.show() else: self.labelingDrawerUi.thresToolButton.hide() def toggleTopToBottom(): index = self.layerstack.layerIndex(layer) self.layerstack.selectRow(index) if index == 0: self.layerstack.moveSelectedToBottom() else: self.layerstack.moveSelectedToTop() layer.shortcutRegistration = ( "i", ShortcutManager.ActionInfo( "Prediction Layers", "Bring Input To Top/Bottom", "Bring Input To Top/Bottom", toggleTopToBottom, self.viewerControlWidget(), layer, ), ) return layers
def setupLayers(self): layers = [] op = self.topLevelOperatorView ravelerLabelsSlot = op.RavelerLabels if ravelerLabelsSlot.ready(): colortable = [] for _ in range(256): r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) colortable.append(QColor(r,g,b).rgba()) ravelerLabelLayer = ColortableLayer(LazyflowSource(ravelerLabelsSlot), colortable, direct=True) ravelerLabelLayer.name = "Raveler Labels" ravelerLabelLayer.visible = False ravelerLabelLayer.opacity = 0.4 layers.append(ravelerLabelLayer) def addFragmentSegmentationLayers(mslot, name): if mslot.ready(): for index, slot in enumerate(mslot): if slot.ready(): raveler_label = slot.meta.selected_label colortable = map(QColor.rgba, self._fragmentColors) fragSegLayer = ColortableLayer(LazyflowSource(slot), colortable, direct=True) fragSegLayer.name = "{} #{} ({})".format( name, index, raveler_label ) fragSegLayer.visible = False fragSegLayer.opacity = 1.0 layers.append(fragSegLayer) addFragmentSegmentationLayers( op.FragmentedBodies, "Saved Fragments" ) addFragmentSegmentationLayers( op.RelabeledFragments, "Relabeled Fragments" ) addFragmentSegmentationLayers( op.FilteredFragmentedBodies, "CC-Filtered Fragments" ) addFragmentSegmentationLayers( op.WatershedFilledBodies, "Watershed-filled Fragments" ) mslot = op.EditedRavelerBodies for index, slot in enumerate(mslot): if slot.ready(): raveler_label = slot.meta.selected_label # 0=Black, 1=Transparent colortable = [QColor(0, 0, 0).rgba(), QColor(0, 0, 0, 0).rgba()] bodyMaskLayer = ColortableLayer(LazyflowSource(slot), colortable, direct=True) bodyMaskLayer.name = "Raveler Body Mask #{} ({})".format( index, raveler_label ) bodyMaskLayer.visible = False bodyMaskLayer.opacity = 1.0 layers.append(bodyMaskLayer) finalSegSlot = op.FinalSegmentation if finalSegSlot.ready(): colortable = [] for _ in range(256): r,g,b = numpy.random.randint(0,255), numpy.random.randint(0,255), numpy.random.randint(0,255) colortable.append(QColor(r,g,b).rgba()) finalLayer = ColortableLayer(LazyflowSource(finalSegSlot), colortable, direct=True) finalLayer.name = "Final Segmentation" finalLayer.visible = False finalLayer.opacity = 0.4 layers.append(finalLayer) inputSlot = op.InputData if inputSlot.ready(): layer = GrayscaleLayer( LazyflowSource(inputSlot) ) layer.name = "WS Input" layer.visible = False layer.opacity = 1.0 layers.append(layer) #raw data rawSlot = self.topLevelOperatorView.RawData rawLayer = None if rawSlot.ready(): raw5D = self.topLevelOperatorView.RawData.value rawLayer = GrayscaleLayer(ArraySource(raw5D), direct=True) #rawLayer = GrayscaleLayer( LazyflowSource(rawSlot) ) rawLayer.name = "raw" rawLayer.visible = True rawLayer.opacity = 1.0 rawLayer.shortcutRegistration = ( "g", ShortcutManager.ActionInfo( "Postprocessing", "Raw Data to Top", "Raw Data to Top", partial(self._toggleRawDataPosition, rawLayer), self.viewerControlWidget(), rawLayer ) ) layers.append(rawLayer) return layers