コード例 #1
0
            expectedShape = self.Inputs[0].meta.shape
            for slot in self.Inputs:
                assert slot.meta.shape == expectedShape, "Can't add images of different shapes!"
            self.Output.meta.assignFrom(self.Inputs[0].meta)

        def execute(self, slot, subindex, roi, result):
            result[...] = numpy.zeros(result.shape)
            for slot in self.Inputs:
                result[...] += slot.get(roi).wait()
            return result

    from lazyflow.operators import OpArrayPiper
    from lazyflow.graph import OperatorWrapper
    opGenericMultiOut = OperatorWrapper(OpArrayPiper, graph=graph)
    opGenericMultiOut.Input.resize(3)
    opGenericMultiOut.name = "OpSomeProvider"
    svgOp1 = SvgOperator(opGenericMultiOut, max_child_depth=0)

    opSum = OpMultiSum(graph=graph)
    opSum.Inputs.resize(3)
    svgOp = SvgOperator(opSum, max_child_depth=1)

    class OpThreshold(Operator):
        ThresholdLevel = InputSlot()
        Input = InputSlot()
        Output = OutputSlot()

        def setupOutputs(self):
            self.Output.meta.assignFrom(self.Input.meta)
            self.Output.meta.dtype = numpy.uint8
コード例 #2
0
    def __init__(self):
        # Create a graph to be shared by all operators
        graph = Graph()
        super(PixelClassificationWorkflow, self).__init__( graph=graph )
        self._applets = []

        ######################
        # Interactive workflow
        ######################
        
        ## Create applets 
        self.projectMetadataApplet = ProjectMetadataApplet()
        self.dataSelectionApplet = DataSelectionApplet(self, "Input Data", "Input Data", supportIlastik05Import=True, batchDataGui=False)
        self.featureSelectionApplet = FeatureSelectionApplet(self, "Feature Selection", "FeatureSelections")
        self.pcApplet = PixelClassificationApplet(self, "PixelClassification")

        ## Access applet operators
        opData = self.dataSelectionApplet.topLevelOperator
        opTrainingFeatures = self.featureSelectionApplet.topLevelOperator
        opClassify = self.pcApplet.topLevelOperator
        
        ## Connect operators ##
        
        # Input Image -> Feature Op
        #         and -> Classification Op (for display)
        opTrainingFeatures.InputImage.connect( opData.Image )
        opClassify.InputImages.connect( opData.Image )
        
        # Feature Images -> Classification Op (for training, prediction)
        opClassify.FeatureImages.connect( opTrainingFeatures.OutputImage )
        opClassify.CachedFeatureImages.connect( opTrainingFeatures.CachedOutputImage )
        
        # Training flags -> Classification Op (for GUI restrictions)
        opClassify.LabelsAllowedFlags.connect( opData.AllowLabels )
        
        ######################
        # Batch workflow
        ######################
        
        ## Create applets
        self.batchInputApplet = DataSelectionApplet(self, "Batch Inputs", "BatchDataSelection", supportIlastik05Import=False, batchDataGui=True)
        self.batchResultsApplet = BatchIoApplet(self, "Batch Results")

        ## Access applet operators
        opBatchInputs = self.batchInputApplet.topLevelOperator
        opBatchInputs.name = 'opBatchInputs'
        opBatchResults = self.batchResultsApplet.topLevelOperator
        
        ## Create additional batch workflow operators
        opBatchFeatures = OperatorWrapper( OpFeatureSelection, graph=graph, parent=self, promotedSlotNames=['InputImage'] )
        opBatchFeatures.name = "opBatchFeatures"
        opBatchPredictor = OperatorWrapper( OpPredictRandomForest, graph=graph, parent=self, promotedSlotNames=['Image'])
        opBatchPredictor.name = "opBatchPredictor"
        opSelectBatchDatasetPath = OperatorWrapper( OpAttributeSelector, graph=graph, parent=self )
        
        ## Connect Operators ## 
        
        # Provide dataset paths from data selection applet to the batch export applet via an attribute selector
        opSelectBatchDatasetPath.InputObject.connect( opBatchInputs.Dataset )
        opSelectBatchDatasetPath.AttributeName.setValue( 'filePath' )
        opBatchResults.DatasetPath.connect( opSelectBatchDatasetPath.Result )
        
        # Connect (clone) the feature operator inputs from 
        #  the interactive workflow's features operator (which gets them from the GUI)
        opBatchFeatures.Scales.connect( opTrainingFeatures.Scales )
        opBatchFeatures.FeatureIds.connect( opTrainingFeatures.FeatureIds )
        opBatchFeatures.SelectionMatrix.connect( opTrainingFeatures.SelectionMatrix )
        
        # Classifier and LabelsCount are provided by the interactive workflow
        opBatchPredictor.Classifier.connect( opClassify.Classifier )
        opBatchPredictor.LabelsCount.connect( opClassify.MaxLabelValue )
        
        # Connect Image pathway:
        # Input Image -> Features Op -> Prediction Op -> Export
        opBatchFeatures.InputImage.connect( opBatchInputs.Image )
        opBatchPredictor.Image.connect( opBatchFeatures.OutputImage )
        opBatchResults.ImageToExport.connect( opBatchPredictor.PMaps )

        self._applets.append(self.projectMetadataApplet)
        self._applets.append(self.dataSelectionApplet)
        self._applets.append(self.featureSelectionApplet)
        self._applets.append(self.pcApplet)
        self._applets.append(self.batchInputApplet)
        self._applets.append(self.batchResultsApplet)

        # The shell needs a slot from which he can read the list of image names to switch between.
        # Use an OpAttributeSelector to create a slot containing just the filename from the OpDataSelection's DatasetInfo slot.
        opSelectFilename = OperatorWrapper( OpAttributeSelector, graph=graph, parent=self )
        opSelectFilename.InputObject.connect( opData.Dataset )
        opSelectFilename.AttributeName.setValue( 'filePath' )

        self._imageNameListSlot = opSelectFilename.Result
