Exemple #1
0
    def runConvexHull(self, segimg, feats):
        # testing 2D Convex Hull features on a 2D image

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

        g = Graph()
        self.featsop = OpRegionFeatures(graph=g)
        self.featsop.LabelVolume.setValue(segimg)
        self.featsop.RawVolume.setValue(rawimg)
        self.featsop.Features.setValue(feats)
        output = self.featsop.Output([]).wait()

        return output
Exemple #2
0
    def setUp(self):
        g = Graph()
        self.features = {
            NAME: {
                "Count": {},
                "RegionCenter": {},
                "Mean": {},
                "Coord<Minimum>": {},
                "Coord<Maximum>": {},
                "Mean in neighborhood": {
                    "margin": (30, 30, 1)
                },
                "Sum": {},
                "Sum in neighborhood": {
                    "margin": (30, 30, 1)
                }
            }
        }

        binimage = binaryImage()
        self.rawimage = rawImage()
        self.labelop = OpLabelVolume(graph=g)
        self.op = OpRegionFeatures(graph=g)
        self.op.LabelVolume.connect(self.labelop.Output)
        self.op.RawVolume.setValue(self.rawimage)
        self.op.Features.setValue(self.features)
        self.img = binaryImage()
        self.labelop.Input.setValue(binimage)
Exemple #3
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)
Exemple #4
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))
Exemple #5
0
class TestConvexHull(unittest.TestCase):


    def test(self):
        # test 2D ConvexHull with 2D image
        segimg = segImage2D()
        feats = feats_2D

        feat_output = self.runConvexHull(segimg,feats)
        # print (feat_output[1]['2D Convex Hull Features'].values())

        self.assertTrue(bool(feat_output[1]['2D Convex Hull Features'].values()) == True)

        # test 2D ConvexHull with 3D image
        segimg = segImage3D()
        feats = feats_2D

        feat_output = self.runConvexHull(segimg,feats)
        # print (feat_output[1]['2D Convex Hull Features'].values())

        self.assertTrue(bool(feat_output[1]['2D Convex Hull Features'].values()) == False )

        # test 3D ConvexHull with 2D image
        segimg = segImage2D()
        feats = feats_3D

        feat_output = self.runConvexHull(segimg,feats)
        # print (feat_output[1]['3D Convex Hull Features'].values())

        self.assertTrue(bool(feat_output[1]['3D Convex Hull Features'].values()) == False)

        # test 3D ConvexHull with 3D image
        segimg = segImage3D()
        feats = feats_3D

        feat_output = self.runConvexHull(segimg,feats)
        # print (feat_output[1]['3D Convex Hull Features'].values())

        self.assertTrue(bool(feat_output[1]['3D Convex Hull Features'].values()) == True)



    def runConvexHull(self ,segimg ,feats):
        #testing 2D Convex Hull features on a 2D image

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


        g = Graph()
        self.featsop = OpRegionFeatures(graph=g)
        self.featsop.LabelVolume.setValue(segimg)
        self.featsop.RawVolume.setValue(rawimg)
        self.featsop.Features.setValue(feats)
        output = self.featsop.Output([]).wait()

        return output
Exemple #6
0
    def setUp(self):
        g = Graph()
        self.labelop = OpLabelVolume(graph=g)
        self.op = OpRegionFeatures(graph=g)
        self.op.LabelVolume.connect(self.labelop.Output)

        # Raw image is arbitrary for our purposes. Just re-use the
        # label image
        self.op.RawVolume.connect(self.labelop.Output)
        self.op.Features.setValue(FEATURES)
        self.img = binaryImage()
        self.labelop.Input.setValue(self.img)
    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
    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)