Пример #1
0
    def __init__(self, *args, **kwargs):
        super(OpPredictionPipeline, self).__init__(*args, **kwargs)

        # Random forest prediction using CACHED features.
        self.predict = OpClassifierPredict(parent=self)
        self.predict.name = "OpClassifierPredict"
        self.predict.Classifier.connect(self.Classifier)
        self.predict.Image.connect(self.CachedFeatureImages)
        self.predict.PredictionMask.connect(self.PredictionMask)
        self.predict.LabelsCount.connect(self.NumClasses)
        self.PredictionProbabilities.connect(self.predict.PMaps)

        # Alternate headless output: uint8 instead of float.
        # Note that drange is automatically updated.
        self.opConvertToUint8 = OpPixelOperator(parent=self)
        self.opConvertToUint8.Input.connect(self.predict.PMaps)
        self.opConvertToUint8.Function.setValue(lambda a:
                                                (255 * a).astype(numpy.uint8))
        self.PredictionProbabilitiesUint8.connect(self.opConvertToUint8.Output)

        # Prediction cache for the GUI
        self.prediction_cache_gui = OpSlicedBlockedArrayCache(parent=self)
        self.prediction_cache_gui.name = "prediction_cache_gui"
        self.prediction_cache_gui.inputs["fixAtCurrent"].connect(
            self.FreezePredictions)
        self.prediction_cache_gui.inputs["Input"].connect(self.predict.PMaps)
        self.CachedPredictionProbabilities.connect(
            self.prediction_cache_gui.Output)

        # Also provide each prediction channel as a separate layer (for the GUI)
        self.opPredictionSlicer = OpMultiArraySlicer2(parent=self)
        self.opPredictionSlicer.name = "opPredictionSlicer"
        self.opPredictionSlicer.Input.connect(self.prediction_cache_gui.Output)
        self.opPredictionSlicer.AxisFlag.setValue('c')
        self.PredictionProbabilityChannels.connect(
            self.opPredictionSlicer.Slices)

        self.opSegmentor = OpMaxChannelIndicatorOperator(parent=self)
        self.opSegmentor.Input.connect(self.prediction_cache_gui.Output)

        self.opSegmentationSlicer = OpMultiArraySlicer2(parent=self)
        self.opSegmentationSlicer.name = "opSegmentationSlicer"
        self.opSegmentationSlicer.Input.connect(self.opSegmentor.Output)
        self.opSegmentationSlicer.AxisFlag.setValue('c')
        self.SegmentationChannels.connect(self.opSegmentationSlicer.Slices)

        # Create a layer for uncertainty estimate
        self.opUncertaintyEstimator = OpEnsembleMargin(parent=self)
        self.opUncertaintyEstimator.Input.connect(
            self.prediction_cache_gui.Output)

        # Cache the uncertainty so we get zeros for uncomputed points
        self.opUncertaintyCache = OpSlicedBlockedArrayCache(parent=self)
        self.opUncertaintyCache.name = "opUncertaintyCache"
        self.opUncertaintyCache.Input.connect(
            self.opUncertaintyEstimator.Output)
        self.opUncertaintyCache.fixAtCurrent.connect(self.FreezePredictions)
        self.UncertaintyEstimate.connect(self.opUncertaintyCache.Output)
