Beispiel #1
0
    def setUp(self):
        segimg = segImage()
        labels = {
            0: np.array([0, 1, 2]),
            1: np.array([
                0,
                0,
                0,
                0,
            ])
        }

        rawimg = np.indices(segimg.shape).sum(0).astype(np.float32)
        rawimg = rawimg.view(vigra.VigraArray)
        rawimg.axistags = vigra.defaultAxistags('txyzc')

        g = Graph()

        features = {"Standard Object Features": {"Count": {}}}

        self.featsop = OpRegionFeatures(graph=g)
        self.featsop.LabelVolume.setValue(segimg)
        self.featsop.RawVolume.setValue(rawimg)
        self.featsop.Features.setValue(features)
        self.assertTrue(
            self.featsop.Output.ready(),
            "The output of operator {} was not ready after connections took place."
            .format(self.featsop))

        self._opRegFeatsAdaptOutput = OpAdaptTimeListRoi(graph=g)
        self._opRegFeatsAdaptOutput.Input.connect(self.featsop.Output)
        self.assertTrue(
            self._opRegFeatsAdaptOutput.Output.ready(),
            "The output of operator {} was not ready after connections took place."
            .format(self._opRegFeatsAdaptOutput))

        self.trainop = OpObjectTrain(graph=g)
        self.trainop.Features.resize(1)
        self.trainop.Features[0].connect(self._opRegFeatsAdaptOutput.Output)
        self.trainop.SelectedFeatures.setValue(features)
        self.trainop.LabelsCount.setValue(2)
        self.trainop.Labels.resize(1)
        self.trainop.Labels.setValues([labels])
        self.trainop.FixClassifier.setValue(False)
        self.trainop.ForestCount.setValue(1)
        self.assertTrue(
            self.trainop.Classifier.ready(),
            "The output of operator {} was not ready after connections took place."
            .format(self.trainop))

        self.op = OpObjectPredict(graph=g)
        self.op.Classifier.connect(self.trainop.Classifier)
        self.op.Features.connect(self._opRegFeatsAdaptOutput.Output)
        self.op.SelectedFeatures.setValue(features)
        self.op.LabelsCount.connect(self.trainop.LabelsCount)
        self.assertTrue(
            self.op.Predictions.ready(),
            "The output of operator {} was not ready after connections took place."
            .format(self.op))
    def __init__(self, block_roi, halo_padding, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)

        self.block_roi = block_roi  # In global coordinates
        self._halo_padding = halo_padding

        self._opBinarySubRegion = OpSubRegion(parent=self)
        self._opBinarySubRegion.Input.connect(self.BinaryImage)

        self._opRawSubRegion = OpSubRegion(parent=self)
        self._opRawSubRegion.Input.connect(self.RawImage)

        self._opExtract = OpObjectExtraction(parent=self)
        self._opExtract.BinaryImage.connect(self._opBinarySubRegion.Output)
        self._opExtract.RawImage.connect(self._opRawSubRegion.Output)
        self._opExtract.Features.connect(self.SelectedFeatures)
        self.BlockwiseRegionFeatures.connect(
            self._opExtract.BlockwiseRegionFeatures)

        self._opPredict = OpObjectPredict(parent=self)
        self._opPredict.Features.connect(self._opExtract.RegionFeatures)
        self._opPredict.SelectedFeatures.connect(self.SelectedFeatures)
        self._opPredict.Classifier.connect(self.Classifier)
        self._opPredict.LabelsCount.connect(self.LabelsCount)

        self._opPredictionImage = OpRelabelSegmentation(parent=self)
        self._opPredictionImage.Image.connect(self._opExtract.LabelImage)
        self._opPredictionImage.Features.connect(
            self._opExtract.RegionFeatures)
        self._opPredictionImage.ObjectMap.connect(self._opPredict.Predictions)
Beispiel #3
0
    def __init__(self, block_roi, halo_padding, *args, **kwargs):
        super(self.__class__, self).__init__(*args, **kwargs)

        self.block_roi = block_roi  # In global coordinates
        self._halo_padding = halo_padding

        self._opBinarySubRegion = OpSubRegion(parent=self)
        self._opBinarySubRegion.Input.connect(self.BinaryImage)

        self._opRawSubRegion = OpSubRegion(parent=self)
        self._opRawSubRegion.Input.connect(self.RawImage)

        self._opExtract = OpObjectExtraction(parent=self)
        self._opExtract.BinaryImage.connect(self._opBinarySubRegion.Output)
        self._opExtract.RawImage.connect(self._opRawSubRegion.Output)
        self._opExtract.Features.connect(self.SelectedFeatures)
        self.BlockwiseRegionFeatures.connect(
            self._opExtract.BlockwiseRegionFeatures)

        self._opExtract._opRegFeats._opCache.name = "blockwise-regionfeats-cache"

        self._opPredict = OpObjectPredict(parent=self)
        self._opPredict.Features.connect(self._opExtract.RegionFeatures)
        self._opPredict.SelectedFeatures.connect(self.SelectedFeatures)
        self._opPredict.Classifier.connect(self.Classifier)
        self._opPredict.LabelsCount.connect(self.LabelsCount)
        self.ObjectwisePredictions.connect(self._opPredict.Predictions)

        self._opPredictionImage = OpRelabelSegmentation(parent=self)
        self._opPredictionImage.Image.connect(self._opExtract.LabelImage)
        self._opPredictionImage.Features.connect(
            self._opExtract.RegionFeatures)
        self._opPredictionImage.ObjectMap.connect(self._opPredict.Predictions)

        self._opPredictionCache = OpArrayCache(parent=self)
        self._opPredictionCache.Input.connect(self._opPredictionImage.Output)

        self._opProbabilityChannelsToImage = OpMultiRelabelSegmentation(
            parent=self)
        self._opProbabilityChannelsToImage.Image.connect(
            self._opExtract.LabelImage)
        self._opProbabilityChannelsToImage.ObjectMaps.connect(
            self._opPredict.ProbabilityChannels)
        self._opProbabilityChannelsToImage.Features.connect(
            self._opExtract.RegionFeatures)

        self._opProbabilityChannelStacker = OpMultiArrayStacker(parent=self)
        self._opProbabilityChannelStacker.Images.connect(
            self._opProbabilityChannelsToImage.Output)
        self._opProbabilityChannelStacker.AxisFlag.setValue('c')

        self._opProbabilityCache = OpArrayCache(parent=self)
        self._opProbabilityCache.Input.connect(
            self._opProbabilityChannelStacker.Output)
