コード例 #1
0
    def connectLane(self, laneIndex):
        """
        Override from base class.
        """
        opDataSelection = self.dataSelectionApplet.topLevelOperator.getLane(
            laneIndex)
        opWsdt = self.wsdtApplet.topLevelOperator.getLane(laneIndex)
        opEdgeTrainingWithMulticut = self.edgeTrainingWithMulticutApplet.topLevelOperator.getLane(
            laneIndex)
        opDataExport = self.dataExportApplet.topLevelOperator.getLane(
            laneIndex)

        # RAW DATA: Convert to float32
        opConvertRaw = OpConvertDtype(parent=self)
        opConvertRaw.ConversionDtype.setValue(np.float32)
        opConvertRaw.Input.connect(
            opDataSelection.ImageGroup[self.DATA_ROLE_RAW])

        # PROBABILITIES: Convert to float32
        opConvertProbabilities = OpConvertDtype(parent=self)
        opConvertProbabilities.ConversionDtype.setValue(np.float32)
        opConvertProbabilities.Input.connect(
            opDataSelection.ImageGroup[self.DATA_ROLE_PROBABILITIES])

        # PROBABILITIES: Normalize drange to [0.0, 1.0]
        opNormalizeProbabilities = OpPixelOperator(parent=self)

        def normalize_inplace(a):
            drange = opConvertProbabilities.Output.meta.drange
            if drange is None or (drange[0] == 0.0 and drange[1] == 1.0):
                return a
            a[:] -= drange[0]
            a[:] = a[:] / float((drange[1] - drange[0]))
            return a

        opNormalizeProbabilities.Input.connect(opConvertProbabilities.Output)
        opNormalizeProbabilities.Function.setValue(normalize_inplace)

        # GROUNDTRUTH: Convert to uint32, relabel, and cache
        opConvertGroundtruth = OpConvertDtype(parent=self)
        opConvertGroundtruth.ConversionDtype.setValue(np.uint32)
        opConvertGroundtruth.Input.connect(
            opDataSelection.ImageGroup[self.DATA_ROLE_GROUNDTRUTH])

        opRelabelGroundtruth = OpRelabelConsecutive(parent=self)
        opRelabelGroundtruth.Input.connect(opConvertGroundtruth.Output)

        opGroundtruthCache = OpBlockedArrayCache(parent=self)
        opGroundtruthCache.CompressionEnabled.setValue(True)
        opGroundtruthCache.Input.connect(opRelabelGroundtruth.Output)

        # watershed inputs
        opWsdt.RawData.connect(opDataSelection.ImageGroup[self.DATA_ROLE_RAW])
        opWsdt.Input.connect(opNormalizeProbabilities.Output)

        # Actual computation is done with both RawData and Probabilities
        opStackRawAndVoxels = OpSimpleStacker(parent=self)
        opStackRawAndVoxels.Images.resize(2)
        opStackRawAndVoxels.Images[0].connect(opConvertRaw.Output)
        opStackRawAndVoxels.Images[1].connect(opNormalizeProbabilities.Output)
        opStackRawAndVoxels.AxisFlag.setValue("c")

        # If superpixels are available from a file, use it.
        opSuperpixelsSelect = OpPrecomputedInput(ignore_dirty_input=True,
                                                 parent=self)
        opSuperpixelsSelect.PrecomputedInput.connect(
            opDataSelection.ImageGroup[self.DATA_ROLE_SUPERPIXELS])
        opSuperpixelsSelect.SlowInput.connect(opWsdt.Superpixels)

        # If the superpixel file changes, then we have to remove the training labels from the image
        opEdgeTraining = opEdgeTrainingWithMulticut.opEdgeTraining

        def handle_new_superpixels(*args):
            opEdgeTraining.handle_dirty_superpixels(opEdgeTraining.Superpixels)

        opDataSelection.ImageGroup[self.DATA_ROLE_SUPERPIXELS].notifyReady(
            handle_new_superpixels)
        opDataSelection.ImageGroup[self.DATA_ROLE_SUPERPIXELS].notifyUnready(
            handle_new_superpixels)

        # edge training inputs
        opEdgeTrainingWithMulticut.RawData.connect(opDataSelection.ImageGroup[
            self.DATA_ROLE_RAW])  # Used for visualization only
        opEdgeTrainingWithMulticut.VoxelData.connect(
            opStackRawAndVoxels.Output)
        opEdgeTrainingWithMulticut.Superpixels.connect(
            opSuperpixelsSelect.Output)
        opEdgeTrainingWithMulticut.GroundtruthSegmentation.connect(
            opGroundtruthCache.Output)
        opEdgeTrainingWithMulticut.WatershedSelectedInput.connect(
            opWsdt.SelectedInput)

        def _invalidate_cache_on_sp_change(*args, **kwargs):
            op = opEdgeTrainingWithMulticut
            opEdgeTrainingWithMulticut.clear_caches(op.current_view_index())

        opSuperpixelsSelect.Output.notifyDirty(_invalidate_cache_on_sp_change)

        # DataExport inputs
        opDataExport.RawData.connect(
            opDataSelection.ImageGroup[self.DATA_ROLE_RAW])
        opDataExport.RawDatasetInfo.connect(
            opDataSelection.DatasetGroup[self.DATA_ROLE_RAW])
        opDataExport.Inputs.resize(len(self.EXPORT_NAMES))
        opDataExport.Inputs[0].connect(opEdgeTrainingWithMulticut.Output)
        for slot in opDataExport.Inputs:
            assert slot.upstream_slot is not None
