예제 #1
0
    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(LazyflowSource(watershedSlot), colortable)
            watershedLayer.name = "Watershed"
            watershedLayer.visible = False
            watershedLayer.opacity = 1.0
            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 )

        inputSlot = opLane.InputData
        if inputSlot.ready():
            inputLayer = self.createStandardLayerFromSlot( inputSlot )
            inputLayer.name = "Input Data"
            inputLayer.visible = True
            inputLayer.opacity = 1.0
            layers.append( inputLayer )

        ''' FIXME: disabled for 0.6 release
        rawSlot = opLane.RawData
        if rawSlot.ready():
            rawLayer = self.createStandardLayerFromSlot( rawSlot )
            rawLayer.name = "Raw Data"
            rawLayer.visible = True
            rawLayer.opacity = 1.0
            layers.append( rawLayer )
        '''

        return layers 
 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)
    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(LazyflowSource(watershedSlot), colortable)
            watershedLayer.name = "Watershed"
            watershedLayer.visible = False
            watershedLayer.opacity = 1.0
            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 )

        inputSlot = opLane.InputData
        if inputSlot.ready():
            inputLayer = self.createStandardLayerFromSlot( inputSlot )
            inputLayer.name = "Input Data"
            inputLayer.visible = True
            inputLayer.opacity = 1.0
            layers.append( inputLayer )

        ''' FIXME: disabled for 0.6 release
        rawSlot = opLane.RawData
        if rawSlot.ready():
            rawLayer = self.createStandardLayerFromSlot( rawSlot )
            rawLayer.name = "Raw Data"
            rawLayer.visible = True
            rawLayer.opacity = 1.0
            layers.append( rawLayer )
        '''

        return layers 
 def addFragmentSegmentationLayers(mslot, name):
     if mslot.ready():
         for index, slot in enumerate(mslot):
             if slot.ready():
                 raveler_label = slot.meta.selected_label
                 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())
                 colortable[0] = QColor(0,0,0,0).rgba()
                 fragSegLayer = ColortableLayer(LazyflowSource(slot), colortable, direct=True)
                 fragSegLayer.name = "{} #{} ({})".format( name, index, raveler_label )
                 fragSegLayer.visible = False
                 fragSegLayer.opacity = 1.0
                 layers.append(fragSegLayer)
    def setUp(self):
        if 'TRAVIS' in os.environ:
            # Colortable requests require vigra, which is not installed on our Travis-CI build.
            # Skip this test on Travis-CI.
            import nose
            raise nose.SkipTest

        super(ColortableImageSourceTest2, self).setUp()
        self.seg = numpy.zeros((6, 7), dtype=numpy.uint32)
        self.seg = numpy.ma.masked_array(self.seg,
                                         mask=numpy.zeros(self.seg.shape,
                                                          dtype=bool),
                                         shrink=False)
        self.seg[0:2, :] = 0
        self.seg[1, :] = numpy.ma.masked
        self.seg[2:4, :] = 1
        self.seg[3, :] = numpy.ma.masked
        self.seg[4:6, :] = 2
        self.seg[5, :] = numpy.ma.masked
        self.ars = _ArraySource2d(self.seg)
        self.ctable = [
            QColor(255, 0, 0).rgba(),
            QColor(0, 255, 0).rgba(),
            QColor(0, 0, 255).rgba()
        ]
        self.layer = ColortableLayer(self.ars, self.ctable)
        self.ims = ColortableImageSource(self.ars, self.layer)
예제 #6
0
    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)
예제 #7
0
    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)
예제 #8
0
 def addFragmentSegmentationLayers(mslot, name):
     if mslot.ready():
         for index, slot in enumerate(mslot):
             if slot.ready():
                 raveler_label = slot.meta.selected_label
                 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())
                 colortable[0] = QColor(0, 0, 0, 0).rgba()
                 fragSegLayer = ColortableLayer(LazyflowSource(slot),
                                                colortable,
                                                direct=True)
                 fragSegLayer.name = "{} #{} ({})".format(
                     name, index, raveler_label)
                 fragSegLayer.visible = False
                 fragSegLayer.opacity = 1.0
                 layers.append(fragSegLayer)
예제 #9
0
    def setupLayers( self ):        
        layers = []
        
        self.translationsrc = self.mainOperator.TranslationVectorsDisplay   
        translationLayer = self.createStandardLayerFromSlot( self.translationsrc )           
        translationLayer.name = "Translation Vector"
        translationLayer.opacity = 0.8
        translationLayer.visible = False
        layers.append(translationLayer)

        ct = colortables.create_default_8bit()
        ct[0] = QColor(0,0,0,0).rgba() # make 0 transparent
        ct[1] = QColor(0,255,0,255).rgba() # foreground is green
        self.warpedSrc = LazyflowSource( self.mainOperator.WarpedImage )
        warpedLayer = ColortableLayer( self.warpedSrc, ct )
        warpedLayer.name = "Translation Corrected Binary Image"
        warpedLayer.visible = False
        warpedLayer.opacity = 0.4
        layers.append(warpedLayer)


        ct = colortables.create_default_8bit()
        ct[0] = QColor(0,0,0,0).rgba() # make 0 transparent
        ct[1] = QColor(255,0,0,255).rgba() # foreground is read
        self.binarySrc = LazyflowSource( self.mainOperator.BinaryImage )
        binaryLayer = ColortableLayer( self.binarySrc, ct )
        binaryLayer.name = "Binary Image"
        binaryLayer.visible = True
        binaryLayer.opacity = 0.8
        layers.append(binaryLayer)
                
        ## raw data layer        
        self.rawsrc = LazyflowSource( self.mainOperator.RawImage )
        rawLayer = GrayscaleLayer( self.rawsrc )
        rawLayer.name = "Raw Image"        
        layers.insert( len(layers), rawLayer )   
        
        
        if self.topLevelOperatorView.TranslationVectors.meta.shape:
            self.editor.dataShape = self.topLevelOperatorView.TranslationVectors.meta.shape    
        
        self.topLevelOperatorView.RawImage.notifyReady( self._onReady )
        self.topLevelOperatorView.RawImage.notifyMetaChanged( self._onMetaChanged ) 
        
        self._onParametersChanged()        
        self._drawer.methodBox.currentIndexChanged.connect(self._onMethodChanged)
        self._drawer.templateSizeBox.valueChanged.connect(self._onMethodChanged)
        self._drawer.maxTranslationBox.valueChanged.connect(self._onMethodChanged)
        self._drawer.maxDiffValsBox.valueChanged.connect(self._onMethodChanged)
                
        return layers
예제 #10
0
 def setUp(self):
     self.seg = numpy.zeros((6, 7), dtype=numpy.uint32)
     self.seg[0:2, :] = 0
     self.seg[2:4, :] = 1
     self.seg[4:6, :] = 2
     self.ars = _ArraySource2d(self.seg)
     self.ctable = [
         QColor(255, 0, 0).rgba(),
         QColor(0, 255, 0).rgba(),
         QColor(0, 0, 255).rgba()
     ]
     self.layer = ColortableLayer(self.ars, self.ctable)
     self.ims = ColortableImageSource(self.ars, self.layer)
예제 #11
0
 def add_layer_from_datasource(self,
                               source,
                               name=None,
                               colortable=None,
                               direct=False):
     if colortable is None:
         colortable = self._randomColors()
     self._overlay_layer = ColortableLayer(source,
                                           colortable,
                                           direct=direct)
     if name:
         self._overlay_layer.name = name
     self.layerstack.append(self._overlay_layer)
     return self._overlay_layer
예제 #12
0
    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
예제 #13
0
    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(LazyflowSource(watershedSlot), colortable)
            watershedLayer.name = "Watershed"
            watershedLayer.visible = False
            watershedLayer.opacity = 1.0
            layers.append(watershedLayer)


        filteredSlot = opLane.FilteredImage
        if filteredSlot.ready():
            filteredLayer = self.createStandardLayerFromSlot( filteredSlot )
            filteredLayer.name = "Filtered Data"
            filteredLayer.visible = False
            filteredLayer.opacity = 1.0
            layers.append( filteredLayer )

        # Raw data        
        rawSlot = opLane.RawData
        if rawSlot.ready():
            rawLayer = self.createStandardLayerFromSlot( rawSlot )
            rawLayer.name = "Raw Data"
            rawLayer.visible = True
            rawLayer.opacity = 1.0
            layers.append( rawLayer )

        return layers 