Пример #2
0
    def __init__(self, *args, **kwargs):
        super(OpPredictionPipeline, self).__init__(*args, **kwargs)

        # Random forest prediction using CACHED features.
        self.predict = OpClassifierPredict(parent=self)
        self.predict.name = "OpClassifierPredict"
        self.predict.Classifier.connect(self.Classifier)
        self.predict.Image.connect(self.CachedFeatureImages)
        self.predict.PredictionMask.connect(self.PredictionMask)
        self.predict.LabelsCount.connect(self.NumClasses)
        self.PredictionProbabilities.connect(self.predict.PMaps)

        # Prepare operator for Autocontext
        self.opConvertPMapsToInputPixelType = OpPixelOperator(parent=self)
        self.opConvertPMapsToInputPixelType.Input.connect(self.predict.PMaps)
        self.PredictionProbabilitiesAutocontext.connect(
            self.opConvertPMapsToInputPixelType.Output)

        # Prediction cache for the GUI
        self.prediction_cache_gui = OpSlicedBlockedArrayCache(parent=self)
        self.prediction_cache_gui.name = "prediction_cache_gui"
        self.prediction_cache_gui.inputs["fixAtCurrent"].connect(
            self.FreezePredictions)
        self.prediction_cache_gui.inputs["Input"].connect(self.predict.PMaps)
        self.CachedPredictionProbabilities.connect(
            self.prediction_cache_gui.Output)

        # Also provide each prediction channel as a separate layer (for the GUI)
        self.opPredictionSlicer = OpMultiArraySlicer2(parent=self)
        self.opPredictionSlicer.name = "opPredictionSlicer"
        self.opPredictionSlicer.Input.connect(self.prediction_cache_gui.Output)
        self.opPredictionSlicer.AxisFlag.setValue("c")
        self.PredictionProbabilityChannels.connect(
            self.opPredictionSlicer.Slices)

        self.opSegmentor = OpMaxChannelIndicatorOperator(parent=self)
        self.opSegmentor.Input.connect(self.prediction_cache_gui.Output)

        self.opSegmentationSlicer = OpMultiArraySlicer2(parent=self)
        self.opSegmentationSlicer.name = "opSegmentationSlicer"
        self.opSegmentationSlicer.Input.connect(self.opSegmentor.Output)
        self.opSegmentationSlicer.AxisFlag.setValue("c")
        self.SegmentationChannels.connect(self.opSegmentationSlicer.Slices)

        # Create a layer for uncertainty estimate
        self.opUncertaintyEstimator = OpEnsembleMargin(parent=self)
        self.opUncertaintyEstimator.Input.connect(
            self.prediction_cache_gui.Output)

        # Cache the uncertainty so we get zeros for uncomputed points
        self.opUncertaintyCache = OpSlicedBlockedArrayCache(parent=self)
        self.opUncertaintyCache.name = "opUncertaintyCache"
        self.opUncertaintyCache.Input.connect(
            self.opUncertaintyEstimator.Output)
        self.opUncertaintyCache.fixAtCurrent.connect(self.FreezePredictions)
        self.UncertaintyEstimate.connect(self.opUncertaintyCache.Output)
Пример #3
0
    def __init__(self, *args, **kwargs):
        super(OpFeatureSelection, self).__init__(*args, **kwargs)

        # Create the cache
        self.opPixelFeatureCache = OpSlicedBlockedArrayCache(parent=self)
        self.opPixelFeatureCache.name = "opPixelFeatureCache"

        # Connect the cache to the feature output
        self.opPixelFeatureCache.Input.connect(self.OutputImage)
        self.opPixelFeatureCache.fixAtCurrent.setValue(False)
    def setUp(self):
        self.dataShape = (1,100,100,10,1)
        self.data = (numpy.random.random(self.dataShape) * 100).astype(int)
        self.data = self.data.view(vigra.VigraArray)
        self.data.axistags = vigra.defaultAxistags('txyzc')

        graph = Graph()
        opProvider = OpArrayPiperWithAccessCount(graph=graph)
        opProvider.Input.setValue(self.data)
        self.opProvider = opProvider
        
        opCache = OpSlicedBlockedArrayCache(graph=graph)
        opCache.Input.connect(opProvider.Output)
        opCache.innerBlockShape.setValue( ( (10,1,10,10,10), (10,10,1,10,10), (10,10,10,1,10) ) )
        opCache.outerBlockShape.setValue( ( (20,2,20,20,20), (20,20,2,20,20), (20,20,20,2,20) ) )
        opCache.fixAtCurrent.setValue(False)
        self.opCache = opCache
    def __init__(self, *args, **kwargs):
        super(OpFeatureSelection, self).__init__(*args, **kwargs)

        # Two internal operators: features and cache
        self.opPixelFeatures = OpPixelFeaturesPresmoothed(parent=self)
        self.opPixelFeatureCache = OpSlicedBlockedArrayCache(parent=self)
        self.opPixelFeatureCache.name = "opPixelFeatureCache"

        # Connect the cache to the feature output
        self.opPixelFeatureCache.Input.connect(self.opPixelFeatures.Output)
        self.opPixelFeatureCache.fixAtCurrent.setValue(False)

        # Connect our internal operators to our external inputs 
        self.opPixelFeatures.Scales.connect( self.Scales )
        self.opPixelFeatures.FeatureIds.connect( self.FeatureIds )
        self.opPixelFeatures.Matrix.connect( self.SelectionMatrix )
        self.opPixelFeatures.Input.connect( self.InputImage )
        
        # Connect our external outputs to our internal operators
        self.OutputImage.connect( self.opPixelFeatures.Output )
        self.CachedOutputImage.connect( self.opPixelFeatureCache.Output )
        self.FeatureLayers.connect( self.opPixelFeatures.Features )
