Exemplo n.º 1
0
    def test_table_export(self):
        opAdapt = OpAdaptTimeListRoi(graph=self.op.graph)
        opAdapt.Input.connect(self.op.Output)

        feats = opAdapt.Output([0, 1]).wait()
        print "feature length:", len(feats)
        OpObjectExtraction.createExportTable(feats)
Exemplo n.º 2
0
    def test(self):
        self.op.Output.fixed = False
        # FIXME: roi specification
        opAdapt = OpAdaptTimeListRoi(graph=self.op.graph)
        opAdapt.Input.connect(self.op.Output)

        feats = opAdapt.Output([0, 1]).wait()
        assert len(feats) == self.img.shape[0]
        for key in self.features[NAME]:
            assert key in list(feats[0][NAME].keys())

        labelimage = self.labelop.Output[:].wait()
        nt = labelimage.shape[0]
        for t in range(nt):
            npcounts = np.bincount(
                np.asarray(labelimage[t, ...].flat, dtype=int))
            counts = feats[t][NAME]["Count"].astype(np.uint32)
            means = feats[t][NAME]["Mean"]
            sum_excl = feats[t][NAME][
                "Sum in neighborhood"]  # sum, not mean, to avoid 0/0
            sum_incl = feats[t][NAME]["Sum in object and neighborhood"]
            sum = feats[t][NAME]["Sum"]
            mins = feats[t][NAME]["Coord<Minimum>"]
            maxs = feats[t][NAME]["Coord<Maximum>"]
            centers = feats[t][NAME]["RegionCenter"]
            # print mins, maxs
            nobj = npcounts.shape[0]
            for iobj in range(1, nobj):
                assert npcounts[iobj] == counts[iobj]
                objmask = labelimage[t, ...] == iobj
                npmean = np.mean(np.asarray(self.rawimage)[t, ...][objmask])
                assert npmean == means[iobj]
                # currently, we have a margin of 30, this assert is very dependent on it
                # FIXME: make margin visible from outside and use it here
                zmin = int(max(mins[iobj][2] - 1, 0))
                zmax = int(min(maxs[iobj][2] + 1, self.rawimage.shape[3]))

                exclmask = labelimage[t, :, :, zmin:zmax, :] != iobj
                npsum_excl = np.sum(
                    np.asarray(self.rawimage)[t, :, :, zmin:zmax, :][exclmask])
                assert npsum_excl == sum_excl[iobj]

                assert sum_incl[iobj] == sum[iobj] + sum_excl[iobj]
                # compare bounding box center to computed object center
                # note that for object centers vigra does statistics on coordinates
                # that means bounding box centers can differ with a maximum of 0.5
                bbox_center = mins[iobj] + ((maxs[iobj] - mins[iobj]) / 2.0)
                np.testing.assert_allclose(centers[iobj],
                                           bbox_center,
                                           atol=0.5)
    def test_features(self):
        self.op.Output.fixed = False
        # FIXME: roi specification
        opAdapt = OpAdaptTimeListRoi(graph=self.op.graph)
        opAdapt.Input.connect(self.op.Output)

        feats = opAdapt.Output([0, 1]).wait()
        assert len(feats)== self.img.shape[0]
        for t in feats:
            assert feats[t][NAME]['Count'].shape[0] > 0
            assert feats[t][NAME]['RegionCenter'].shape[0] > 0

        assert np.any(feats[0][NAME]['Count'] != feats[1][NAME]['Count'])
        assert np.any(feats[0][NAME]['RegionCenter'] != feats[1][NAME]['RegionCenter'])
Exemplo n.º 4
0
    def test(self):
        self.op.Output.fixed = False
        # FIXME: roi specification
        opAdapt = OpAdaptTimeListRoi(graph=self.op.graph)
        opAdapt.Input.connect(self.op.Output)

        feats = opAdapt.Output([0, 1]).wait()
        assert len(feats) == self.img.shape[0]
        for key in self.features[NAME]:
            assert key in feats[0][NAME].keys()

        labelimage = self.labelop.Output[:].wait()
        nt = labelimage.shape[0]
        for t in range(nt):
            npcounts = np.bincount(
                np.asarray(labelimage[t, ...].flat, dtype=int))
            counts = feats[t][NAME]["Count"].astype(np.uint32)
            means = feats[t][NAME]["Mean"]
            sum_excl = feats[t][NAME][
                "Sum in neighborhood"]  #sum, not mean, to avoid 0/0
            sum_incl = feats[t][NAME]["Sum in object and neighborhood"]
            sum = feats[t][NAME]["Sum"]
            mins = feats[t][NAME]["Coord<Minimum>"]
            maxs = feats[t][NAME]["Coord<Maximum>"]
            centers = feats[t][NAME]["RegionCenter"]
            #print mins, maxs
            nobj = npcounts.shape[0]
            for iobj in range(1, nobj):
                assert npcounts[iobj] == counts[iobj]
                objmask = labelimage[t, ...] == iobj
                npmean = np.mean(np.asarray(self.rawimage)[t, ...][objmask])
                assert npmean == means[iobj]
                #currently, we have a margin of 30, this assert is very dependent on it
                #FIXME: make margin visible from outside and use it here
                zmin = max(mins[iobj][2] - 1, 0)
                zmax = min(maxs[iobj][2] + 1, self.rawimage.shape[3])

                exclmask = labelimage[t, :, :, zmin:zmax, :] != iobj
                npsum_excl = np.sum(
                    np.asarray(self.rawimage)[t, :, :, zmin:zmax, :][exclmask])
                assert npsum_excl == sum_excl[iobj]

                assert sum_incl[iobj] == sum[iobj] + sum_excl[iobj]
                #check that regionCenter wasn't shifted
                for icoord, coord in enumerate(centers[iobj]):
                    center_good = mins[iobj][icoord] + (
                        maxs[iobj][icoord] - mins[iobj][icoord]) / 2.
                    assert abs(coord - center_good) < 0.01