コード例 #3
0
ファイル: schematic.py プロジェクト: CVML/lazyflow
            expectedShape = self.Inputs[0].meta.shape
            for slot in self.Inputs:
                assert slot.meta.shape == expectedShape, "Can't add images of different shapes!"
            self.Output.meta.assignFrom(self.Inputs[0].meta)
    
        def execute(self, slot, subindex, roi, result):
            result[...] = numpy.zeros(result.shape)
            for slot in self.Inputs:
                result[...] += slot.get(roi).wait()
            return result

    from lazyflow.operators import OpArrayPiper
    from lazyflow.graph import OperatorWrapper
    opGenericMultiOut = OperatorWrapper( OpArrayPiper, graph=graph )
    opGenericMultiOut.Input.resize(3)
    opGenericMultiOut.name = "OpSomeProvider"
    svgOp1 = SvgOperator(opGenericMultiOut, max_child_depth=0)

    opSum = OpMultiSum(graph=graph)
    opSum.Inputs.resize(3)
    svgOp = SvgOperator(opSum, max_child_depth=1)

    class OpThreshold(Operator):
        ThresholdLevel = InputSlot()
        Input = InputSlot()
        Output = OutputSlot()
        
        def setupOutputs(self):
            self.Output.meta.assignFrom(self.Input.meta)
            self.Output.meta.dtype = numpy.uint8