예제 #14
0
    def setUp(self):
        if "TRAVIS" in os.environ:
            # Colortable requests require vigra, which is not installed on our Travis-CI build.
            # Skip this test on Travis-CI.
            import nose

            raise nose.SkipTest

        super(ColortableImageSourceTest, self).setUp()
        self.seg = numpy.zeros((6, 7), dtype=numpy.uint32)
        self.seg[0:2, :] = 0
        self.seg[2:4, :] = 1
        self.seg[4:6, :] = 2
        self.ars = _ArraySource2d(self.seg)
        self.ctable = [QColor(255, 0, 0).rgba(), QColor(0, 255, 0).rgba(), QColor(0, 0, 255).rgba()]
        self.layer = ColortableLayer(self.ars, self.ctable)
        self.ims = ColortableImageSource(self.ars, self.layer)
예제 #15
0
 def setUp(self):
     super(ColortableImageSourceTest2, self).setUp()
     self.seg = numpy.zeros((6, 7), dtype=numpy.uint32)
     self.seg = numpy.ma.masked_array(self.seg,
                                      mask=numpy.zeros(self.seg.shape,
                                                       dtype=bool),
                                      shrink=False)
     self.seg[0:2, :] = 0
     self.seg[1, :] = numpy.ma.masked
     self.seg[2:4, :] = 1
     self.seg[3, :] = numpy.ma.masked
     self.seg[4:6, :] = 2
     self.seg[5, :] = numpy.ma.masked
     self.ars = _ArraySource2d(self.seg)
     self.ctable = [
         QColor(255, 0, 0).rgba(),
         QColor(0, 255, 0).rgba(),
         QColor(0, 0, 255).rgba()
     ]
     self.layer = ColortableLayer(self.ars, self.ctable)
     self.ims = ColortableImageSource(self.ars, self.layer)
예제 #16
0
    def setupLayers( self ):
        logger.debug( "setupLayers" )
        
        layers = []

        def onButtonsEnabled(slot, roi):
            currObj = self.topLevelOperatorView.CurrentObjectName.value
            hasSeg  = self.topLevelOperatorView.HasSegmentation.value
            
            self.labelingDrawerUi.currentObjectLabel.setText(currObj)
            self.labelingDrawerUi.save.setEnabled(hasSeg)

        self.topLevelOperatorView.CurrentObjectName.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.HasSegmentation.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opLabelArray.NonzeroBlocks.notifyDirty(onButtonsEnabled)
        
        # Labels
        labellayer, labelsrc = self.createLabelLayer(direct=True)
        if labellayer is not None:
            labellayer._allowToggleVisible = False
            layers.append(labellayer)
            # Tell the editor where to draw label data
            self.editor.setLabelSink(labelsrc)

        #uncertainty
        #if self._showUncertaintyLayer:
        #    uncert = self.topLevelOperatorView.Uncertainty
        #    if uncert.ready():
        #        colortable = []
        #        for i in range(256-len(colortable)):
        #            r,g,b,a = i,0,0,i
        #            colortable.append(QColor(r,g,b,a).rgba())
        #        layer = ColortableLayer(LazyflowSource(uncert), colortable, direct=True)
        #        layer.name = "Uncertainty"
        #        layer.visible = True
        #        layer.opacity = 0.3
        #        layers.append(layer)
       
        #segmentation 
        seg = self.topLevelOperatorView.Segmentation
        
        #seg = self.topLevelOperatorView.MST.value.segmentation
        #temp = self._done_lut[self.MST.value.supervoxelUint32[sl[1:4]]]
        if seg.ready():
            #source = RelabelingArraySource(seg)
            #source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
            for i in range(256-len(colortable)):
                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())

            layer = ColortableLayer(LazyflowSource(seg), colortable, direct=True)
            layer.name = "Segmentation"
            layer.setToolTip("This layer displays the <i>current</i> segmentation. Simply add foreground and background " \
                             "labels, then press <i>Segment</i>.")
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)
        
        #done 
        done = self.topLevelOperatorView.DoneObjects
        if done.ready(): 
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,255).rgba()]
            #have to use lazyflow because it provides dirty signals
            layer = ColortableLayer(LazyflowSource(done), colortable, direct=True)
            layer.name = "Completed segments (unicolor)"
            layer.setToolTip("In order to keep track of which objects you have already completed, this layer " \
                             "shows <b>all completed object</b> in one color (<b>blue</b>). " \
                             "The reason for only one color is that for finding out which " \
                              "objects to label next, the identity of already completed objects is unimportant " \
                              "and destracting.")
            layer.visible = False
            layer.opacity = 0.5
            layers.append(layer)

        #done seg
        doneSeg = self.topLevelOperatorView.DoneSegmentation
        if doneSeg.ready():
            layer = ColortableLayer(LazyflowSource(doneSeg), self._doneSegmentationColortable, direct=True)
            layer.name = "Completed segments (one color per object)"
            layer.setToolTip("<html>In order to keep track of which objects you have already completed, this layer " \
                             "shows <b>all completed object</b>, each with a random color.</html>")
            layer.visible = False
            layer.opacity = 0.5
            self._doneSegmentationLayer = layer
            layers.append(layer)

        #supervoxel
        sv = self.topLevelOperatorView.Supervoxels
        if sv.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())
            layer = ColortableLayer(LazyflowSource(sv), colortable, direct=True)
            layer.name = "Supervoxels"
            layer.setToolTip("<html>This layer shows the partitioning of the input image into <b>supervoxels</b>. The carving " \
                             "algorithm uses these tiny puzzle-piceces to piece together the segmentation of an " \
                             "object. Sometimes, supervoxels are too large and straddle two distinct objects " \
                             "(undersegmentation). In this case, it will be impossible to achieve the desired " \
                             "segmentation. This layer helps you to understand these cases.</html>")
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        # Visual overlay (just for easier labeling)
        overlaySlot = self.topLevelOperatorView.OverlayData
        if overlaySlot.ready():
            overlay5D = self.topLevelOperatorView.OverlayData.value
            layer = GrayscaleLayer(ArraySource(overlay5D), direct=True)
            layer.visible = True
            layer.name = 'Overlay'
            layer.opacity = 1.0
            # if the flag window_leveling is set the contrast 
            # of the layer is adjustable
            layer.window_leveling = True
            self.labelingDrawerUi.thresToolButton.show()
            layers.append(layer)
            del layer

        inputSlot = self.topLevelOperatorView.InputData
        if inputSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(inputSlot), direct=True )
            layer.name = "Input Data"
            layer.setToolTip("<html>The data originally loaded into ilastik (unprocessed).</html>")
            #layer.visible = not rawSlot.ready()
            layer.visible = True
            layer.opacity = 1.0

            # Window leveling is already active on the Overlay,
            # but if no overlay was provided, then activate window_leveling on the raw data instead.
            if not overlaySlot.ready():
                # if the flag window_leveling is set the contrast 
                # of the layer is adjustable
                layer.window_leveling = True
                self.labelingDrawerUi.thresToolButton.show()

            layers.append(layer)
            del layer

        filteredSlot = self.topLevelOperatorView.FilteredInputData
        if filteredSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(filteredSlot) )
            layer.name = "Filtered Input"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        return layers