Exemplo n.º 5
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)
Exemplo n.º 6
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))
Exemplo n.º 7
0
    def exportPlugin(self, filename, plugin, checkOverwriteFiles=False):
        with_divisions = self.Parameters.value["withDivisions"] if self.Parameters.ready() else False
        with_merger_resolution = self.Parameters.value["withMergerResolution"] if self.Parameters.ready() else False

        # Create opRegionFeatures to extract features of relabeled volume
        if with_merger_resolution:
            parameters = self.Parameters.value
            
            # Use simple relabeled merger feature slot configuration instead of opRelabeledMergerFeatureExtraction
            # This is faster for videos with few mergers and few number of objects per frame
            if False:#'withAnimalTracking' in parameters and parameters['withAnimalTracking']:  
                logger.info('Setting relabeled merger feature slots for animal tracking')
                from ilastik.applets.trackingFeatureExtraction import config
                
                self._opRegionFeatures = OpRegionFeatures(parent=self)
                self._opRegionFeatures.RawVolume.connect(self.RawImage)
                self._opRegionFeatures.LabelVolume.connect(self.RelabeledImage)
                
                vigra_features = list((set(config.vigra_features)).union(config.selected_features_objectcount[config.features_vigra_name]))
                feature_names_vigra = {}
                feature_names_vigra[config.features_vigra_name] = { name: {} for name in vigra_features }
                self._opRegionFeatures.Features.setValue(feature_names_vigra)
        
                self._opAdaptTimeListRoi = OpAdaptTimeListRoi(parent=self)
                self._opAdaptTimeListRoi.Input.connect(self._opRegionFeatures.Output)
                
                object_feature_slot = self._opAdaptTimeListRoi.Output
            # Use opRelabeledMergerFeatureExtraction for cell tracking
            else:
                opRelabeledRegionFeatures = self._setupRelabeledFeatureSlot(self.ObjectFeatures)
                object_feature_slot = opRelabeledRegionFeatures.RegionFeatures                
            
            label_image = self.RelabeledImage

        # Use ObjectFeaturesWithDivFeatures slot
        elif with_divisions:
            object_feature_slot = self.ObjectFeaturesWithDivFeatures
            label_image = self.LabelImage
        # Use ObjectFeatures slot only
        else:
            object_feature_slot = self.ObjectFeatures
            label_image = self.LabelImage
        
        hypothesesGraph = self.HypothesesGraph.value

        if checkOverwriteFiles and plugin.checkFilesExist(filename):
            # do not export if we would otherwise overwrite files
            return False

        if not plugin.export(filename, hypothesesGraph, object_feature_slot, label_image, self.RawImage):
            raise RuntimeError('Exporting tracking solution with plugin failed')
        else:
            return True
Exemplo n.º 8
0
    def __init__(self, parent):
        super(OpTrackingFeatureExtraction, self).__init__(parent)
        self._default_features = None
        # internal operators
        self._objectExtraction = OpObjectExtraction(parent=self)

        self._opDivFeats = OpCachedDivisionFeatures(parent=self)
        self._opDivFeatsAdaptOutput = OpAdaptTimeListRoi(parent=self)

        # connect internal operators
        self._objectExtraction.RawImage.connect(self.RawImage)
        self._objectExtraction.BinaryImage.connect(self.BinaryImage)
        self._objectExtraction.BypassModeEnabled.connect(
            self.BypassModeEnabled)
        self._objectExtraction.Features.connect(self.FeatureNamesVigra)
        self._objectExtraction.RegionFeaturesCacheInput.connect(
            self.RegionFeaturesCacheInputVigra)
        self._objectExtraction.LabelImageCacheInput.connect(
            self.LabelImageCacheInput)
        self.CleanLabelBlocks.connect(self._objectExtraction.CleanLabelBlocks)
        self.RegionFeaturesCleanBlocksVigra.connect(
            self._objectExtraction.RegionFeaturesCleanBlocks)
        self.ObjectCenterImage.connect(
            self._objectExtraction.ObjectCenterImage)
        self.LabelImage.connect(self._objectExtraction.LabelImage)
        self.BlockwiseRegionFeaturesVigra.connect(
            self._objectExtraction.BlockwiseRegionFeatures)
        self.RegionFeaturesVigra.connect(self._objectExtraction.RegionFeatures)

        self._opDivFeats.LabelImage.connect(self.LabelImage)
        self._opDivFeats.DivisionFeatureNames.connect(
            self.FeatureNamesDivision)
        self._opDivFeats.CacheInput.connect(
            self.RegionFeaturesCacheInputDivision)
        self._opDivFeats.RegionFeaturesVigra.connect(
            self._objectExtraction.BlockwiseRegionFeatures)
        self.RegionFeaturesCleanBlocksDivision.connect(
            self._opDivFeats.CleanBlocks)
        self.BlockwiseRegionFeaturesDivision.connect(self._opDivFeats.Output)

        self._opDivFeatsAdaptOutput.Input.connect(self._opDivFeats.Output)
        self.RegionFeaturesDivision.connect(self._opDivFeatsAdaptOutput.Output)

        # As soon as input data is available, check its constraints
        self.RawImage.notifyReady(self._checkConstraints)
        self.BinaryImage.notifyReady(self._checkConstraints)

        # FIXME this shouldn't be done in post-filtering, but in reading the config or around that time
        self.RawImage.notifyReady(self._filterFeaturesByDim)
