def __init__(self, *args, **kwargs): super(OpLabelPipeline, self).__init__(*args, **kwargs) self.opInputShapeReader = OpShapeReader(parent=self) self.opInputShapeReader.Input.connect(self.RawImage) self.opLabelArray = OpBlockedSparseLabelArray(parent=self) self.opLabelArray.Input.connect(self.LabelInput) self.opLabelArray.shape.connect(self.opInputShapeReader.OutputShape) self.opLabelArray.eraser.setValue(100) self.opBoxArray = OpBlockedSparseLabelArray(parent=self) self.opBoxArray.Input.connect(self.BoxLabelInput) self.opBoxArray.shape.connect(self.opInputShapeReader.OutputShape) self.opBoxArray.eraser.setValue(100) # Initialize the delete input to -1, which means "no label". # Now changing this input to a positive value will cause label deletions. # (The deleteLabel input is monitored for changes.) self.opLabelArray.deleteLabel.setValue(-1) # Connect external outputs to their internal sources self.Output.connect(self.opLabelArray.Output) self.nonzeroBlocks.connect(self.opLabelArray.nonzeroBlocks) self.MaxLabel.connect(self.opLabelArray.maxLabel) self.BoxOutput.connect(self.opBoxArray.Output)
def __init__(self, blockDims=None, *args, **kwargs): """ Instantiate all internal operators and connect them together. """ super(OpLabelingSingleLane, self).__init__(*args, **kwargs) # Configuration options if blockDims is None: blockDims = {'t': 1, 'x': 32, 'y': 32, 'z': 32, 'c': 1} assert isinstance(blockDims, dict) self._blockDims = blockDims # Create internal operators self.opInputShapeReader = OpShapeReader(parent=self) self.opLabelArray = OpBlockedSparseLabelArray(parent=self) # Set up label cache shape input self.opInputShapeReader.Input.connect(self.InputImage) # Note: 'shape' is a (poorly named) INPUT SLOT here self.opLabelArray.shape.connect(self.opInputShapeReader.OutputShape) # Set up other label cache inputs self.opLabelArray.Input.connect(self.LabelInput) self.opLabelArray.eraser.connect(self.LabelEraserValue) self.opLabelArray.deleteLabel.connect(self.LabelDelete) # Connect our internal outputs to our external outputs self.LabelImage.connect(self.opLabelArray.Output) self.NonzeroLabelBlocks.connect(self.opLabelArray.nonzeroBlocks) self.MaxLabelValue.connect(self.opLabelArray.maxLabel)
def setup(self): graph = Graph() op = OpBlockedSparseLabelArray(graph=graph) arrayshape = (1,100,100,10,1) op.inputs["shape"].setValue( arrayshape ) blockshape = (1,10,10,10,1) # Why doesn't this work if blockshape is an ndarray? op.inputs["blockShape"].setValue( blockshape ) op.eraser.setValue(100) dummyData = vigra.VigraArray(arrayshape, axistags=vigra.defaultAxistags('txyzc')) op.Input.setValue( dummyData ) slicing = sl[0:1, 1:15, 2:36, 3:7, 0:1] inDataShape = slicing2shape(slicing) inputData = ( 3*numpy.random.random(inDataShape) ).astype(numpy.uint8) op.Input[slicing] = inputData data = numpy.zeros(arrayshape, dtype=numpy.uint8) data[slicing] = inputData self.op = op self.slicing = slicing self.inData = inputData self.data = data
def test(self): graph = Graph() testVolumePath = 'tinyfib_volume.h5' # Unzip the data if necessary if not os.path.exists(testVolumePath): zippedTestVolumePath = testVolumePath + ".gz" assert os.path.exists(zippedTestVolumePath) os.system("gzip -d " + zippedTestVolumePath) assert os.path.exists(testVolumePath) f = h5py.File(testVolumePath, 'r') data = f['data'][...] data = data.view(vigra.VigraArray) data.axistags = vigra.defaultAxistags('txyzc') labels = f['labels'][...] assert data.shape[:-1] == labels.shape[:-1] assert labels.shape[-1] == 1 assert len(data.shape) == 5 f.close() scales = [0.3, 0.7, 1, 1.6, 3.5, 5.0, 10.0] featureIds = OpPixelFeaturesPresmoothed.DefaultFeatureIds # The following conditions cause this test to *usually* fail, but *sometimes* pass: # When using Structure Tensor EVs at sigma >= 3.5 (NaNs in feature matrix) # When using Gaussian Gradient Mag at sigma >= 3.5 (inf in feature matrix) # When using *any feature* at sigma == 10.0 (NaNs in feature matrix) # sigma: 0.3 0.7 1.0 1.6 3.5 5.0 10.0 selections = numpy.array([ [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], [False, False, False, False, True, False, False], # ST EVs [False, False, False, False, False, False, False], [False, False, False, False, False, False, False], # GGM [False, False, False, False, False, False, False] ]) opFeatures = OpPixelFeaturesPresmoothed(graph=graph) opFeatures.Input.setValue(data) opFeatures.Scales.setValue(scales) opFeatures.FeatureIds.setValue(featureIds) opFeatures.Matrix.setValue(selections) opTrain = OpTrainRandomForestBlocked(graph=graph) opTrain.Images.resize(1) opTrain.Images[0].connect(opFeatures.Output) opTrain.Labels.resize(1) opTrain.nonzeroLabelBlocks.resize(1) # This test only fails when this flag is True. use_sparse_label_storage = True if use_sparse_label_storage: opLabelArray = OpBlockedSparseLabelArray(graph=graph) opLabelArray.inputs["shape"].setValue(labels.shape) opLabelArray.inputs["blockShape"].setValue((1, 32, 32, 32, 1)) opLabelArray.inputs["eraser"].setValue(100) opTrain.nonzeroLabelBlocks[0].connect(opLabelArray.nonzeroBlocks) # Slice the label data into the sparse array storage opLabelArray.Input[...] = labels[...] opTrain.Labels[0].connect(opLabelArray.Output) else: # Skip the sparse storage operator and provide labels as one big block opTrain.Labels[0].setValue(labels) # One big block opTrain.nonzeroLabelBlocks.resize(1) opTrain.nonzeroLabelBlocks[0].setValue([[slice(None, None, None)] * 5]) # Sanity check: Make sure we configured the training operator correctly. readySlots = [slot.ready() for slot in opTrain.inputs.values()] assert all(readySlots) # Generate the classifier classifier = opTrain.Classifier.value