예제 #17
0
    def setupLayers(self):
        def findLayer(f, layerlist):
            for l in layerlist:
                if f(l):
                    return l
            return None

        layers = []
        baseCarvingLayers = super(SplitBodyCarvingGui, self).setupLayers()

        crosshairSlot = self.topLevelOperatorView.AnnotationCrosshairs
        if crosshairSlot.ready():
            # 0=Transparent, 1=pink
            colortable = [
                QColor(0, 0, 0, 0).rgba(),
                QColor(236, 184, 201).rgba()
            ]
            crosshairLayer = ColortableLayer(LazyflowSource(crosshairSlot),
                                             colortable,
                                             direct=True)
            crosshairLayer.name = "Annotation Points"
            crosshairLayer.visible = True
            crosshairLayer.opacity = 1.0
            layers.append(crosshairLayer)

        highlightedObjectSlot = self.topLevelOperatorView.CurrentRavelerObject
        if highlightedObjectSlot.ready():
            # 0=Transparent, 1=blue
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(0, 0, 255).rgba()]
            highlightedObjectLayer = ColortableLayer(
                LazyflowSource(highlightedObjectSlot), colortable, direct=True)
            highlightedObjectLayer.name = "Current Raveler Object"
            highlightedObjectLayer.visible = False
            highlightedObjectLayer.opacity = 0.25
            layers.append(highlightedObjectLayer)

        remainingRavelerObjectSlot = self.topLevelOperatorView.CurrentRavelerObjectRemainder
        if remainingRavelerObjectSlot.ready():
            # 0=Transparent, 1=blue
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(255, 0, 0).rgba()]
            remainingObjectLayer = ColortableLayer(
                LazyflowSource(remainingRavelerObjectSlot),
                colortable,
                direct=True)
            remainingObjectLayer.name = "Remaining Raveler Object"
            remainingObjectLayer.visible = True
            remainingObjectLayer.opacity = 0.25
            layers.append(remainingObjectLayer)

        fragmentSegSlot = self.topLevelOperatorView.CurrentFragmentSegmentation
        if fragmentSegSlot.ready():
            colortable = map(QColor.rgba, self._fragmentColors)
            fragSegLayer = ColortableLayer(LazyflowSource(fragmentSegSlot),
                                           colortable,
                                           direct=True)
            fragSegLayer.name = "Saved Fragments"
            fragSegLayer.visible = True
            fragSegLayer.opacity = 0.25
            layers.append(fragSegLayer)

        ravelerLabelsSlot = self.topLevelOperatorView.RavelerLabels
        if ravelerLabelsSlot.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())
            ravelerLabelLayer = ColortableLayer(
                LazyflowSource(ravelerLabelsSlot), colortable, direct=True)
            ravelerLabelLayer.name = "Raveler Labels"
            ravelerLabelLayer.visible = False
            ravelerLabelLayer.opacity = 0.4
            layers.append(ravelerLabelLayer)

        maskedSegSlot = self.topLevelOperatorView.MaskedSegmentation
        if maskedSegSlot.ready():
            colortable = [
                QColor(0, 0, 0, 0).rgba(),
                QColor(0, 0, 0, 0).rgba(),
                QColor(0, 255, 0).rgba()
            ]
            maskedSegLayer = ColortableLayer(LazyflowSource(maskedSegSlot),
                                             colortable,
                                             direct=True)
            maskedSegLayer.name = "Masked Segmentation"
            maskedSegLayer.visible = True
            maskedSegLayer.opacity = 0.3
            layers.append(maskedSegLayer)

            # Hide the original carving segmentation.
            # TODO: Remove it from the list altogether?
            carvingSeg = findLayer(lambda l: l.name == "segmentation",
                                   baseCarvingLayers)
            if carvingSeg is not None:
                carvingSeg.visible = False

        def removeBaseLayer(layerName):
            layer = findLayer(lambda l: l.name == layerName, baseCarvingLayers)
            if layer:
                baseCarvingLayers.remove(layer)

        # Don't show carving layers that aren't relevant to the split-body workflow
        removeBaseLayer("Uncertainty")
        removeBaseLayer("Segmentation")
        removeBaseLayer("Completed segments (unicolor)")
        #removeBaseLayer( "pmap" )
        #removeBaseLayer( "hints" )
        #removeBaseLayer( "done" )
        #removeBaseLayer( "done" )

        ActionInfo = ShortcutManager.ActionInfo

        # Attach a shortcut to the raw data layer
        if self.topLevelOperatorView.RawData.ready():
            rawLayer = findLayer(lambda l: l.name == "Raw Data",
                                 baseCarvingLayers)
            assert rawLayer is not None, "Couldn't find the raw data layer.  Did it's name change?"
            rawLayer.shortcutRegistration = (
                "f",
                ActionInfo("Carving", "Raw Data to Top", "Raw Data to Top",
                           partial(self._toggleRawDataPosition, rawLayer),
                           self.viewerControlWidget(), rawLayer))
        layers += baseCarvingLayers
        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
예제 #19
0
data_arr = (255 * numpy.random.random(SHAPE)).astype(numpy.uint8)
label_arr = numpy.zeros(SHAPE, dtype=numpy.uint8)

##-----
app = QApplication(sys.argv)
v = Viewer()

data_src = ArraySource(data_arr)
data_layer = GrayscaleLayer(data_src)
data_layer.name = "Raw"
data_layer.numberOfChannels = 1

label_src = ArraySinkSource(label_arr)
label_layer = ColortableLayer(label_src,
                              colorTable=default16_new,
                              direct=False)
label_layer.name = "Labels"
label_layer.ref_object = None

assert SHAPE == label_arr.shape == data_arr.shape
v.dataShape = SHAPE

v.layerstack.append(data_layer)
v.layerstack.append(label_layer)

v.editor.setLabelSink(label_src)
v.editor.setInteractionMode("brushing")

v.setWindowTitle("labeling")
v.showMaximized()
    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)

        supervoxelsSlot = op.Supervoxels
        if supervoxelsSlot.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())
            supervoxelsLayer = ColortableLayer(LazyflowSource(supervoxelsSlot), colortable)
            supervoxelsLayer.name = "Input Supervoxels"
            supervoxelsLayer.visible = False
            supervoxelsLayer.opacity = 1.0
            layers.append(supervoxelsLayer)

        def addFragmentSegmentationLayers(mslot, name):
            if mslot.ready():
                for index, slot in enumerate(mslot):
                    if slot.ready():
                        raveler_label = slot.meta.selected_label
                        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())
                        colortable[0] = QColor(0,0,0,0).rgba()
                        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.MaskedSupervoxels, "Masked Supervoxels" )
        addFragmentSegmentationLayers( op.FilteredMaskedSupervoxels, "Filtered Masked Supervoxels" )
        addFragmentSegmentationLayers( op.HoleFilledSupervoxels, "Hole Filled Supervoxels" )
        addFragmentSegmentationLayers( op.RelabeledSupervoxels, "Relabeled Supervoxels" )

        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.FinalSupervoxels
        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)
            finalLayer.name = "Final Supervoxels"
            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
        if rawSlot.ready():
            raw5D = self.topLevelOperatorView.RawData.value
            layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
            #layer = GrayscaleLayer( LazyflowSource(rawSlot) )
            layer.name = "raw"
            layer.visible = True
            layer.opacity = 1.0
            layers.append(layer)

        return layers
