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():        
            num_channels = predictionSlot.meta.getTaggedShape()['c']
            if num_channels != len(names) or num_channels != len(colors):
                names = map(lambda n: "Label {}".format(n), range(1, num_channels+1))
                colors = self._createDefault16ColorColorTable()[:num_channels]

        # 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 = LazyflowSource(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
Exemple #2
0
    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 = LazyflowSource(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 _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 = LazyflowSource(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
Exemple #4
0
    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 = LazyflowSource(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 _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