コード例 #2
0
ファイル: opThresholdTwoLevels.py プロジェクト: wolny/ilastik
    def __init__(self, *args, **kwargs):
        super(OpThresholdTwoLevels, self).__init__(*args, **kwargs)

        self.opReorderInput = OpReorderAxes(parent=self)
        self.opReorderInput.AxisOrder.setValue('tzyxc')
        self.opReorderInput.Input.connect(self.InputImage)

        # PROBABILITIES: Convert to float32
        self.opConvertProbabilities = OpConvertDtype( parent=self )
        self.opConvertProbabilities.ConversionDtype.setValue( np.float32 )
        self.opConvertProbabilities.Input.connect( self.opReorderInput.Output )

        # PROBABILITIES: Normalize drange to [0.0, 1.0]
        self.opNormalizeProbabilities = OpPixelOperator( parent=self )
        def normalize_inplace(a):
            drange = self.opNormalizeProbabilities.Input.meta.drange
            if drange is None or (drange[0] == 0.0 and drange[1] == 1.0):
                return a
            a[:] -= drange[0]
            a[:] = a[:]/float(( drange[1] - drange[0] ))
            return a
        self.opNormalizeProbabilities.Input.connect( self.opConvertProbabilities.Output )
        self.opNormalizeProbabilities.Function.setValue( normalize_inplace )
        
        self.opSmoother = OpAnisotropicGaussianSmoothing5d(parent=self)
        self.opSmoother.Sigmas.connect( self.SmootherSigma )
        self.opSmoother.Input.connect( self.opNormalizeProbabilities.Output )
        
        self.opSmootherCache = OpBlockedArrayCache(parent=self)
        self.opSmootherCache.BlockShape.setValue((1, None, None, None, 1))
        self.opSmootherCache.Input.connect( self.opSmoother.Output )
        
        self.opCoreChannelSelector = OpSingleChannelSelector(parent=self)
        self.opCoreChannelSelector.Index.connect( self.CoreChannel )
        self.opCoreChannelSelector.Input.connect( self.opSmootherCache.Output )
        
        self.opCoreThreshold = OpLabeledThreshold(parent=self)
        self.opCoreThreshold.Method.setValue( ThresholdMethod.SIMPLE )
        self.opCoreThreshold.FinalThreshold.connect( self.HighThreshold )
        self.opCoreThreshold.Input.connect( self.opCoreChannelSelector.Output )

        self.opCoreFilter = OpFilterLabels(parent=self)
        self.opCoreFilter.BinaryOut.setValue(False)
        self.opCoreFilter.MinLabelSize.connect( self.MinSize )
        self.opCoreFilter.MaxLabelSize.connect( self.MaxSize )
        self.opCoreFilter.Input.connect( self.opCoreThreshold.Output )
        
        self.opFinalChannelSelector = OpSingleChannelSelector(parent=self)
        self.opFinalChannelSelector.Index.connect( self.Channel )
        self.opFinalChannelSelector.Input.connect( self.opSmootherCache.Output )

        self.opSumInputs = OpMultiArrayMerger(parent=self) # see setupOutputs (below) for input connections
        self.opSumInputs.MergingFunction.setValue( sum )
        
        self.opFinalThreshold = OpLabeledThreshold(parent=self)
        self.opFinalThreshold.Method.connect( self.CurOperator )
        self.opFinalThreshold.FinalThreshold.connect( self.LowThreshold )
        self.opFinalThreshold.GraphcutBeta.connect( self.Beta )
        self.opFinalThreshold.CoreLabels.connect( self.opCoreFilter.Output )
        self.opFinalThreshold.Input.connect( self.opSumInputs.Output )
        
        self.opFinalFilter = OpFilterLabels(parent=self)
        self.opFinalFilter.BinaryOut.setValue(False)
        self.opFinalFilter.MinLabelSize.connect( self.MinSize )
        self.opFinalFilter.MaxLabelSize.connect( self.MaxSize )
        self.opFinalFilter.Input.connect( self.opFinalThreshold.Output )

        self.opReorderOutput = OpReorderAxes(parent=self)
        #self.opReorderOutput.AxisOrder.setValue('tzyxc') # See setupOutputs()
        self.opReorderOutput.Input.connect(self.opFinalFilter.Output)

        self.Output.connect( self.opReorderOutput.Output )

        self.opCache = OpBlockedArrayCache(parent=self)
        self.opCache.CompressionEnabled.setValue(True)
        self.opCache.Input.connect( self.opReorderOutput.Output )
        
        self.CachedOutput.connect( self.opCache.Output )
        self.CleanBlocks.connect( self.opCache.CleanBlocks )
        
        ## Debug outputs
        self.Smoothed.connect( self.opSmootherCache.Output )
        self.InputChannel.connect( self.opFinalChannelSelector.Output )
        self.SmallRegions.connect( self.opCoreThreshold.Output )
        self.BeforeSizeFilter.connect( self.opFinalThreshold.Output )

        self.opFilteredSmallLabelsCache = OpBlockedArrayCache(parent=self)
        self.opFilteredSmallLabelsCache.CompressionEnabled.setValue(True)
        self.opFilteredSmallLabelsCache.Input.connect(self.opCoreFilter.Output)
        self.FilteredSmallLabels.connect(self.opFilteredSmallLabelsCache.Output)

        # Since hysteresis thresholding creates the big regions and immediately discards the bad ones,
        # we have to recreate it here if the user wants to view it as a debug layer 
        self.opBigRegionsThreshold = OpLabeledThreshold(parent=self)
        self.opBigRegionsThreshold.Method.setValue( ThresholdMethod.SIMPLE )
        self.opBigRegionsThreshold.FinalThreshold.connect( self.LowThreshold )
        self.opBigRegionsThreshold.Input.connect( self.opFinalChannelSelector.Output )
        self.BigRegions.connect( self.opBigRegionsThreshold.Output )