예제 #21
0
    def setupLayers(self):
        def findLayer(f, layerlist):
            for l in layerlist:
                if f(l):
                    return l
            return None

        layers = []
        baseCarvingLayers = super(SplitBodyCarvingGui, self).setupLayers()        
        
        crosshairSlot = self.topLevelOperatorView.AnnotationCrosshairs
        if crosshairSlot.ready():
            # 0=Transparent, 1=pink
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(236, 184, 201).rgba()]
            crosshairLayer = ColortableLayer(LazyflowSource(crosshairSlot), colortable, direct=True)
            crosshairLayer.name = "Annotation Points"
            crosshairLayer.visible = True
            crosshairLayer.opacity = 1.0
            layers.append(crosshairLayer)
        
        
        highlightedObjectSlot = self.topLevelOperatorView.CurrentRavelerObject
        if highlightedObjectSlot.ready():
            # 0=Transparent, 1=blue
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(0, 0, 255).rgba()]
            highlightedObjectLayer = ColortableLayer(LazyflowSource(highlightedObjectSlot), colortable, direct=True)
            highlightedObjectLayer.name = "Current Raveler Object"
            highlightedObjectLayer.visible = False
            highlightedObjectLayer.opacity = 0.25
            layers.append(highlightedObjectLayer)

        remainingRavelerObjectSlot = self.topLevelOperatorView.CurrentRavelerObjectRemainder
        if remainingRavelerObjectSlot.ready():
            # 0=Transparent, 1=blue
            colortable = [QColor(0, 0, 0, 0).rgba(), QColor(255, 0, 0).rgba()]
            remainingObjectLayer = ColortableLayer(LazyflowSource(remainingRavelerObjectSlot), colortable, direct=True)
            remainingObjectLayer.name = "Remaining Raveler Object"
            remainingObjectLayer.visible = True
            remainingObjectLayer.opacity = 0.25
            layers.append(remainingObjectLayer)

        fragmentSegSlot = self.topLevelOperatorView.CurrentFragmentSegmentation
        if fragmentSegSlot.ready():
            colortable = map(QColor.rgba, self._fragmentColors)
            fragSegLayer = ColortableLayer(LazyflowSource(fragmentSegSlot), colortable, direct=True)
            fragSegLayer.name = "Saved Fragments"
            fragSegLayer.visible = True
            fragSegLayer.opacity = 0.25
            layers.append(fragSegLayer)

        ravelerLabelsSlot = self.topLevelOperatorView.RavelerLabels
        if ravelerLabelsSlot.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())
            ravelerLabelLayer = ColortableLayer(LazyflowSource(ravelerLabelsSlot), colortable, direct=True)
            ravelerLabelLayer.name = "Raveler Labels"
            ravelerLabelLayer.visible = False
            ravelerLabelLayer.opacity = 0.4
            layers.append(ravelerLabelLayer)

        maskedSegSlot = self.topLevelOperatorView.MaskedSegmentation
        if maskedSegSlot.ready():
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
            maskedSegLayer = ColortableLayer(LazyflowSource(maskedSegSlot), colortable, direct=True)
            maskedSegLayer.name = "Masked Segmentation"
            maskedSegLayer.visible = True
            maskedSegLayer.opacity = 0.3
            layers.append(maskedSegLayer)
            
            # Hide the original carving segmentation.
            # TODO: Remove it from the list altogether?
            carvingSeg = findLayer( lambda l: l.name == "segmentation", baseCarvingLayers )
            if carvingSeg is not None:
                carvingSeg.visible = False

        def removeBaseLayer(layerName):
            layer = findLayer(lambda l: l.name == layerName, baseCarvingLayers)
            if layer:
                baseCarvingLayers.remove(layer)

        # Don't show carving layers that aren't relevant to the split-body workflow
        removeBaseLayer( "uncertainty" )
        removeBaseLayer( "done seg" )
        removeBaseLayer( "pmap" )
        removeBaseLayer( "hints" )
        removeBaseLayer( "done" )
        removeBaseLayer( "done" )
        
        # Attach a shortcut to the raw data layer
        if self.topLevelOperatorView.RawData.ready():
            rawLayer = findLayer(lambda l: l.name == "raw", baseCarvingLayers)
            assert rawLayer is not None, "Couldn't find the raw data layer.  Did it's name change?"
            rawLayer.shortcutRegistration = ( "Carving",
                                              "Raw Data to Top",
                                              QShortcut( QKeySequence("f"),
                                                         self.viewerControlWidget(),
                                                         partial(self._toggleRawDataPosition, rawLayer) ),
                                             rawLayer )
        layers += baseCarvingLayers
        return layers
예제 #22
0
 def setupLayers( self, currentImageIndex ):
     layers = []
    
     def onButtonsEnabled(slot, roi):
         currObj = self._carvingApplet.topLevelOperator.opCarving[currentImageIndex].CurrentObjectName.value
         hasSeg  = self._carvingApplet.topLevelOperator.opCarving[currentImageIndex].HasSegmentation.value
         nzLB    = self._carvingApplet.topLevelOperator.opLabeling.NonzeroLabelBlocks[currentImageIndex][:].wait()[0]
         
         self.labelingDrawerUi.currentObjectLabel.setText("current object: %s" % currObj)
         self.labelingDrawerUi.save.setEnabled(currObj != "" and hasSeg)
         self.labelingDrawerUi.saveAs.setEnabled(currObj == "" and hasSeg)
         #rethink this
         #self.labelingDrawerUi.segment.setEnabled(len(nzLB) > 0)
         #self.labelingDrawerUi.clear.setEnabled(len(nzLB) > 0)
     self._carvingApplet.topLevelOperator.opCarving[currentImageIndex].CurrentObjectName.notifyDirty(onButtonsEnabled)
     self._carvingApplet.topLevelOperator.opCarving[currentImageIndex].HasSegmentation.notifyDirty(onButtonsEnabled)
     self._carvingApplet.topLevelOperator.opLabeling.NonzeroLabelBlocks[currentImageIndex].notifyDirty(onButtonsEnabled)
     
     # Labels
     labellayer, labelsrc = self.createLabelLayer(currentImageIndex, direct=True)
     if labellayer is not None:
         layers.append(labellayer)
         # Tell the editor where to draw label data
         self.editor.setLabelSink(labelsrc)
    
     #segmentation 
     seg = self._carvingApplet.topLevelOperator.opCarving.Segmentation[currentImageIndex]
     
     #seg = self._carvingApplet.topLevelOperator.opCarving[0]._mst.segmentation
     #temp = self._done_lut[self._mst.regionVol[sl[1:4]]]
     if seg.ready(): 
         #source = RelabelingArraySource(seg)
         #source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))
         colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
         for i in range(256-len(colortable)):
             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())
             
         #layer = DirectColorTableLayer(seg, colortable, lazyflow=True)
         layer = ColortableLayer(LazyflowSource(seg), colortable, direct=True)
         layer.name = "segmentation"
         layer.visible = True
         layer.opacity = 0.3
         layers.append(layer)
     
     #done 
     done = self._carvingApplet.topLevelOperator.opCarving.DoneObjects[currentImageIndex]
     if done.ready(): 
         colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,255).rgba()]
         for i in range(254-len(colortable)):
             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())
         #have to use lazyflow because it provides dirty signals
         #layer = DirectColorTableLayer(done, colortable, lazyflow=True)
         layer = ColortableLayer(LazyflowSource(done), colortable, direct=True)
         layer.name = "done"
         layer.visible = False
         layer.opacity = 0.5
         layers.append(layer)
         
     doneSeg = self._carvingApplet.topLevelOperator.opCarving.DoneSegmentation[currentImageIndex]
     if doneSeg.ready(): 
         layer = ColortableLayer(LazyflowSource(doneSeg), self._doneSegmentationColortable, direct=True)
         layer.name = "done seg"
         layer.visible = False
         layer.opacity = 0.5
         self._doneSegmentationLayer = layer
         layers.append(layer)
         
     #supervoxel
     sv = self._carvingApplet.topLevelOperator.opCarving.Supervoxels[currentImageIndex]
     if sv.ready():
         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())
         #layer = DirectColorTableLayer(sv, colortable, lazyflow=True)
         layer = ColortableLayer(LazyflowSource(sv), colortable, direct=True)
         layer.name = "supervoxels"
         layer.visible = False
         layer.opacity = 1.0
         layers.append(layer)
     
     #
     # load additional layer: features / probability map
     #
     import h5py
     f = h5py.File("pmap.h5")
     pmap = f["data"].value
     
     #
     # here we load the actual raw data from an ArraySource rather than from a LazyflowSource for speed reasons
     #
     raw = self._carvingApplet.topLevelOperator.opCarving[0]._mst.raw
     raw5D = numpy.zeros((1,)+raw.shape+(1,), dtype=raw.dtype)
     raw5D[0,:,:,:,0] = raw[:,:,:]
     #layer = DirectGrayscaleLayer(raw5D)
     layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
     layer.name = "raw"
     layer.visible = True
     layer.opacity = 1.0
     #layers.insert(1, layer)
     layers.append(layer)
         
     return layers