Пример #6
0
    def setupOperators(self, *args, **kwargs):

        self.predictors = []
        self.prediction_caches = []

        #niter = len(self.Classifiers)
        niter = self.AutocontextIterations.value
        for i in range(niter):
            #predict = OperatorWrapper(OpPredictRandomForest, parent=self, parent=self)
            predict = OpPredictRandomForest(parent=self)
            self.predictors.append(predict)
            #prediction_cache = OperatorWrapper( OpSlicedBlockedArrayCache, parent=self, parent=self )
            prediction_cache = OpSlicedBlockedArrayCache(parent=self)
            self.prediction_caches.append(prediction_cache)

        # Setup autocontext features
        self.autocontextFeatures = []
        self.autocontextFeaturesMulti = []
        self.autocontext_caches = []
        self.featureStackers = []

        for i in range(niter - 1):
            features = createAutocontextFeatureOperators(self, False)
            self.autocontextFeatures.append(features)
            opMulti = Op50ToMulti(parent=self)
            self.autocontextFeaturesMulti.append(opMulti)
            opStacker = OpMultiArrayStacker(parent=self)
            opStacker.inputs["AxisFlag"].setValue("c")
            opStacker.inputs["AxisIndex"].setValue(3)
            self.featureStackers.append(opStacker)
            autocontext_cache = OpSlicedBlockedArrayCache(parent=self)
            self.autocontext_caches.append(autocontext_cache)

        # connect the features to predictors
        for i in range(niter - 1):
            for ifeat, feat in enumerate(self.autocontextFeatures[i]):
                feat.inputs['Input'].connect(self.prediction_caches[i].Output)
                print "Multi: Connecting an output", "Input%.2d" % (ifeat)
                self.autocontextFeaturesMulti[i].inputs[
                    "Input%.2d" % (ifeat)].connect(feat.outputs["Output"])
            # connect the pixel features to the same multislot
            print "Multi: Connecting an output", "Input%.2d" % (len(
                self.autocontextFeatures[i]))
            self.autocontextFeaturesMulti[i].inputs["Input%.2d" % (len(
                self.autocontextFeatures[i]))].connect(self.FeatureImage)
            # stack the autocontext features with pixel features
            self.featureStackers[i].inputs["Images"].connect(
                self.autocontextFeaturesMulti[i].outputs["Outputs"])
            # cache the stacks
            self.autocontext_caches[i].inputs["Input"].connect(
                self.featureStackers[i].outputs["Output"])
            self.autocontext_caches[i].inputs["fixAtCurrent"].setValue(False)

        for i in range(niter):

            self.predictors[i].inputs['Classifier'].connect(
                self.Classifiers[i])
            self.predictors[i].inputs['LabelsCount'].connect(
                self.MaxLabelValue)

            self.prediction_caches[i].inputs["fixAtCurrent"].setValue(False)
            self.prediction_caches[i].inputs["Input"].connect(
                self.predictors[i].PMaps)

        self.predictors[0].inputs['Image'].connect(self.FeatureImage)
        for i in range(1, niter):
            self.predictors[i].inputs['Image'].connect(
                self.autocontext_caches[i - 1].outputs["Output"])

        #self.PixelOnlyPredictions.connect(self.predictors[-1].PMaps)
        self.PredictionProbabilities.connect(self.predictors[0].PMaps)