Exemplo n.º 9
0
    def __init__(self, parent):
        super(OpTrackingFeatureExtraction, self).__init__(parent)

        # internal operators
        self._objectExtraction = OpObjectExtraction(parent=self)

        self._opDivFeats = OpCachedDivisionFeatures(parent=self)
        self._opDivFeatsAdaptOutput = OpAdaptTimeListRoi(parent=self)

        # connect internal operators
        self._objectExtraction.RawImage.connect(self.RawImage)
        self._objectExtraction.BinaryImage.connect(self.BinaryImage)

        self._objectExtraction.Features.connect(self.FeatureNamesVigra)
        self._objectExtraction.LabelInputHdf5.connect(self.LabelInputHdf5)
        self._objectExtraction.RegionFeaturesCacheInput.connect(
            self.RegionFeaturesCacheInputVigra)
        self.LabelOutputHdf5.connect(self._objectExtraction.LabelOutputHdf5)
        self.CleanLabelBlocks.connect(self._objectExtraction.CleanLabelBlocks)
        self.RegionFeaturesCleanBlocksVigra.connect(
            self._objectExtraction.RegionFeaturesCleanBlocks)
        self.ObjectCenterImage.connect(
            self._objectExtraction.ObjectCenterImage)
        self.LabelImage.connect(self._objectExtraction.LabelImage)
        self.BlockwiseRegionFeaturesVigra.connect(
            self._objectExtraction.BlockwiseRegionFeatures)
        self.ComputedFeatureNamesVigra.connect(
            self._objectExtraction.ComputedFeatureNames)
        self.RegionFeaturesVigra.connect(self._objectExtraction.RegionFeatures)

        self._opDivFeats.LabelImage.connect(self.LabelImage)
        self._opDivFeats.DivisionFeatureNames.connect(
            self.FeatureNamesDivision)
        self._opDivFeats.CacheInput.connect(
            self.RegionFeaturesCacheInputDivision)
        self._opDivFeats.RegionFeaturesVigra.connect(
            self._objectExtraction.BlockwiseRegionFeatures)
        self.RegionFeaturesCleanBlocksDivision.connect(
            self._opDivFeats.CleanBlocks)
        self.BlockwiseRegionFeaturesDivision.connect(self._opDivFeats.Output)

        self._opDivFeatsAdaptOutput.Input.connect(self._opDivFeats.Output)
        self.RegionFeaturesDivision.connect(self._opDivFeatsAdaptOutput.Output)

        # As soon as input data is available, check its constraints
        self.RawImage.notifyReady(self._checkConstraints)
        self.BinaryImage.notifyReady(self._checkConstraints)
    def __init__(self, parent):
        super(OpRelabeledMergerFeatureExtraction, self).__init__(parent)

        # TODO: uncached! combine old and new features for export

        # internal operators
        self._opMergersOnly = OpDifference(parent=self)
        self._opMergersOnly.ImageA.connect(self.LabelImage)
        self._opMergersOnly.ImageB.connect(self.RelabeledImage)

        self._opZeroBasedMergerImage = OpZeroBasedConsecutiveIndexRelabeling(parent=self)
        self._opZeroBasedMergerImage.LabelImage.connect(self._opMergersOnly.Output)

        self._opRegionFeatures = OpRegionFeatures(parent=self)
        self._opRegionFeatures.RawVolume.connect(self.RawImage)
        self._opRegionFeatures.LabelVolume.connect(self._opZeroBasedMergerImage.Output)
        self._opRegionFeatures.Features.connect(self.FeatureNames)

        self._opAdaptTimeListRoi = OpAdaptTimeListRoi(parent=self)
        self._opAdaptTimeListRoi.Input.connect(self._opRegionFeatures.Output)
        self.RegionFeaturesVigra.connect(self._opAdaptTimeListRoi.Output)