예제 #23
0
    def setupLayers(self):
        logger.debug("setupLayers")

        layers = []

        def onButtonsEnabled(slot, roi):
            currObj = self.topLevelOperatorView.CurrentObjectName.value
            hasSeg = self.topLevelOperatorView.HasSegmentation.value

            self.labelingDrawerUi.currentObjectLabel.setText(currObj)
            self.labelingDrawerUi.save.setEnabled(hasSeg)

        self.topLevelOperatorView.CurrentObjectName.notifyDirty(
            onButtonsEnabled)
        self.topLevelOperatorView.HasSegmentation.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opLabelArray.NonzeroBlocks.notifyDirty(
            onButtonsEnabled)

        # Labels
        labellayer, labelsrc = self.createLabelLayer(direct=True)
        if labellayer is not None:
            labellayer._allowToggleVisible = False
            layers.append(labellayer)
            # Tell the editor where to draw label data
            self.editor.setLabelSink(labelsrc)

        # uncertainty
        # if self._showUncertaintyLayer:
        #    uncert = self.topLevelOperatorView.Uncertainty
        #    if uncert.ready():
        #        colortable = []
        #        for i in range(256-len(colortable)):
        #            r,g,b,a = i,0,0,i
        #            colortable.append(QColor(r,g,b,a).rgba())
        #        layer = ColortableLayer(createDataSource(uncert), colortable, direct=True)
        #        layer.name = "Uncertainty"
        #        layer.visible = True
        #        layer.opacity = 0.3
        #        layers.append(layer)

        # segmentation
        seg = self.topLevelOperatorView.Segmentation

        # seg = self.topLevelOperatorView.MST.value.segmentation
        # temp = self._done_lut[self.MST.value.supervoxelUint32[sl[1:4]]]
        if seg.ready():
            # source = RelabelingArraySource(seg)
            # source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))

            # assign to the object label color, 0 is transparent, 1 is background
            colortable = [
                QColor(0, 0, 0, 0).rgba(),
                QColor(0, 0, 0, 0).rgba(), labellayer._colorTable[2]
            ]
            for i in range(256 - len(colortable)):
                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())

            layer = ColortableLayer(createDataSource(seg),
                                    colortable,
                                    direct=True)
            layer.name = "Segmentation"
            layer.setToolTip(
                "This layer displays the <i>current</i> segmentation. Simply add foreground and background "
                "labels, then press <i>Segment</i>.")
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)

        # done
        doneSeg = self.topLevelOperatorView.DoneSegmentation
        if doneSeg.ready():
            # FIXME: if the user segments more than 255 objects, those with indices that divide by 255 will be shown as transparent
            # both here and in the _doneSegmentationColortable
            colortable = 254 * [QColor(230, 25, 75).rgba()]
            colortable.insert(0, QColor(0, 0, 0, 0).rgba())

            # have to use lazyflow because it provides dirty signals
            layer = ColortableLayer(createDataSource(doneSeg),
                                    colortable,
                                    direct=True)
            layer.name = "Completed segments (unicolor)"
            layer.setToolTip(
                "In order to keep track of which objects you have already completed, this layer "
                "shows <b>all completed object</b> in one color (<b>blue</b>). "
                "The reason for only one color is that for finding out which "
                "objects to label next, the identity of already completed objects is unimportant "
                "and destracting.")
            layer.visible = False
            layer.opacity = 0.5
            layers.append(layer)

            layer = ColortableLayer(createDataSource(doneSeg),
                                    self._doneSegmentationColortable,
                                    direct=True)
            layer.name = "Completed segments (one color per object)"
            layer.setToolTip(
                "<html>In order to keep track of which objects you have already completed, this layer "
                "shows <b>all completed object</b>, each with a random color.</html>"
            )
            layer.visible = False
            layer.opacity = 0.5
            layer.colortableIsRandom = True
            self._doneSegmentationLayer = layer
            layers.append(layer)

        # supervoxel
        sv = self.topLevelOperatorView.Supervoxels
        if sv.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())
            layer = ColortableLayer(createDataSource(sv),
                                    colortable,
                                    direct=True)
            layer.name = "Supervoxels"
            layer.setToolTip(
                "<html>This layer shows the partitioning of the input image into <b>supervoxels</b>. The carving "
                "algorithm uses these tiny puzzle-piceces to piece together the segmentation of an "
                "object. Sometimes, supervoxels are too large and straddle two distinct objects "
                "(undersegmentation). In this case, it will be impossible to achieve the desired "
                "segmentation. This layer helps you to understand these cases.</html>"
            )
            layer.visible = False
            layer.colortableIsRandom = True
            layer.opacity = 0.5
            layers.append(layer)

        # Visual overlay (just for easier labeling)
        overlaySlot = self.topLevelOperatorView.OverlayData
        if overlaySlot.ready():
            overlay5D = self.topLevelOperatorView.OverlayData.value
            layer = GrayscaleLayer(ArraySource(overlay5D), direct=True)
            layer.visible = True
            layer.name = "Overlay"
            layer.opacity = 1.0
            # if the flag window_leveling is set the contrast
            # of the layer is adjustable
            layer.window_leveling = True
            self.labelingDrawerUi.thresToolButton.show()
            layers.append(layer)
            del layer

        inputSlot = self.topLevelOperatorView.InputData
        if inputSlot.ready():
            layer = GrayscaleLayer(createDataSource(inputSlot), direct=True)
            layer.name = "Input Data"
            layer.setToolTip(
                "<html>The data originally loaded into ilastik (unprocessed).</html>"
            )
            # layer.visible = not rawSlot.ready()
            layer.visible = True
            layer.opacity = 1.0

            # Window leveling is already active on the Overlay,
            # but if no overlay was provided, then activate window_leveling on the raw data instead.
            if not overlaySlot.ready():
                # if the flag window_leveling is set the contrast
                # of the layer is adjustable
                layer.window_leveling = True
                self.labelingDrawerUi.thresToolButton.show()

            layers.append(layer)
            del layer

        filteredSlot = self.topLevelOperatorView.FilteredInputData
        if filteredSlot.ready():
            layer = GrayscaleLayer(createDataSource(filteredSlot))
            layer.name = "Filtered Input"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        return layers
