Ejemplo n.º 1
0
    def _add_grayscale_layer(self, data, name=None, visible=False):
        '''
        adds a grayscale layer to the layerstack

        :param data: numpy array (2D) containing the data
        :param name: name of layer
        :param visible: bool determining whether this layer should be set to visible
        :return:
        '''
        #assert len(data.shape) == 2
        a, data_shape = createDataSource(data, True)
        self.editor.dataShape = list(data_shape)
        new_layer = GrayscaleLayer(a)
        new_layer.visible = visible
        if name is not None:
            new_layer.name = name
        self.layerstack.append(new_layer)
Ejemplo n.º 2
0
    def _add_grayscale_layer(self, data, name=None, visible=False):
        '''
        adds a grayscale layer to the layerstack

        :param data: numpy array (2D) containing the data
        :param name: name of layer
        :param visible: bool determining whether this layer should be set to visible
        :return:
        '''
        #assert len(data.shape) == 2
        a, data_shape = createDataSource(data, True)
        self.editor.dataShape = list(data_shape)
        new_layer = GrayscaleLayer(a)
        new_layer.visible = visible
        if name is not None:
            new_layer.name = name
        self.layerstack.append(new_layer)
    def 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
    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
Ejemplo n.º 5
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
Ejemplo n.º 6
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_()
Ejemplo n.º 7
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_()