Example #1
0
    def setUp(self):
        segimg = segImage()

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

        feats = {"Standard Object Features": 
                    {"Count":{}, "RegionCenter":{}, "Coord<Principal<Kurtosis>>":{}, "Coord<Minimum>":{}, "Coord<Maximum>":{}} 
                }
        
        g = Graph()
        self.featsop = OpRegionFeatures(graph=g)
        self.featsop.LabelVolume.setValue(segimg)
        self.featsop.RawVolume.setValue( rawimg )
        self.featsop.Features.setValue(feats)
        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.op = OpObjectTrain(graph=g)
        self.op.Features.resize(1)
        self.op.Features[0].connect(self._opRegFeatsAdaptOutput.Output)
        self.op.SelectedFeatures.setValue(feats)
        self.op.FixClassifier.setValue(False)
        self.op.ForestCount.setValue(self.nRandomForests)
Example #2
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))
Example #3
0
    def setUp(self):
        segimg = segImage()
        binimg = (segimg > 0).astype(np.uint8)
        labels = {0: np.array([0, 1, 2]), 1: np.array([0, 1, 1, 2])}

        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": {},
                "RegionCenter": {},
                "Coord<Principal<Kurtosis>>": {},
                "Coord<Maximum>": {},
                "Mean": {},
                "Mean in neighborhood": {
                    "margin": (30, 30, 1)
                },
            }
        }

        sel_features = {
            "Standard Object Features": {
                "Count": {},
                "Mean": {},
                "Mean in neighborhood": {
                    "margin": (30, 30, 1)
                },
                "Variance": {},
            }
        }

        self.extrOp = OpObjectExtraction(graph=g)
        self.extrOp.BinaryImage.setValue(binimg)
        self.extrOp.RawImage.setValue(rawimg)
        self.extrOp.Features.setValue(features)

        assert self.extrOp.RegionFeatures.ready()
        feats = self.extrOp.RegionFeatures([0, 1]).wait()

        assert len(feats) == rawimg.shape[0]
        for key in features["Standard Object Features"]:
            assert key in list(feats[0]["Standard Object Features"].keys())

        self.trainop = OpObjectTrain(graph=g)
        self.trainop.Features.resize(1)
        self.trainop.Features.connect(self.extrOp.RegionFeatures)
        self.trainop.SelectedFeatures.setValue(sel_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)

        assert self.trainop.Classifier.ready()