예제 #24
0
def showStuff(raw_name,
              pred_viewer1,
              pred_viewer2,
              cutout_name,
              one_extra=None):
    # display the raw and annotations for cremi challenge data
    raw = vigra.impex.readHDF5(indir + datasets[raw_name], "data", order='C')
    # raw_old = vigra.readHDF5(indir+datasets["raw_bad"], "data", order = 'C')
    defect_prediction_128 = vigra.impex.readHDF5(indir +
                                                 datasets[pred_viewer2],
                                                 "data",
                                                 order='C')
    defect_prediction_150 = vigra.impex.readHDF5(indir +
                                                 datasets[pred_viewer1],
                                                 "data",
                                                 order='C')
    cutout_from_150_pred = vigra.impex.readHDF5(indir + datasets[cutout_name],
                                                "data",
                                                order='C')

    ####################################################################################################################
    # only used for fast testing stuff
    #change_one = vigra.readHDF5(indir+datasets["segmentation_on_equalized_image"], "data", order = 'C')
    #pdb.set_trace()
    #defect_prediction_150[1,:,:] = change_one[0,:,:,0]
    ####################################################################################################################
    # defect_prediction_150 = gt[..., 0]
    cutout = numpy.asarray(cutout_from_150_pred)
    rawdata = numpy.asarray(raw)
    # rawdata_old = numpy.asarray(raw_old)
    # op5ify
    # shape5d = rawdata.shape
    shape5d = (1, ) + rawdata.shape + (1, )
    print shape5d, rawdata.shape, rawdata.dtype

    app = QApplication([])
    v = Viewer()
    direct = False

    # layer for raw data
    rawdata = numpy.reshape(rawdata, shape5d)
    rawsource = ArraySource(rawdata)
    v.dataShape = shape5d
    lraw = GrayscaleLayer(rawsource, direct=direct)
    lraw.visible = True
    lraw.name = "raw"
    v.layerstack.append(lraw)

    # layer for cutout regions from raw data
    cutout = numpy.reshape(cutout, shape5d)
    cutoutsource = ArraySource(cutout)
    lcutout = GrayscaleLayer(cutoutsource, direct=direct)
    lcutout.visible = False
    lcutout.name = "cut_out"
    v.layerstack.append(lcutout)

    # layer for first prediction result
    defect_prediction_128 = numpy.reshape(defect_prediction_128, shape5d)
    synsource = ArraySource(defect_prediction_128)
    ct = create_random_16bit()
    ct[0] = 0
    lsyn = ColortableLayer(synsource, ct)
    lsyn.name = pred_viewer2
    lsyn.visible = False
    v.layerstack.append(lsyn)

    # layer for second prediction result
    segm = numpy.reshape(defect_prediction_150, shape5d)
    segsource = ArraySource(segm)
    ct = create_random_16bit()
    ct[0] = 0
    lseg = ColortableLayer(segsource, ct)
    lseg.name = pred_viewer1
    lseg.visible = False
    v.layerstack.append(lseg)
    if one_extra is None:
        v.showMaximized()
        app.exec_()

    if one_extra is not None:
        # layer for third prediction result
        extra_prediction = vigra.readHDF5(indir + datasets[one_extra],
                                          "data",
                                          order='C')
        extra_pred_reshaped = numpy.reshape(extra_prediction, shape5d)
        segsource = ArraySource(extra_pred_reshaped)
        ct = create_random_16bit()
        ct[0] = 0
        # ct = create_default_16bit()
        lseg = ColortableLayer(segsource, ct)
        lseg.name = one_extra
        lseg.visible = False
        v.layerstack.append(lseg)
        v.showMaximized()
        app.exec_()
예제 #25
0
    def setupLayers(self):
        layers = []
        op = self.topLevelOperatorView

        # Superpixels
        if op.Superpixels.ready():
            layer = ColortableLayer(LazyflowSource(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 op.debug_results.items():
                axiskeys = op.Superpixels.meta.getAxisKeys(
                )[:-1]  # debug images don't have a channel axis
                permutation = map(
                    lambda key: axiskeys.index(key)
                    if key in axiskeys else None, '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(LazyflowSource(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 = "Input"
            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
예제 #26
0
    def setupLayers(self):
        layers = []
        op = self.topLevelOperatorView

        # Superpixels
        if op.Superpixels.ready():
            layer = ColortableLayer( LazyflowSource(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 op.debug_results.items():
                axiskeys = op.Superpixels.meta.getAxisKeys()[:-1] # debug images don't have a channel axis
                permutation = map(lambda key: axiskeys.index(key) if key in axiskeys else None, '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( LazyflowSource(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 = "Input"
            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
예제 #27
0
    def setupLayers( self ):
        layers = []

        def onButtonsEnabled(slot, roi):
            currObj = self.topLevelOperatorView.opCarving.CurrentObjectName.value
            hasSeg  = self.topLevelOperatorView.opCarving.HasSegmentation.value
            nzLB    = self.topLevelOperatorView.opCarving.opLabeling.NonzeroLabelBlocks[:].wait()[0]
            
            self.labelingDrawerUi.currentObjectLabel.setText("current object: %s" % currObj)
            self.labelingDrawerUi.save.setEnabled(currObj != "" and hasSeg)
            self.labelingDrawerUi.saveAs.setEnabled(currObj == "" and hasSeg)
            #rethink this
            #self.labelingDrawerUi.segment.setEnabled(len(nzLB) > 0)
            #self.labelingDrawerUi.clear.setEnabled(len(nzLB) > 0)
        self.topLevelOperatorView.opCarving.CurrentObjectName.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opCarving.HasSegmentation.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opCarving.opLabeling.NonzeroLabelBlocks.notifyDirty(onButtonsEnabled)
        
        # Labels
        labellayer, labelsrc = self.createLabelLayer(direct=True)
        if labellayer is not None:
            layers.append(labellayer)
            # Tell the editor where to draw label data
            self.editor.setLabelSink(labelsrc)

        #uncertainty
        uncert = self.topLevelOperatorView.opCarving.Uncertainty
        if uncert.ready():
            colortable = []
            for i in range(256-len(colortable)):
                r,g,b,a = i,0,0,i
                colortable.append(QColor(r,g,b,a).rgba())

            layer = ColortableLayer(LazyflowSource(uncert), colortable, direct=True)
            layer.name = "uncertainty"
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)

       
        #segmentation 
        seg = self.topLevelOperatorView.opCarving.Segmentation
        
        #seg = self.topLevelOperatorView.opCarving.MST.value.segmentation
        #temp = self._done_lut[self.MST.value.regionVol[sl[1:4]]]
        if seg.ready():
            #source = RelabelingArraySource(seg)
            #source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
            for i in range(256-len(colortable)):
                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())

            layer = ColortableLayer(LazyflowSource(seg), colortable, direct=True)
            layer.name = "segmentation"
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)
        
        #done 
        done = self.topLevelOperatorView.opCarving.DoneObjects
        if done.ready(): 
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,255).rgba()]
            for i in range(254-len(colortable)):
                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())
            #have to use lazyflow because it provides dirty signals
            layer = ColortableLayer(LazyflowSource(done), colortable, direct=True)
            layer.name = "done"
            layer.visible = False
            layer.opacity = 0.5
            layers.append(layer)

        #hints
        useLazyflow = True
        ctable = [QColor(0,0,0,0).rgba(), QColor(255,0,0).rgba()]
        ctable.extend( [QColor(255*random.random(), 255*random.random(), 255*random.random()) for x in range(254)] )
        if useLazyflow:
            hints = self.topLevelOperatorView.opCarving.HintOverlay
            layer = ColortableLayer(LazyflowSource(hints), ctable, direct=True)
        else:
            hints = self.topLevelOperatorView.opCarving._hints
            layer = ColortableLayer(ArraySource(hints), ctable, direct=True)
        if not useLazyflow or hints.ready():
            layer.name = "hints"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)
            
        #pmaps
        useLazyflow = True
        pmaps = self.topLevelOperatorView.opCarving._pmap
        if pmaps is not None:
            layer = GrayscaleLayer(ArraySource(pmaps), direct=True)
            layer.name = "pmap"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        #done seg
        doneSeg = self.topLevelOperatorView.opCarving.DoneSegmentation
        if doneSeg.ready():
            if self._doneSegmentationLayer is None:
                layer = ColortableLayer(LazyflowSource(doneSeg), self._doneSegmentationColortable, direct=True)
                layer.name = "done seg"
                layer.visible = False
                layer.opacity = 0.5
                self._doneSegmentationLayer = layer
                layers.append(layer)
            else:
                layers.append(self._doneSegmentationLayer)

        #supervoxel
        sv = self.topLevelOperatorView.opCarving.Supervoxels
        if sv.ready():
            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())
            layer = ColortableLayer(LazyflowSource(sv), colortable, direct=True)
            layer.name = "supervoxels"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        #raw data
        #(here we load the actual raw data from an ArraySource rather than from a LazyflowSource for speed reasons)
        raw5D = self.topLevelOperatorView.RawData.value
        layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
        layer.name = "raw"
        layer.visible = True
        layer.opacity = 1.0
        layers.append(layer)

        return layers
