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)
def setUp(self): g = Graph() self.op = OpObjectExtraction(graph=g) # Raw image is arbitrary for our purposes. Just re-use the # label image rm = rawImage() rm = rm[:, :, :, 0:1, :] self.op.RawImage.setValue(rm) self.Features_standard = FEATURES self.Features_convex_hull = { "2D Convex Hull Features": { "HullVolume": {}, "DefectVolumeKurtosis": {} } } self.Features_skeleton = { "2D Skeleton Features": { "Diameter": {}, "Total Length": {} } } # self.op.Features.setValue(FEATURES) bm = binaryImage() bm = bm[:, :, :, 0:1, :] self.op.BinaryImage.setValue(bm)
class TestPlugins(object): def setUp(self): g = Graph() self.op = OpObjectExtraction(graph=g) # Raw image is arbitrary for our purposes. Just re-use the # label image rm = rawImage() rm = rm[:, :, :, 0:1, :] self.op.RawImage.setValue(rm) self.Features_standard = FEATURES self.Features_convex_hull = { '2D Convex Hull Features': { 'HullVolume': {}, 'DefectVolumeKurtosis': {} } } self.Features_skeleton = { '2D Skeleton Features': { 'Diameter': {}, 'Total Length': {} } } #self.op.Features.setValue(FEATURES) bm = binaryImage() bm = bm[:, :, :, 0:1, :] self.op.BinaryImage.setValue(bm) def test_plugins(self): self.op.Features.setValue(self.Features_standard) feats = self.op.RegionFeatures([0]).wait() self.op.Features.setValue(self.Features_convex_hull) feats = self.op.RegionFeatures([0]).wait() self.op.Features.setValue(self.Features_skeleton) feats = self.op.RegionFeatures([0]).wait()
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()
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<Minimum>":{}, "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() self.classOp = OpObjectClassification(graph=g) self.classOp.BinaryImages.setValues([binimg]) self.classOp.SegmentationImages.setValues([segimg]) self.classOp.RawImages.setValues([rawimg]) self.classOp.LabelInputs.setValues([labels]) self.classOp.ObjectFeatures.connect(self.extrOp.RegionFeatures) self.classOp.ComputedFeatureNames.connect(self.extrOp.Features) self.classOp.SelectedFeatures.setValue(sel_features)
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)
def __init__(self): # Set memory and number of threads here #lazyflow.request.Request.reset_thread_pool(2) #Memory.setAvailableRam(500*1024**2) binary_img = binaryImage() raw_img = rawImage() g = Graph() # Reorder axis operators self.op5Raw = OpReorderAxes(graph=g) self.op5Raw.AxisOrder.setValue("txyzc") #self.op5Raw.Input.connect(self.opReaderRaw.OutputImage)#self.opReaderRaw.OutputImage) self.op5Raw.Input.setValue(raw_img) self.op5Binary = OpReorderAxes(graph=g) self.op5Binary.AxisOrder.setValue("txyzc") #self.op5Binary.Input.connect(self.opReaderBinary.OutputImage) self.op5Binary.Input.setValue(binary_img) # Cache operators self.opCacheRaw = OpBlockedArrayCache(graph=g) self.opCacheRaw.Input.connect(self.op5Raw.Output) self.opCacheRaw.BlockShape.setValue((1, ) + self.op5Raw.Output.meta.shape[1:]) self.opCacheBinary = OpBlockedArrayCache(graph=g) self.opCacheBinary.Input.connect(self.op5Binary.Output) self.opCacheBinary.BlockShape.setValue( (1, ) + self.op5Binary.Output.meta.shape[1:]) # Label volume operator self.opLabel = OpLabelVolume(graph=g) self.opLabel.Input.connect(self.op5Binary.Output) #self.opLabel.Input.connect(self.opCacheBinary.Output) # Object extraction self.opObjectExtraction = OpObjectExtraction(graph=g) self.opObjectExtraction.RawImage.connect(self.op5Raw.Output) self.opObjectExtraction.BinaryImage.connect(self.op5Binary.Output) self.opObjectExtraction.Features.setValue(FEATURES) # Simplified object features operator (No overhead) self.opObjectFeaturesSimp = OpObjectFeaturesSimplified(graph=g) self.opObjectFeaturesSimp.RawVol.connect(self.opCacheRaw.Output) self.opObjectFeaturesSimp.BinaryVol.connect(self.opCacheBinary.Output)
class TestFeatureSelection(unittest.TestCase): 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 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() def test_predict(self): rf = self.trainop.Classifier.value #pass a vector of 4 random features. vigra shouldn't complain #even though we computed more than 4 dummy_feats = np.zeros((1, 4), dtype=np.float32) dummy_feats[:] = 42 pred = rf.predict_probabilities(dummy_feats)
def setUpObjExtraction(self): opObjectExtraction = OpObjectExtraction(graph=self.graph) opObjectExtraction.RawImage.connect(self.rawSource.Output) opObjectExtraction.BinaryImage.connect(self.binarySource.Output) opObjectExtraction.BackgroundLabels.setValue([0]) opObjectExtraction.Features.setValue(self.testingFeatures) self.objExtraction = opObjectExtraction
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)
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)
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)
class ObjectExtractionTimeComparison(object): def __init__(self): # Set memory and number of threads here #lazyflow.request.Request.reset_thread_pool(2) #Memory.setAvailableRam(500*1024**2) binary_img = binaryImage() raw_img = rawImage() g = Graph() # Reorder axis operators self.op5Raw = OpReorderAxes(graph=g) self.op5Raw.AxisOrder.setValue("txyzc") #self.op5Raw.Input.connect(self.opReaderRaw.OutputImage)#self.opReaderRaw.OutputImage) self.op5Raw.Input.setValue(raw_img) self.op5Binary = OpReorderAxes(graph=g) self.op5Binary.AxisOrder.setValue("txyzc") #self.op5Binary.Input.connect(self.opReaderBinary.OutputImage) self.op5Binary.Input.setValue(binary_img) # Cache operators self.opCacheRaw = OpBlockedArrayCache(graph=g) self.opCacheRaw.Input.connect(self.op5Raw.Output) self.opCacheRaw.BlockShape.setValue((1, ) + self.op5Raw.Output.meta.shape[1:]) self.opCacheBinary = OpBlockedArrayCache(graph=g) self.opCacheBinary.Input.connect(self.op5Binary.Output) self.opCacheBinary.BlockShape.setValue( (1, ) + self.op5Binary.Output.meta.shape[1:]) # Label volume operator self.opLabel = OpLabelVolume(graph=g) self.opLabel.Input.connect(self.op5Binary.Output) #self.opLabel.Input.connect(self.opCacheBinary.Output) # Object extraction self.opObjectExtraction = OpObjectExtraction(graph=g) self.opObjectExtraction.RawImage.connect(self.op5Raw.Output) self.opObjectExtraction.BinaryImage.connect(self.op5Binary.Output) self.opObjectExtraction.Features.setValue(FEATURES) # Simplified object features operator (No overhead) self.opObjectFeaturesSimp = OpObjectFeaturesSimplified(graph=g) self.opObjectFeaturesSimp.RawVol.connect(self.opCacheRaw.Output) self.opObjectFeaturesSimp.BinaryVol.connect(self.opCacheBinary.Output) def run(self): # # Load caches beforehand (To remove overhead of reading frames) # with Timer() as timerCaches: # rawVol = self.opCacheRaw.Output([]).wait() # binaryVol = self.opCacheBinary.Output([]).wait() # # print "Caches took {} secs".format(timerCaches.seconds()) # # del rawVol # del binaryVol # Profile object extraction simplified print( "\nStarting object extraction simplified (single-thread, without cache)" ) with Timer() as timerObjectFeaturesSimp: featsObjectFeaturesSimp = self.opObjectFeaturesSimp.Features( []).wait() print("Simplified object extraction took: {} seconds".format( timerObjectFeaturesSimp.seconds())) # Profile object extraction optimized print("\nStarting object extraction (multi-thread, without cache)") with Timer() as timerObjectExtraction: featsObjectExtraction = self.opObjectExtraction.RegionFeatures( []).wait() print("Object extraction took: {} seconds".format( timerObjectExtraction.seconds())) # Profile for basic multi-threaded feature computation # just a multi-threaded loop that labels volumes and extract object features directly (No operators, no plugin system, no overhead, just a loop) featsBasicFeatureComp = dict.fromkeys( list(range(self.op5Raw.Output.meta.shape[0])), None) print("\nStarting basic multi-threaded feature computation") pool = RequestPool() for t in range(0, self.op5Raw.Output.meta.shape[0], 1): pool.add( Request( partial(self._computeObjectFeatures, t, featsBasicFeatureComp))) with Timer() as timerBasicFeatureComp: pool.wait() print( "Basic multi-threaded feature extraction took: {} seconds".format( timerBasicFeatureComp.seconds())) # Compute object features for single frame def _computeObjectFeatures(self, t, result): roi = [slice(None) for i in range(len(self.op5Raw.Output.meta.shape))] roi[0] = slice(t, t + 1) roi = tuple(roi) # rawVol = self.opCacheRaw.Output(roi).wait() # binaryVol = self.opCacheBinary.Output(roi).wait() rawVol = self.op5Raw.Output(roi).wait() binaryVol = self.op5Binary.Output(roi).wait() features = [ 'Count', 'Coord<Minimum>', 'RegionCenter', 'Coord<Principal<Kurtosis>>', 'Coord<Maximum>' ] for i in range(t, t + 1): labelVol = vigra.analysis.labelImageWithBackground( binaryVol[i - t].squeeze(), background_value=int(0)) res = vigra.analysis.extractRegionFeatures( rawVol[i - t].squeeze().astype(np.float32), labelVol.squeeze().astype(np.uint32), features, ignoreLabel=0) # Cleanup results (as done in vigra_objfeats) local_features = [x for x in features if "Global<" not in x] nobj = res[local_features[0]].shape[0] result[i] = cleanup(res, nobj, features)
def testTime(self): # Move the labels around different time steps. # Assert the same results gr = Graph() opExtract = OpObjectExtraction(graph=gr) opPredict = OpObjectClassification(graph=gr) opExtract.RawImage.setValue(self.rawimg) opExtract.BinaryImage.setValue(self.binimg) opExtract.Features.setValue(self.features) opPredict.RawImages.setValues([self.rawimg]) opPredict.BinaryImages.setValues([self.binimg]) opPredict.SegmentationImages.resize(1) opPredict.SegmentationImages[0].connect(opExtract.LabelImage) opPredict.ObjectFeatures.resize(1) opPredict.ObjectFeatures[0].connect(opExtract.RegionFeatures) opPredict.ComputedFeatureNames.connect(opExtract.Features) grT = Graph() opExtractT = OpObjectExtraction(graph=grT) opPredictT = OpObjectClassification(graph=grT) opExtractT.RawImage.setValue(self.rawimgt) opExtractT.BinaryImage.setValue(self.binimgt) opExtractT.Features.setValue(self.features) opPredictT.RawImages.setValues([self.rawimgt]) opPredictT.BinaryImages.setValues([self.binimgt]) opPredictT.SegmentationImages.resize(1) opPredictT.SegmentationImages[0].connect(opExtractT.LabelImage) opPredictT.ObjectFeatures.resize(1) opPredictT.ObjectFeatures[0].connect(opExtractT.RegionFeatures) opPredictT.ComputedFeatureNames.connect(opExtractT.Features) #run the workflow with the test blocks in the gui, #if you want to see why these labels are chosen #object 11 -small white square #object 27 -large grey square labelArray = numpy.zeros((28, )) labelArray[11] = 1 labelArray[27] = 2 labelDict = {0: labelArray} opPredict.LabelInputs.setValues([labelDict]) labelArray11 = numpy.zeros((12, )) labelArray11[11] = 1 labelArray27 = numpy.zeros((28, )) labelArray27[27] = 2 labelArray0 = numpy.zeros((2, )) labelDictT = { 0: labelArray0, 1: labelArray11, 2: labelArray0, 3: labelArray27 } opPredictT.LabelInputs.setValues([labelDictT]) #Predict by size selFeatures = {"Standard Object Features": {"Count": {}}} opPredict.SelectedFeatures.setValue(selFeatures) #[0][0] - first image, first time slice predictions = opPredict.Predictions[0][0].wait() predicted_labels = predictions[0] assert predicted_labels[0] == 0 assert numpy.all(predicted_labels[1:16] == 1) assert numpy.all(predicted_labels[16:] == 2) opPredictT.SelectedFeatures.setValue(selFeatures) predictionsT = opPredictT.Predictions[0][1].wait() predicted_labels_T = predictionsT[1] assert predicted_labels_T[0] == 0 assert numpy.all(predicted_labels_T[1:16] == 1) assert numpy.all(predicted_labels_T[16:] == 2) #Predict by color selFeatures = {"Standard Object Features": {"Mean": {}}} opPredict.SelectedFeatures.setValue(selFeatures) predictions = opPredict.Predictions[0][0].wait() predicted_labels = predictions[0] assert predicted_labels[0] == 0 assert predicted_labels[1] == 1 assert predicted_labels[11] == 1 assert predicted_labels[16] == 1 assert predicted_labels[23] == 1 assert predicted_labels[2] == 2 assert predicted_labels[18] == 2 assert predicted_labels[24] == 2 assert predicted_labels[26] == 2 opPredictT.SelectedFeatures.setValue(selFeatures) predictionsT = opPredictT.Predictions[0][2].wait() predicted_labels_T = predictionsT[2] assert predicted_labels_T[0] == 0 assert predicted_labels_T[1] == 1 assert predicted_labels_T[11] == 1 assert predicted_labels_T[16] == 1 assert predicted_labels_T[23] == 1 assert predicted_labels_T[2] == 2 assert predicted_labels_T[18] == 2 assert predicted_labels_T[24] == 2 assert predicted_labels_T[26] == 2 #Predict by neighborhood color selFeatures = { "Standard Object Features": { "Mean in neighborhood": { "margin": (5, 5, 2) } } } opPredict.SelectedFeatures.setValue(selFeatures) predictions = opPredict.Predictions[0][0].wait() predicted_labels = predictions[0] assert predicted_labels[0] == 0 assert predicted_labels[1] == 1 assert predicted_labels[8] == 1 assert predicted_labels[24] == 1 assert predicted_labels[28] == 1 assert predicted_labels[9] == 2 assert predicted_labels[14] == 2 assert predicted_labels[26] == 2 assert predicted_labels[29] == 2 opPredictT.SelectedFeatures.setValue(selFeatures) predictionsT = opPredictT.Predictions[0][3].wait() predicted_labels_T = predictionsT[3] assert predicted_labels_T[0] == 0 assert predicted_labels_T[1] == 1 assert predicted_labels_T[8] == 1 assert predicted_labels_T[24] == 1 assert predicted_labels_T[28] == 1 assert predicted_labels_T[9] == 2 assert predicted_labels_T[14] == 2 assert predicted_labels_T[26] == 2 assert predicted_labels_T[29] == 2