コード例 #4
0
    def __init__(self):
        super(PixelClassificationWorkflow, self).__init__()
        self._applets = []

        # Create a graph to be shared by all operators
        graph = Graph()
        self._graph = graph

        ######################
        # Interactive workflow
        ######################

        ## Create applets
        self.projectMetadataApplet = ProjectMetadataApplet()
        self.dataSelectionApplet = DataSelectionApplet(
            graph,
            "Input Data",
            "Input Data",
            supportIlastik05Import=True,
            batchDataGui=False)
        self.featureSelectionApplet = FeatureSelectionApplet(
            graph, "Feature Selection", "FeatureSelections")
        self.pcApplet = PixelClassificationApplet(graph, "PixelClassification")

        ## Access applet operators
        opData = self.dataSelectionApplet.topLevelOperator
        opTrainingFeatures = self.featureSelectionApplet.topLevelOperator
        opClassify = self.pcApplet.topLevelOperator

        ## Connect operators ##

        # Input Image -> Feature Op
        #         and -> Classification Op (for display)
        opTrainingFeatures.InputImage.connect(opData.Image)
        opClassify.InputImages.connect(opData.Image)

        # Feature Images -> Classification Op (for training, prediction)
        opClassify.FeatureImages.connect(opTrainingFeatures.OutputImage)
        opClassify.CachedFeatureImages.connect(
            opTrainingFeatures.CachedOutputImage)

        # Training flags -> Classification Op (for GUI restrictions)
        opClassify.LabelsAllowedFlags.connect(opData.AllowLabels)

        ######################
        # Batch workflow
        ######################

        ## Create applets
        self.batchInputApplet = DataSelectionApplet(
            graph,
            "Batch Inputs",
            "BatchDataSelection",
            supportIlastik05Import=False,
            batchDataGui=True)
        self.batchResultsApplet = BatchIoApplet(graph, "Batch Results")

        ## Access applet operators
        opBatchInputs = self.batchInputApplet.topLevelOperator
        opBatchInputs.name = 'opBatchInputs'
        opBatchResults = self.batchResultsApplet.topLevelOperator

        ## Create additional batch workflow operators
        opBatchFeatures = OperatorWrapper(OpFeatureSelection,
                                          graph=graph,
                                          promotedSlotNames=['InputImage'])
        opBatchFeatures.name = "opBatchFeatures"
        opBatchPredictor = OperatorWrapper(OpPredictRandomForest,
                                           graph=graph,
                                           promotedSlotNames=['Image'])
        opBatchPredictor.name = "opBatchPredictor"
        opSelectBatchDatasetPath = OperatorWrapper(OpAttributeSelector,
                                                   graph=graph)

        ## Connect Operators ##

        # Provide dataset paths from data selection applet to the batch export applet via an attribute selector
        opSelectBatchDatasetPath.InputObject.connect(opBatchInputs.Dataset)
        opSelectBatchDatasetPath.AttributeName.setValue('filePath')
        opBatchResults.DatasetPath.connect(opSelectBatchDatasetPath.Result)

        # Connect (clone) the feature operator inputs from
        #  the interactive workflow's features operator (which gets them from the GUI)
        opBatchFeatures.Scales.connect(opTrainingFeatures.Scales)
        opBatchFeatures.FeatureIds.connect(opTrainingFeatures.FeatureIds)
        opBatchFeatures.SelectionMatrix.connect(
            opTrainingFeatures.SelectionMatrix)

        # Classifier and LabelsCount are provided by the interactive workflow
        opBatchPredictor.Classifier.connect(opClassify.Classifier)
        opBatchPredictor.LabelsCount.connect(opClassify.MaxLabelValue)

        # Connect Image pathway:
        # Input Image -> Features Op -> Prediction Op -> Export
        opBatchFeatures.InputImage.connect(opBatchInputs.Image)
        opBatchPredictor.Image.connect(opBatchFeatures.OutputImage)
        opBatchResults.ImageToExport.connect(opBatchPredictor.PMaps)

        self._applets.append(self.projectMetadataApplet)
        self._applets.append(self.dataSelectionApplet)
        self._applets.append(self.featureSelectionApplet)
        self._applets.append(self.pcApplet)
        self._applets.append(self.batchInputApplet)
        self._applets.append(self.batchResultsApplet)

        # The shell needs a slot from which he can read the list of image names to switch between.
        # Use an OpAttributeSelector to create a slot containing just the filename from the OpDataSelection's DatasetInfo slot.
        opSelectFilename = OperatorWrapper(OpAttributeSelector, graph=graph)
        opSelectFilename.InputObject.connect(opData.Dataset)
        opSelectFilename.AttributeName.setValue('filePath')

        self._imageNameListSlot = opSelectFilename.Result