예제 #28
0
    def setupLayers( self ):
        logger.debug( "setupLayers" )
        
        layers = []

        def onButtonsEnabled(slot, roi):
            currObj = self.topLevelOperatorView.CurrentObjectName.value
            hasSeg  = self.topLevelOperatorView.HasSegmentation.value
            
            self.labelingDrawerUi.currentObjectLabel.setText(currObj)
            self.labelingDrawerUi.save.setEnabled(hasSeg)

        self.topLevelOperatorView.CurrentObjectName.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.HasSegmentation.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opLabelArray.NonzeroBlocks.notifyDirty(onButtonsEnabled)
        
        # Labels
        labellayer, labelsrc = self.createLabelLayer(direct=True)
        if labellayer is not None:
            labellayer._allowToggleVisible = False
            layers.append(labellayer)
            # Tell the editor where to draw label data
            self.editor.setLabelSink(labelsrc)

        #uncertainty
        if self._showUncertaintyLayer:
            uncert = self.topLevelOperatorView.Uncertainty
            if uncert.ready():
                colortable = []
                for i in range(256-len(colortable)):
                    r,g,b,a = i,0,0,i
                    colortable.append(QColor(r,g,b,a).rgba())
    
                layer = ColortableLayer(LazyflowSource(uncert), colortable, direct=True)
                layer.name = "Uncertainty"
                layer.visible = True
                layer.opacity = 0.3
                layers.append(layer)
       
        #segmentation 
        seg = self.topLevelOperatorView.Segmentation
        
        #seg = self.topLevelOperatorView.MST.value.segmentation
        #temp = self._done_lut[self.MST.value.regionVol[sl[1:4]]]
        if seg.ready():
            #source = RelabelingArraySource(seg)
            #source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
            for i in range(256-len(colortable)):
                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())

            layer = ColortableLayer(LazyflowSource(seg), colortable, direct=True)
            layer.name = "Segmentation"
            layer.setToolTip("This layer displays the <i>current</i> segmentation. Simply add foreground and background " \
                             "labels, then press <i>Segment</i>.")
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)
        
        #done 
        done = self.topLevelOperatorView.DoneObjects
        if done.ready(): 
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,255).rgba()]
            #have to use lazyflow because it provides dirty signals
            layer = ColortableLayer(LazyflowSource(done), colortable, direct=True)
            layer.name = "Completed segments (unicolor)"
            layer.setToolTip("In order to keep track of which objects you have already completed, this layer " \
                             "shows <b>all completed object</b> in one color (<b>blue</b>). " \
                             "The reason for only one color is that for finding out which " \
                              "objects to label next, the identity of already completed objects is unimportant " \
                              "and destracting.")
            layer.visible = False
            layer.opacity = 0.5
            layers.append(layer)

        #done seg
        doneSeg = self.topLevelOperatorView.DoneSegmentation
        if doneSeg.ready():
            layer = ColortableLayer(LazyflowSource(doneSeg), self._doneSegmentationColortable, direct=True)
            layer.name = "Completed segments (one color per object)"
            layer.setToolTip("<html>In order to keep track of which objects you have already completed, this layer " \
                             "shows <b>all completed object</b>, each with a random color.</html>")
            layer.visible = False
            layer.opacity = 0.5
            self._doneSegmentationLayer = layer
            layers.append(layer)

        #supervoxel
        sv = self.topLevelOperatorView.Supervoxels
        if sv.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())
            layer = ColortableLayer(LazyflowSource(sv), colortable, direct=True)
            layer.name = "Supervoxels"
            layer.setToolTip("<html>This layer shows the partitioning of the input image into <b>supervoxels</b>. The carving " \
                             "algorithm uses these tiny puzzle-piceces to piece together the segmentation of an " \
                             "object. Sometimes, supervoxels are too large and straddle two distinct objects " \
                             "(undersegmentation). In this case, it will be impossible to achieve the desired " \
                             "segmentation. This layer helps you to understand these cases.</html>")
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        #raw data
        rawSlot = self.topLevelOperatorView.RawData
        if rawSlot.ready():
            raw5D = self.topLevelOperatorView.RawData.value
            layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
            #layer = GrayscaleLayer( LazyflowSource(rawSlot) )
            layer.visible = True
            layer.name = 'Raw Data'
            layer.opacity = 1.0
            layers.append(layer)

        inputSlot = self.topLevelOperatorView.InputData
        if inputSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(inputSlot), direct=True )
            layer.name = "Input Data"
            layer.setToolTip("<html>The data originally loaded into ilastik (unprocessed).</html>")
            #layer.visible = not rawSlot.ready()
            layer.visible = True
            layer.opacity = 1.0
            # if the flag window_leveling is set the contrast 
            # of the layer is adjustable
            layer.window_leveling = True
            layers.append(layer)

            if layer.window_leveling:
                self.labelingDrawerUi.thresToolButton.show()
            else:
                self.labelingDrawerUi.thresToolButton.hide()

        filteredSlot = self.topLevelOperatorView.FilteredInputData
        if filteredSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(filteredSlot) )
            layer.name = "Filtered Input"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        return layers
예제 #29
0
        # 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()
예제 #30
0
def showStuff(raw_name, pred_viewer1, pred_viewer2, cutout_name, one_extra = None):
    # display the raw and annotations for cremi challenge data
    raw = vigra.impex.readHDF5(indir+datasets[raw_name], "data", order = 'C')
    # raw_old = vigra.readHDF5(indir+datasets["raw_bad"], "data", order = 'C')
    defect_prediction_128 = vigra.impex.readHDF5(indir+datasets[pred_viewer2], "data", order = 'C')
    defect_prediction_150 = vigra.impex.readHDF5(indir+datasets[pred_viewer1], "data", order = 'C')
    cutout_from_150_pred = vigra.impex.readHDF5(indir+datasets[cutout_name], "data", order = 'C')

    ####################################################################################################################
    # only used for fast testing stuff
    #change_one = vigra.readHDF5(indir+datasets["segmentation_on_equalized_image"], "data", order = 'C')
    #pdb.set_trace()
    #defect_prediction_150[1,:,:] = change_one[0,:,:,0]
    ####################################################################################################################
    # defect_prediction_150 = gt[..., 0]
    cutout = numpy.asarray(cutout_from_150_pred)
    rawdata = numpy.asarray(raw)
    # rawdata_old = numpy.asarray(raw_old)
    # op5ify
    # shape5d = rawdata.shape
    shape5d = (1,)+rawdata.shape+(1,)
    print shape5d, rawdata.shape, rawdata.dtype

    app = QApplication([])
    v = Viewer()
    direct = False

    # layer for raw data
    rawdata = numpy.reshape(rawdata, shape5d)
    rawsource = ArraySource(rawdata)
    v.dataShape = shape5d
    lraw = GrayscaleLayer(rawsource, direct=direct)
    lraw.visible = True
    lraw.name = "raw"
    v.layerstack.append(lraw)

    # layer for cutout regions from raw data
    cutout = numpy.reshape(cutout, shape5d)
    cutoutsource = ArraySource(cutout)
    lcutout = GrayscaleLayer(cutoutsource, direct = direct)
    lcutout.visible = False
    lcutout.name = "cut_out"
    v.layerstack.append(lcutout)

    # layer for first prediction result
    defect_prediction_128 = numpy.reshape(defect_prediction_128, shape5d)
    synsource = ArraySource(defect_prediction_128)
    ct = create_random_16bit()
    ct[0] = 0
    lsyn = ColortableLayer(synsource, ct)
    lsyn.name = pred_viewer2
    lsyn.visible = False
    v.layerstack.append(lsyn)

    # layer for second prediction result
    segm = numpy.reshape(defect_prediction_150, shape5d)
    segsource = ArraySource(segm)
    ct = create_random_16bit()
    ct[0] = 0
    lseg = ColortableLayer(segsource, ct)
    lseg.name = pred_viewer1
    lseg.visible = False
    v.layerstack.append(lseg)
    if one_extra is None:
        v.showMaximized()
        app.exec_()

    if one_extra is not None:
        # layer for third prediction result
        extra_prediction = vigra.readHDF5(indir+datasets[one_extra], "data", order = 'C')
        extra_pred_reshaped = numpy.reshape(extra_prediction, shape5d)
        segsource = ArraySource(extra_pred_reshaped)
        ct = create_random_16bit()
        ct[0] = 0
        # ct = create_default_16bit()
        lseg = ColortableLayer(segsource, ct)
        lseg.name = one_extra
        lseg.visible = False
        v.layerstack.append(lseg)
        v.showMaximized()
        app.exec_()