Пример #7
0
    def __init__(self, *args, **kwargs):
        super(OpVigraWatershedViewer, self).__init__(*args, **kwargs)
        self._seedThreshold = None

        # Overview Schematic
        # Example here uses input channels 0,2,5

        # InputChannelIndexes=[0,2,5] ----
        #                                 \
        # InputImage --> opChannelSlicer .Slices[0] ---\
        #                                .Slices[1] ----> opAverage -------------------------------------------------> opWatershed --> opWatershedCache --> opColorizer --> GUI
        #                                .Slices[2] ---/           \                                                  /
        #                                                           \     MinSeedSize                                /
        #                                                            \               \                              /
        #                              SeedThresholdValue ----------> opThreshold --> opSeedLabeler --> opSeedFilter --> opSeedCache --> opSeedColorizer --> GUI

        # Create operators
        self.opChannelSlicer = OpMultiArraySlicer2(parent=self)
        self.opAverage = OpMultiArrayMerger(parent=self)
        self.opWatershed = OpVigraWatershed(parent=self)
        self.opWatershedCache = OpSlicedBlockedArrayCache(parent=self)
        self.opColorizer = OpColorizeLabels(parent=self)

        self.opThreshold = OpPixelOperator(parent=self)
        self.opSeedLabeler = OpVigraLabelVolume(parent=self)
        self.opSeedFilter = OpFilterLabels(parent=self)
        self.opSeedCache = OpSlicedBlockedArrayCache(parent=self)
        self.opSeedColorizer = OpColorizeLabels(parent=self)

        # Select specific input channels
        self.opChannelSlicer.Input.connect(self.InputImage)
        self.opChannelSlicer.SliceIndexes.connect(self.InputChannelIndexes)
        self.opChannelSlicer.AxisFlag.setValue('c')

        # Average selected channels
        def average(arrays):
            if len(arrays) == 0:
                return 0
            else:
                return sum(arrays) / float(len(arrays))

        self.opAverage.MergingFunction.setValue(average)
        self.opAverage.Inputs.connect(self.opChannelSlicer.Slices)

        # Threshold for seeds
        self.opThreshold.Input.connect(self.opAverage.Output)

        # Label seeds
        self.opSeedLabeler.Input.connect(self.opThreshold.Output)

        # Filter seeds
        self.opSeedFilter.MinLabelSize.connect(self.MinSeedSize)
        self.opSeedFilter.Input.connect(self.opSeedLabeler.Output)

        # Cache seeds
        self.opSeedCache.fixAtCurrent.connect(self.FreezeCache)
        self.opSeedCache.Input.connect(self.opSeedFilter.Output)

        # Color seeds for RBG display
        self.opSeedColorizer.Input.connect(self.opSeedCache.Output)
        self.opSeedColorizer.OverrideColors.setValue({0: (0, 0, 0, 0)})

        # Compute watershed labels (possibly with seeds, see setupOutputs)
        self.opWatershed.InputImage.connect(self.opAverage.Output)
        self.opWatershed.PaddingWidth.connect(self.WatershedPadding)

        # Cache the watershed output
        self.opWatershedCache.fixAtCurrent.connect(self.FreezeCache)
        self.opWatershedCache.Input.connect(self.opWatershed.Output)

        # Colorize the watershed labels for RGB display
        self.opColorizer.Input.connect(self.opWatershedCache.Output)
        self.opColorizer.OverrideColors.connect(self.OverrideLabels)

        # Connnect external outputs the operators that provide them
        self.Seeds.connect(self.opSeedCache.Output)
        self.ColoredPixels.connect(self.opColorizer.Output)
        self.SelectedInputChannels.connect(self.opChannelSlicer.Slices)
        self.SummedInput.connect(self.opAverage.Output)
        self.ColoredSeeds.connect(self.opSeedColorizer.Output)