Beispiel #4
0
class TestOpObjectPredict(unittest.TestCase):
    def setUp(self):
        segimg = segImage()
        labels = {0 : np.array([0, 1, 2]),
                  1 : np.array([0, 0, 0, 0,])}

        rawimg = np.indices(segimg.shape).sum(0).astype(np.float32)
        rawimg = rawimg.view(vigra.VigraArray)
        rawimg.axistags = vigra.defaultAxistags('txyzc')
        
        g = Graph()
        
        features = {"Standard Object Features": {"Count":{}}}
        
        self.featsop = OpRegionFeatures(graph=g)
        self.featsop.LabelVolume.setValue(segimg)
        self.featsop.RawVolume.setValue( rawimg )
        self.featsop.Features.setValue(features)
        self.assertTrue(self.featsop.Output.ready(), "The output of operator {} was not ready after connections took place.".format(self.featsop))

        self._opRegFeatsAdaptOutput = OpAdaptTimeListRoi(graph=g)
        self._opRegFeatsAdaptOutput.Input.connect(self.featsop.Output)
        self.assertTrue(self._opRegFeatsAdaptOutput.Output.ready(), "The output of operator {} was not ready after connections took place.".format(self._opRegFeatsAdaptOutput))

        self.trainop = OpObjectTrain(graph=g)
        self.trainop.Features.resize(1)
        self.trainop.Features[0].connect(self._opRegFeatsAdaptOutput.Output)
        self.trainop.SelectedFeatures.setValue(features)
        self.trainop.LabelsCount.setValue(2)
        self.trainop.Labels.resize(1)
        self.trainop.Labels.setValues([labels])
        self.trainop.FixClassifier.setValue(False)
        self.trainop.ForestCount.setValue(1)
        self.assertTrue(self.trainop.Classifier.ready(), "The output of operator {} was not ready after connections took place.".format(self.trainop))

        self.op = OpObjectPredict(graph=g)
        self.op.Classifier.connect(self.trainop.Classifier)
        self.op.Features.connect(self._opRegFeatsAdaptOutput.Output)
        self.op.SelectedFeatures.setValue(features)
        self.op.LabelsCount.connect( self.trainop.LabelsCount )
        self.assertTrue(self.op.Predictions.ready(), "The output of operator {} was not ready after connections took place.".format(self.op))

    def test_predict(self):
        ###
        # test whether prediction works correctly
        
        # label 1 is 'big object', label 2 is 'small object'
        ###
        preds = self.op.Predictions([0, 1]).wait()
        self.assertTrue(np.all(preds[0] == np.array([0, 1, 2])))
        self.assertTrue(np.all(preds[1] == np.array([0, 1, 1, 2])))
        
    def test_probabilities(self):
        ###
        # test whether the probability channel slots and the total probability slot return the same values
        ###
        probs = self.op.Probabilities([0, 1]).wait()
        probChannel0Time0 = self.op.ProbabilityChannels[0][0].wait()
        probChannel1Time0 = self.op.ProbabilityChannels[1][0].wait()
        probChannel0Time1 = self.op.ProbabilityChannels[0][1].wait()
        probChannel1Time1 = self.op.ProbabilityChannels[1][1].wait()
        probChannel0Time01 = self.op.ProbabilityChannels[0]([0, 1]).wait()
        
        self.assertTrue( np.all(probChannel0Time0[0]==probs[0][:, 0]) )
        self.assertTrue( np.all(probChannel1Time0[0]==probs[0][:, 1]) )
        
        self.assertTrue( np.all(probChannel0Time1[1]==probs[1][:, 0]) )
        self.assertTrue( np.all(probChannel1Time1[1]==probs[1][:, 1]) )
        
        self.assertTrue( np.all(probChannel0Time01[0]==probs[0][:, 0]) )
        self.assertTrue( np.all(probChannel0Time01[1]==probs[1][:, 0]) )