예제 #31
0
    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)

        supervoxelsSlot = op.Supervoxels
        if supervoxelsSlot.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())
            supervoxelsLayer = ColortableLayer(LazyflowSource(supervoxelsSlot),
                                               colortable)
            supervoxelsLayer.name = "Input Supervoxels"
            supervoxelsLayer.visible = False
            supervoxelsLayer.opacity = 1.0
            layers.append(supervoxelsLayer)

        def addFragmentSegmentationLayers(mslot, name):
            if mslot.ready():
                for index, slot in enumerate(mslot):
                    if slot.ready():
                        raveler_label = slot.meta.selected_label
                        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())
                        colortable[0] = QColor(0, 0, 0, 0).rgba()
                        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.MaskedSupervoxels,
                                      "Masked Supervoxels")
        addFragmentSegmentationLayers(op.FilteredMaskedSupervoxels,
                                      "Filtered Masked Supervoxels")
        addFragmentSegmentationLayers(op.HoleFilledSupervoxels,
                                      "Hole Filled Supervoxels")
        addFragmentSegmentationLayers(op.RelabeledSupervoxels,
                                      "Relabeled Supervoxels")

        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.FinalSupervoxels
        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)
            finalLayer.name = "Final Supervoxels"
            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
        if rawSlot.ready():
            raw5D = self.topLevelOperatorView.RawData.value
            layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
            #layer = GrayscaleLayer( LazyflowSource(rawSlot) )
            layer.name = "raw"
            layer.visible = True
            layer.opacity = 1.0
            layers.append(layer)

        return layers
예제 #32
0
    def setupLayers( self ):
        layers = []

        def onButtonsEnabled(slot, roi):
            currObj = self.topLevelOperatorView.CurrentObjectName.value
            hasSeg  = self.topLevelOperatorView.HasSegmentation.value
            
            self.labelingDrawerUi.currentObjectLabel.setText(currObj)
            self.labelingDrawerUi.save.setEnabled(hasSeg)

        self.topLevelOperatorView.CurrentObjectName.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.HasSegmentation.notifyDirty(onButtonsEnabled)
        self.topLevelOperatorView.opLabelArray.NonzeroBlocks.notifyDirty(onButtonsEnabled)
        
        # Labels
        labellayer, labelsrc = self.createLabelLayer(direct=True)
        if labellayer is not None:
            layers.append(labellayer)
            # Tell the editor where to draw label data
            self.editor.setLabelSink(labelsrc)

        #uncertainty
        if self._showUncertaintyLayer:
            uncert = self.topLevelOperatorView.Uncertainty
            if uncert.ready():
                colortable = []
                for i in range(256-len(colortable)):
                    r,g,b,a = i,0,0,i
                    colortable.append(QColor(r,g,b,a).rgba())
    
                layer = ColortableLayer(LazyflowSource(uncert), colortable, direct=True)
                layer.name = "Uncertainty"
                layer.visible = True
                layer.opacity = 0.3
                layers.append(layer)
       
        #segmentation 
        seg = self.topLevelOperatorView.Segmentation
        
        #seg = self.topLevelOperatorView.MST.value.segmentation
        #temp = self._done_lut[self.MST.value.regionVol[sl[1:4]]]
        if seg.ready():
            #source = RelabelingArraySource(seg)
            #source.setRelabeling(numpy.arange(256, dtype=numpy.uint8))
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,0,0).rgba(), QColor(0,255,0).rgba()]
            for i in range(256-len(colortable)):
                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())

            layer = ColortableLayer(LazyflowSource(seg), colortable, direct=True)
            layer.name = "Segmentation"
            layer.setToolTip("This layer displays the <i>current</i> segmentation. Simply add foreground and background " \
                             "labels, then press <i>Segment</i>.")
            layer.visible = True
            layer.opacity = 0.3
            layers.append(layer)
        
        #done 
        done = self.topLevelOperatorView.DoneObjects
        if done.ready(): 
            colortable = [QColor(0,0,0,0).rgba(), QColor(0,0,255).rgba()]
            for i in range(254-len(colortable)):
                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)
                colortable.append(QColor(r,g,b).rgba())
            #have to use lazyflow because it provides dirty signals
            layer = ColortableLayer(LazyflowSource(done), colortable, direct=True)
            layer.name = "Completed segments (unicolor)"
            layer.setToolTip("In order to keep track of which objects you have already completed, this layer " \
                             "shows <b>all completed object</b> in one color (<b>blue</b>). " \
                             "The reason for only one color is that for finding out which " \
                              "objects to label next, the identity of already completed objects is unimportant " \
                              "and destracting.")
            layer.visible = False
            layer.opacity = 0.5
            layers.append(layer)

        #hints
        '''
        useLazyflow = True
        ctable = [QColor(0,0,0,0).rgba(), QColor(255,0,0).rgba()]
        ctable.extend( [QColor(255*random.random(), 255*random.random(), 255*random.random()) for x in range(254)] )
        if useLazyflow:
            hints = self.topLevelOperatorView.HintOverlay
            layer = ColortableLayer(LazyflowSource(hints), ctable, direct=True)
        else:
            hints = self.topLevelOperatorView._hints
            layer = ColortableLayer(ArraySource(hints), ctable, direct=True)
        if not useLazyflow or hints.ready():
            layer.name = "hints"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)
        '''
        
        '''
        #pmaps
        useLazyflow = True
        pmaps = self.topLevelOperatorView._pmap
        if pmaps is not None:
            layer = GrayscaleLayer(ArraySource(pmaps), direct=True)
            layer.name = "pmap"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)
        '''

        #done seg
        doneSeg = self.topLevelOperatorView.DoneSegmentation
        if doneSeg.ready():
            if self._doneSegmentationLayer is None:
                layer = ColortableLayer(LazyflowSource(doneSeg), self._doneSegmentationColortable, direct=True)
                layer.name = "Completed segments (one color per object)"
                layer.setToolTip("<html>In order to keep track of which objects you have already completed, this layer " \
                                 "shows <b>all completed object</b>, each with a random color.</html>")
                layer.visible = False
                layer.opacity = 0.5
                self._doneSegmentationLayer = layer
                layers.append(layer)
            else:
                layers.append(self._doneSegmentationLayer)

        #supervoxel
        sv = self.topLevelOperatorView.Supervoxels
        if sv.ready():
            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())
            layer = ColortableLayer(LazyflowSource(sv), colortable, direct=True)
            layer.name = "Supervoxels"
            layer.setToolTip("<html>This layer shows the partitioning of the input image into <b>supervoxels</b>. The carving " \
                             "algorithm uses these tiny puzzle-piceces to piece together the segmentation of an " \
                             "object. Sometimes, supervoxels are too large and straddle two distinct objects " \
                             "(undersegmentation). In this case, it will be impossible to achieve the desired " \
                             "segmentation. This layer helps you to understand these cases.</html>")
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        #raw data
        '''
        rawSlot = self.topLevelOperatorView.RawData
        if rawSlot.ready():
            raw5D = self.topLevelOperatorView.RawData.value
            layer = GrayscaleLayer(ArraySource(raw5D), direct=True)
            #layer = GrayscaleLayer( LazyflowSource(rawSlot) )
            layer.visible = True
            layer.name = 'raw'
            layer.opacity = 1.0
            layers.append(layer)
        '''

        inputSlot = self.topLevelOperatorView.InputData
        if inputSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(inputSlot), direct=True )
            layer.name = "Input Data"
            layer.setToolTip("<html>The data originally loaded into ilastik (unprocessed).</html>")
            #layer.visible = not rawSlot.ready()
            layer.visible = True
            layer.opacity = 1.0
            layers.append(layer)

        filteredSlot = self.topLevelOperatorView.FilteredInputData
        if filteredSlot.ready():
            layer = GrayscaleLayer( LazyflowSource(filteredSlot) )
            layer.name = "Filtered Input"
            layer.visible = False
            layer.opacity = 1.0
            layers.append(layer)

        return layers