def setupLayers(self): layers = [] fromDiskSlot = self.topLevelOperatorView.ImageOnDisk if fromDiskSlot.ready(): exportLayer = ColortableLayer(createDataSource(fromDiskSlot), colorTable=self.ct) exportLayer.name = "Selected Output - Exported" exportLayer.visible = True layers.append(exportLayer) previewSlot = self.topLevelOperatorView.ImageToExport if previewSlot.ready(): previewLayer = ColortableLayer(createDataSource(previewSlot), colorTable=self.ct) previewLayer.name = "Selected Output - Preview" previewLayer.visible = False layers.append(previewLayer) rawSlot = self.topLevelOperatorView.RawData if rawSlot.ready(): rawLayer = self.createStandardLayerFromSlot(rawSlot) rawLayer.name = "Raw Data" rawLayer.opacity = 1.0 layers.append(rawLayer) return layers
def setupLayers(self): layers = [] predictionSlot = self.topLevelOperatorView.PredictionImage if predictionSlot.ready(): predictLayer = ColortableLayer(createDataSource(predictionSlot), colorTable=self._colorTable16) predictLayer.name = "Blockwise prediction" predictLayer.visible = False layers.append(predictLayer) binarySlot = self.topLevelOperatorView.BinaryImage if binarySlot.ready(): ct_binary = [ QColor(0, 0, 0, 0).rgba(), QColor(255, 255, 255, 255).rgba() ] binaryLayer = ColortableLayer(createDataSource(binarySlot), ct_binary) binaryLayer.name = "Binary Image" layers.append(binaryLayer) rawSlot = self.topLevelOperatorView.RawImage if rawSlot.ready(): rawLayer = self.createStandardLayerFromSlot(rawSlot) rawLayer.name = "Raw data" layers.append(rawLayer) return layers
def setupLayers(self): layers = [] op = self.topLevelOperatorView binct = [QColor(Qt.black), QColor(Qt.white)] # binct[0] = 0 ct = create_default_16bit() # associate label 0 with black/transparent? ct[0] = 0 # Show the cached output, since it goes through a blocked cache if op.CachedOutput.ready(): outputSrc = createDataSource(op.CachedOutput) outputLayer = ColortableLayer(outputSrc, ct) outputLayer.name = "Connected Components" outputLayer.visible = False outputLayer.opacity = 1.0 outputLayer.setToolTip("Results of connected component analysis") layers.append(outputLayer) if op.Input.ready(): rawSrc = createDataSource(op.Input) rawLayer = ColortableLayer(outputSrc, binct) # rawLayer = self.createStandardLayerFromSlot(op.Input) rawLayer.name = "Raw data" rawLayer.visible = True rawLayer.opacity = 1.0 layers.append(rawLayer) return layers
def setupLayers(self): layers = [] op = self.topLevelOperatorView # Superpixels if op.Superpixels.ready(): layer = ColortableLayer( createDataSource(op.Superpixels), self._sp_colortable ) layer.colortableIsRandom = True layer.name = "Superpixels" layer.visible = True layer.opacity = 0.5 layers.append(layer) del layer # Debug layers if op.debug_results: for name, compressed_array in list(op.debug_results.items()): axiskeys = op.Superpixels.meta.getAxisKeys()[:-1] # debug images don't have a channel axis permutation = [axiskeys.index(key) if key in axiskeys else None for key in 'txyzc'] arraysource = ArraySource( TransposedView(compressed_array, permutation) ) if compressed_array.dtype == np.uint32: layer = ColortableLayer(arraysource, self._sp_colortable) else: layer = GrayscaleLayer(arraysource) # TODO: Normalize? Maybe the drange should be included with the debug image. layer.name = name layer.visible = False layer.opacity = 1.0 layers.append(layer) del layer # Threshold if op.ThresholdedInput.ready(): layer = ColortableLayer( createDataSource(op.ThresholdedInput), self._threshold_colortable ) layer.name = "Thresholded Input" layer.visible = True layer.opacity = 1.0 layers.append(layer) del layer # Raw Data (grayscale) if op.Input.ready(): layer = self._create_grayscale_layer_from_slot( op.Input, op.Input.meta.getTaggedShape()['c'] ) layer.name = "Probability Map" layer.visible = False layer.opacity = 1.0 layers.append(layer) del layer # Raw Data (grayscale) if op.RawData.ready(): layer = self.createStandardLayerFromSlot( op.RawData ) layer.name = "Raw Data" layer.visible = True layer.opacity = 1.0 layers.append(layer) del layer return layers
def _create_rgba_layer_from_slot(cls, slot, numChannels, lastChannelIsAlpha): bindex = aindex = None rindex, gindex = 0,1 if numChannels > 3 or (numChannels == 3 and not lastChannelIsAlpha): bindex = 2 if lastChannelIsAlpha: aindex = numChannels-1 if numChannels>=2: gindex = 1 if numChannels>=3: bindex = 2 if numChannels>=4: aindex = numChannels-1 redSource = None if rindex is not None: redProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent) redProvider.Input.connect(slot) redProvider.Index.setValue( rindex ) redSource = createDataSource( redProvider.Output ) redSource.additional_owned_ops.append( redProvider ) greenSource = None if gindex is not None: greenProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent) greenProvider.Input.connect(slot) greenProvider.Index.setValue( gindex ) greenSource = createDataSource( greenProvider.Output ) greenSource.additional_owned_ops.append( greenProvider ) blueSource = None if bindex is not None: blueProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent) blueProvider.Input.connect(slot) blueProvider.Index.setValue( bindex ) blueSource = createDataSource( blueProvider.Output ) blueSource.additional_owned_ops.append( blueProvider ) alphaSource = None if aindex is not None: alphaProvider = OpSingleChannelSelector(parent=slot.getRealOperator().parent) alphaProvider.Input.connect(slot) alphaProvider.Index.setValue( aindex ) alphaSource = createDataSource( alphaProvider.Output ) alphaSource.additional_owned_ops.append( alphaProvider ) layer = RGBALayer( red=redSource, green=greenSource, blue=blueSource, alpha=alphaSource) normalize = cls._should_normalize_display(slot) for i in range(4): if [redSource,greenSource,blueSource,alphaSource][i]: layer.set_range(i, slot.meta.drange) layer.set_normalize(i, normalize) return layer
def create_multicut_disagreement_layer(self): ActionInfo = ShortcutManager.ActionInfo op = self.__topLevelOperatorView if not op.Output.ready(): return None # Final segmentation -- Edges default_pen = QPen(SegmentationEdgesLayer.DEFAULT_PEN) default_pen.setColor(Qt.transparent) layer = SegmentationEdgesLayer(createDataSource(op.Superpixels), default_pen) layer.name = "Multicut Disagreements" layer.visible = False # Off by default... layer.opacity = 1.0 self.disagreement_layer = layer self.__update_disagreement_edges() # Initialize layer.shortcutRegistration = ( "d", ActionInfo( "Multicut", "MulticutDisagrementVisibility", "Show/Hide Multicut Disagreement Edges", layer.toggleVisible, self.viewerControlWidget(), layer, ), ) return layer
def _initPredictionLayers(self, predictionSlot): layers = [] opLane = self.topLevelOperatorView # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(predictionSlot) opSlicer.AxisFlag.setValue("c") for channel, channelSlot in enumerate(opSlicer.Slices): if channelSlot.ready(): drange = channelSlot.meta.drange or (0.0, 1.0) predictsrc = createDataSource(channelSlot) predictLayer = AlphaModulatedLayer( predictsrc, tintColor=QColor.fromRgba(self._colorTable16[channel + 1]), # FIXME: This is weird. Why are range and normalize both set to the same thing? range=drange, normalize=drange, ) predictLayer.opacity = 1.0 predictLayer.visible = True predictLayer.name = "Probability Channel #{}".format(channel + 1) layers.append(predictLayer) return layers
def create_multicut_edge_layer(self): ActionInfo = ShortcutManager.ActionInfo op = self.__topLevelOperatorView if not op.Output.ready(): return None # Final segmentation -- Edges default_pen = QPen(SegmentationEdgesLayer.DEFAULT_PEN) default_pen.setColor(Qt.blue) layer = SegmentationEdgesLayer(createDataSource(op.Output), default_pen) layer.name = "Multicut Edges" layer.visible = False # Off by default... layer.opacity = 1.0 layer.shortcutRegistration = ( "m", ActionInfo( "Multicut", "MulticutEdgesVisibility", "Show/Hide Multicut Edges", layer.toggleVisible, self.viewerControlWidget(), layer, ), ) return layer
def _add_color_layer(self, data, name=None, visible=False): ''' adds a color layer to the layerstack :param data: numpy array (2D, c) containing the data (c is color) :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 3 data_sources = [] for i in range(data.shape[2]): a, data_shape = createDataSource(data[:,:,i], True) data_sources.append(a) self.editor.dataShape = list(data_shape) if data.shape[2] == 2: new_layer = RGBALayer(data_sources[0], data_sources[1]) elif data.shape[2] == 3: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2]) elif data.shape[2] == 4: new_layer = RGBALayer(data_sources[0], data_sources[1], data_sources[2], data_sources[3]) else: raise Exception("Unexpected number of colors") new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def setupLayers(self): layers = [self.createStandardLayerFromSlot(self.topLevelOperatorView.Input)] layers[0].opacity = 1.0 superVoxelBoundarySlot = self.topLevelOperatorView.BoundariesOutput if superVoxelBoundarySlot.ready(): layer = AlphaModulatedLayer( LazyflowSource(superVoxelBoundarySlot), tintColor=QColor(Qt.blue), range=(0.0, 1.0), normalize=(0.0, 1.0), ) layer.name = "Supervoxel Boundaries" layer.visible = True layer.opacity = 1.0 layers.insert(0, layer) superVoxelSlot = self.topLevelOperatorView.Output if superVoxelSlot.ready(): colortable = generateRandomColors(M=256, clamp={"v": 1.0, "s": 0.5}, zeroIsTransparent=False) layer = ColortableLayer(createDataSource(superVoxelSlot), colortable) layer.colortableIsRandom = True layer.name = "SLIC Superpixels" layer.visible = True layer.opacity = 1.0 layers.insert(0, layer) return layers
def _onReady(self, slot): if slot is self.topLevelOperatorView.RawImage: if slot.meta.shape and not self.rawsrc: self.rawsrc = createDataSource( self.topLevelOperatorView.RawImage) layerraw = GrayscaleLayer(self.rawsrc) layerraw.name = "Raw data" self.layerstack.append(layerraw)
def _create_grayscale_layer_from_slot(cls, slot, n_channels): # FIXME: move all of this stuff into the class constructor. Same for all # _create_*layer_from_slot methods. source = createDataSource(slot) layer = GrayscaleLayer(source, window_leveling=True) layer.numberOfChannels = n_channels layer.set_normalize(0, (slot.meta.normalizeDisplay and slot.meta.drange) or None) return layer
def _create_binary_mask_layer_from_slot(cls, slot): # 0: black, 1-255: transparent # This works perfectly for uint8. # For uint32, etc., values of 256,512, etc. will be appear 'off'. # But why would you use uint32 for a binary mask anyway? colortable = [QColor(0, 0, 0, 255).rgba()] colortable += 255 * [QColor(0, 0, 0, 0).rgba()] layer = ColortableLayer(createDataSource(slot), colortable) return layer
def setupLayers(self): layers = [] opLane = self.topLevelOperatorView selection_names = opLane.SelectionNames.value selection = selection_names[opLane.InputSelection.value] # This code is written to handle the specific output cases we know about. # If those change, update this function! assert selection in [ "Object Predictions", "Object Probabilities", "Blockwise Object Predictions", "Blockwise Object Probabilities", "Object Identities", "Pixel Probabilities", ] if selection in ("Object Predictions", "Blockwise Object Predictions"): previewSlot = self.topLevelOperatorView.ImageToExport if previewSlot.ready(): previewLayer = ColortableLayer(createDataSource(previewSlot), colorTable=self._colorTable16) previewLayer.name = "Prediction - Preview" previewLayer.visible = False layers.append(previewLayer) elif selection in ("Object Probabilities", "Blockwise Object Probabilities"): previewLayers = self._initPredictionLayers(opLane.ImageToExport) for layer in previewLayers: layer.visible = False layer.name = layer.name + "- Preview" layers += previewLayers elif selection == "Pixel Probabilities": previewLayers = self._initPredictionLayers(opLane.ImageToExport) for layer in previewLayers: layer.visible = False layer.name = layer.name + "- Preview" layers += previewLayers elif selection == "Object Identities": previewSlot = self.topLevelOperatorView.ImageToExport layer = self._initColortableLayer(previewSlot) layers.append(layer) else: assert False, "Unknown selection." rawSlot = self.topLevelOperatorView.RawData if rawSlot.ready(): rawLayer = self.createStandardLayerFromSlot(rawSlot) rawLayer.name = "Raw Data" rawLayer.opacity = 1.0 layers.append(rawLayer) return layers
def setupLayers(self): layers = [] opLane = self.topLevelOperatorView # Supervoxels watershedSlot = opLane.WatershedImage if watershedSlot.ready(): colortable = [] for i 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()) watershedLayer = ColortableLayer(createDataSource(watershedSlot), colortable) watershedLayer.name = "Watershed" watershedLayer.visible = False watershedLayer.opacity = 0.5 watershedLayer.colortableIsRandom = True layers.append(watershedLayer) """ FIXME: disabled for 0.6 release wsSourceSlot = opLane.WatershedSourceImage if wsSourceSlot.ready(): wsSourceLayer = self.createStandardLayerFromSlot( wsSourceSlot ) wsSourceLayer.name = "Watershed Source" wsSourceLayer.visible = False wsSourceLayer.opacity = 1.0 layers.append( wsSourceLayer ) """ filteredSlot = opLane.FilteredImage if filteredSlot.ready(): filteredLayer = self.createStandardLayerFromSlot(filteredSlot) filteredLayer.name = "Filtered Data" filteredLayer.visible = False filteredLayer.opacity = 1.0 layers.append(filteredLayer) overlaySlot = opLane.OverlayData if overlaySlot.ready(): inputLayer = self.createStandardLayerFromSlot(overlaySlot) inputLayer.name = "Overlay Image" inputLayer.visible = False inputLayer.opacity = 1.0 layers.append(inputLayer) inputSlot = opLane.InputData if inputSlot.ready(): inputLayer = self.createStandardLayerFromSlot(inputSlot) inputLayer.name = "Input Data" inputLayer.visible = True inputLayer.opacity = 1.0 layers.append(inputLayer) return layers
def _create_random_colortable_layer_from_slot(cls, slot, num_colors=256): colortable = generateRandomColors(num_colors, clamp={ "v": 1.0, "s": 0.5 }, zeroIsTransparent=True) layer = ColortableLayer(createDataSource(slot), colortable) layer.colortableIsRandom = True return layer
def _initColortableLayer(self, labelSlot): objectssrc = createDataSource(labelSlot) objectssrc.setObjectName("LabelImage LazyflowSrc") ct = colortables.create_default_16bit() ct[0] = QColor(0, 0, 0, 0).rgba() # make 0 transparent layer = ColortableLayer(objectssrc, ct) layer.name = "Object Identities - Preview" layer.setToolTip("Segmented objects, shown in different colors") layer.visible = False layer.opacity = 0.5 layer.colortableIsRandom = True return layer
def _onMetaChanged(self, slot): # FiXME: why do we need that? if slot is self.topLevelOperatorView.BinaryImage: if slot.meta.shape: self.editor.dataShape = slot.meta.shape if slot is self.topLevelOperatorView.RawImage: if slot.meta.shape and not self.rawsrc: self.rawsrc = createDataSource( self.topLevelOperatorView.RawImage) layerraw = GrayscaleLayer(self.rawsrc) layerraw.name = "Raw data" self.layerstack.append(layerraw)
def setupLayers(self): """ which layers will be shown in the layerviewergui. Triggers the prediciton by setting the layer on visible """ inputSlot = self.topLevelOperator.InputImage layers = [] for channel, predictionSlot in enumerate( self.topLevelOperator.PredictionProbabilityChannels): if predictionSlot.ready(): predictsrc = createDataSource(predictionSlot) predictionLayer = AlphaModulatedLayer(predictsrc, range=(0.0, 1.0), normalize=(0.0, 1.0)) predictionLayer.visible = self.drawer.liveUpdateButton.isChecked( ) predictionLayer.opacity = 0.25 predictionLayer.visibleChanged.connect( self.updateShowPredictionCheckbox) def setPredLayerName(n, predictLayer_=predictionLayer, initializing=False): """ function for setting the names for every Channel """ if not initializing and predictLayer_ not in self.layerstack: # This layer has been removed from the layerstack already. # Don't touch it. return newName = "Prediction for %s" % n predictLayer_.name = newName setPredLayerName(channel, initializing=True) layers.append(predictionLayer) # always as last layer if inputSlot.ready(): rawLayer = self.createStandardLayerFromSlot(inputSlot) rawLayer.visible = True rawLayer.opacity = 1.0 rawLayer.name = "Raw Data (display only)" layers.append(rawLayer) return layers
def _initColortablelayer(self, segSlot): """ Used to export both segmentation and labels """ if not segSlot.ready(): return None opLane = self.topLevelOperatorView colors = opLane.PmapColors.value colortable = [] colortable.append(QColor(0, 0, 0, 0).rgba()) # transparent for color in colors: colortable.append(QColor(*color).rgba()) segsrc = createDataSource(segSlot) seglayer = ColortableLayer(segsrc, colortable) return seglayer
def _add_grayscale_layer(self, data, name=None, visible=False): ''' adds a grayscale layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' #assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = GrayscaleLayer(a) new_layer.visible = visible if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def _initPredictionLayers(self, predictionSlot): opLane = self.topLevelOperatorView if not opLane.LabelNames.ready() or not opLane.PmapColors.ready(): return [] layers = [] colors = opLane.PmapColors.value names = opLane.LabelNames.value if predictionSlot.ready(): if 'c' in predictionSlot.meta.getAxisKeys(): num_channels = predictionSlot.meta.getTaggedShape()['c'] else: num_channels = 1 if num_channels != len(names) or num_channels != len(colors): names = [ "Label {}".format(n) for n in range(1, num_channels + 1) ] colors = num_channels * [ (0, 0, 0) ] # it doesn't matter, if the pmaps color is not known, # we are either initializing and it will be rewritten or # something is very wrong elsewhere # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(predictionSlot) opSlicer.AxisFlag.setValue('c') for channel, channelSlot in enumerate(opSlicer.Slices): if channelSlot.ready( ) and channel < len(colors) and channel < len(names): drange = channelSlot.meta.drange or (0.0, 1.0) predictsrc = createDataSource(channelSlot) predictLayer = AlphaModulatedLayer( predictsrc, tintColor=QColor(*colors[channel]), # FIXME: This is weird. Why are range and normalize both set to the same thing? range=drange, normalize=drange) predictLayer.opacity = 0.25 predictLayer.visible = True predictLayer.name = names[channel] layers.append(predictLayer) return layers
def _add_segmentation_layer(self, data, name=None, visible=False): ''' adds a segementation layer to the layerstack :param data: numpy array (2D) containing the data :param name: name of layer :param visible: bool determining whether this layer should be set to visible :return: ''' assert len(data.shape) == 2 a, data_shape = createDataSource(data, True) self.editor.dataShape = list(data_shape) new_layer = ColortableLayer(a, self.colortable) new_layer.visible = visible new_layer.opacity = 0.5 if name is not None: new_layer.name = name self.layerstack.append(new_layer)
def initUic(self): self.g = g = Graph() #get the absolute path of the 'ilastik' module uic.loadUi("designerElements/MainWindow.ui", self) self.actionQuit.triggered.connect(qApp.quit) def toggleDebugPatches(show): self.editor.showDebugPatches = show self.actionShowDebugPatches.toggled.connect(toggleDebugPatches) self.layerstack = LayerStackModel() readerNew = op.OpH5ReaderBigDataset(g) readerNew.inputs["Filenames"].setValue([ "scripts/CB_compressed_XY.h5", "scripts/CB_compressed_XZ.h5", "scripts/CB_compressed_YZ.h5" ]) readerNew.inputs["hdf5Path"].setValue("volume/data") datasrc = createDataSource(readerNew.outputs["Output"]) layer1 = GrayscaleLayer(datasrc) layer1.name = "Big Data" self.layerstack.append(layer1) shape = readerNew.outputs["Output"].meta.shape print(shape) self.editor = VolumeEditor(shape, self.layerstack) #self.editor.setDrawingEnabled(False) self.volumeEditorWidget.init(self.editor) model = self.editor.layerStack self.layerWidget.init(model) self.UpButton.clicked.connect(model.moveSelectedUp) model.canMoveSelectedUp.connect(self.UpButton.setEnabled) self.DownButton.clicked.connect(model.moveSelectedDown) model.canMoveSelectedDown.connect(self.DownButton.setEnabled) self.DeleteButton.clicked.connect(model.deleteSelected) model.canDeleteSelected.connect(self.DeleteButton.setEnabled)
def _initPredictionLayers(self, predictionSlot): layers = [] colors = [] names = [] opLane = self.topLevelOperatorView if opLane.PmapColors.ready(): colors = opLane.PmapColors.value if opLane.LabelNames.ready(): names = opLane.LabelNames.value # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(predictionSlot) opSlicer.AxisFlag.setValue("c") colors = [QColor(*c) for c in colors] for channel in range(len(colors), len(opSlicer.Slices)): colors.append(PredictionViewerGui.DefaultColors[channel]) for channel in range(len(names), len(opSlicer.Slices)): names.append("Class {}".format(channel + 1)) for channel, channelSlot in enumerate(opSlicer.Slices): if channelSlot.ready( ) and channel < len(colors) and channel < len(names): predictsrc = createDataSource(channelSlot) predictLayer = AlphaModulatedLayer(predictsrc, tintColor=colors[channel], range=(0.0, 1.0), normalize=(0.0, 1.0)) predictLayer.opacity = 0.25 predictLayer.visible = True predictLayer.name = names[channel] layers.append(predictLayer) return layers return colors
def _initPredictionLayers(self, predictionSlot): layers = [] opLane = self.topLevelOperatorView if predictionSlot.ready( ) and self.topLevelOperatorView.UpperBound.ready(): upperBound = self.topLevelOperatorView.UpperBound.value layer = ColortableLayer(createDataSource(predictionSlot), colorTable=countingColorTable, normalize=(0, upperBound)) layer.name = "Density" layers.append(layer) # def _initPredictionLayers(self, predictionSlot): # layers = [] # # opLane = self.topLevelOperatorView # colors = opLane.PmapColors.value # names = opLane.LabelNames.value # # # Use a slicer to provide a separate slot for each channel layer # opSlicer = OpMultiArraySlicer2( parent=opLane.viewed_operator() ) # opSlicer.Input.connect( predictionSlot ) # opSlicer.AxisFlag.setValue('c') # # for channel, channelSlot in enumerate(opSlicer.Slices): # if channelSlot.ready() and channel < len(colors) and channel < len(names): # drange = channelSlot.meta.drange or (0.0, 1.0) # predictsrc = createDataSource(channelSlot) # predictLayer = AlphaModulatedLayer( predictsrc, # tintColor=QColor(*colors[channel]), # # FIXME: This is weird. Why are range and normalize both set to the same thing? # range=drange, # normalize=drange ) # predictLayer.opacity = 0.25 # predictLayer.visible = True # predictLayer.name = names[channel] # layers.append(predictLayer) return layers
def setupLayers(self): layers = [] opLane = self.topLevelOperatorView labelSlot = opLane.LabelImage if labelSlot.ready(): labelImageLayer = ColortableLayer(createDataSource(labelSlot), colorTable=self._colorTable16) labelImageLayer.name = "Label Image" labelImageLayer.visible = True layers.append(labelImageLayer) # If available, also show the raw data layer rawSlot = opLane.RawImage if rawSlot.ready(): rawLayer = self.createStandardLayerFromSlot(rawSlot) rawLayer.name = "Raw Data" rawLayer.visible = True rawLayer.opacity = 1.0 layers.append(rawLayer) return layers
def _initSegmentationLayers(self, segmentationSlot): opLane = self.topLevelOperatorView layers = [] # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(segmentationSlot) opSlicer.AxisFlag.setValue("c") for channel, segmentationSlot in enumerate(opSlicer.Slices): if segmentationSlot.ready(): segmentationSrc = createDataSource(segmentationSlot) segmentationLayer = AlphaModulatedLayer(segmentationSrc, range=(0.0, 1.0), normalize=(0.0, 1.0)) segmentationLayer.visible = ( channel == 1) # only show the channel with the foreground segmentationLayer.opacity = 1 def setSegmentationLayerName( n, segmentationLayer_=segmentationLayer, initializing=False): """ function for setting the names for every Channel """ if not initializing and segmentationLayer_ not in self.layerstack: # This layer has been removed from the layerstack already. # Don't touch it. return newName = "Segmentation of %s" % n segmentationLayer_.name = newName setSegmentationLayerName(channel, initializing=True) layers.append(segmentationLayer) return layers
def _initPredictionLayers(self, predictionSlot): opLane = self.topLevelOperatorView layers = [] # Use a slicer to provide a separate slot for each channel layer opSlicer = OpMultiArraySlicer2(parent=opLane.viewed_operator().parent) opSlicer.Input.connect(predictionSlot) opSlicer.AxisFlag.setValue('c') for channel, predictionSlot in enumerate(opSlicer.Slices): if predictionSlot.ready(): predictsrc = createDataSource(predictionSlot) predictLayer = AlphaModulatedLayer(predictsrc, range=(0.0, 1.0), normalize=(0.0, 1.0)) predictLayer.opacity = 0.25 predictLayer.visible = True def setPredLayerName(n, predictLayer_=predictLayer, initializing=False): """ function for setting the names for every Channel """ if not initializing and predictLayer_ not in self.layerstack: # This layer has been removed from the layerstack already. # Don't touch it. return newName = "Prediction for %s" % n predictLayer_.name = newName setPredLayerName(channel, initializing=True) layers.append(predictLayer) return layers
def do(): # Generate # array[:] = np.random.randint(0,255,500*500).reshape(shape).astype(np.uint8) a = np.zeros(500 * 500).reshape(500, 500).astype(np.uint8) ii = np.random.randint(0, 500, 1) jj = np.random.randint(0, 500, 1) a[ii, jj] = 1 a = vigra.filters.discDilation(a, radius=20) array[:] = a.reshape(shape).view(np.ndarray) * 255 op.Input.setDirty() do() cron.timeout.connect(do) ds = createDataSource(op.Output) layer = ColortableLayer(ds, jet()) mainwin = Viewer() mainwin.layerstack.append(layer) mainwin.dataShape = (1, h, w, 1, 1) print(mainwin.centralWidget()) BoxContr = BoxController(mainwin.editor, op.Output, boxListModel) BoxInt = BoxInterpreter(mainwin.editor.navInterpret, mainwin.editor.posModel, BoxContr, mainwin.centralWidget()) mainwin.editor.setNavigationInterpreter(BoxInt) # boxListModel.boxRemoved.connect(BoxContr.deleteItem) LV.show() mainwin.show()