def testWithCustomBackground(self): graph = Graph() # OpDummyData needs an input array to decide what shape/dtype/axes to make the output a = numpy.ndarray(shape=(2, 100, 100, 100, 3), dtype=numpy.uint32) v = a.view(vigra.VigraArray) v.axistags = vigra.defaultAxistags('txyzc') # OpDummyData provides a simple binary image with a bunch of thick diagonal planes. opData = OpDummyData(graph=graph) opData.Input.setValue(v) assert opData.Output.ready() assert opData.Output.meta.axistags is not None # Each diagonal plane should get it's own label... op = OpCachedLabelImage(graph=graph) op.Input.connect(opData.Output) op.BackgroundLabels.setValue( [0, 1, 0]) # Use inverted background for the second channel assert op.Output.ready() data = opData.Output[:].wait() labels = op.Output[:].wait() channel = 0 #logger.debug( "data-c0:\n{}".format( str(data[0,:80:5,:80:5,0,channel])) ) #logger.debug( "labels-c0:\n{}".format( str(labels[0,:80:5,:80:5,0,channel])) ) channel = 1 #logger.debug( "data-c1:\n{}".format( str(data[0,:80:5,:80:5,0,channel])) ) #logger.debug( "labels-c1:\n{}".format( str(labels[0,:80:5,:80:5,0,channel])) ) assert labels[0, 0, 0, 0, 0] == 1 assert labels[ 0, 0, 0, 0, 1] == 0, "Expected inverted background for the second channel"
class OpBlockwiseFilesetReader(Operator): """ Adapter that provides an operator interface to the BlockwiseFileset class for reading ONLY. """ name = "OpBlockwiseFilesetReader" DescriptionFilePath = InputSlot(stype="filestring") Output = OutputSlot() class MissingDatasetError(Exception): pass def __init__(self, *args, **kwargs): super(OpBlockwiseFilesetReader, self).__init__(*args, **kwargs) self._blockwiseFileset = None self._opDummyData = OpDummyData(parent=self) def setupOutputs(self): if not os.path.exists(self.DescriptionFilePath.value): raise OpBlockwiseFilesetReader.MissingDatasetError( "Dataset description not found: {}".format( self.DescriptionFilePath.value)) # Load up the class that does the real work self._blockwiseFileset = BlockwiseFileset( self.DescriptionFilePath.value) # Check for errors in the description file descriptionFields = self._blockwiseFileset.description axes = descriptionFields.axes assert False not in [ a in "txyzc" for a in axes ], "Unknown axis type. Known axes: txyzc Your axes:".format(axes) self.Output.meta.shape = tuple(descriptionFields.view_shape) self.Output.meta.dtype = descriptionFields.dtype self.Output.meta.axistags = vigra.defaultAxistags( str(descriptionFields.axes)) drange = descriptionFields.drange if drange is not None: self.Output.meta.drange = drange def execute(self, slot, subindex, roi, result): assert slot == self.Output, "Unknown output slot" try: self._blockwiseFileset.readData((roi.start, roi.stop), result) except BlockwiseFileset.BlockNotReadyError: result[:] = self._opDummyData.execute(slot, subindex, roi, result) return result def propagateDirty(self, slot, subindex, roi): assert slot == self.DescriptionFilePath, "Unknown input slot." self.Output.setDirty(slice(None)) def cleanUp(self): if self._blockwiseFileset is not None: self._blockwiseFileset.close() super(OpBlockwiseFilesetReader, self).cleanUp()
class OpBlockwiseFilesetReader(Operator): """ Adapter that provides an operator interface to the BlockwiseFileset class for reading ONLY. """ name = "OpBlockwiseFilesetReader" DescriptionFilePath = InputSlot(stype="filestring") Output = OutputSlot() class MissingDatasetError(Exception): pass def __init__(self, *args, **kwargs): super(OpBlockwiseFilesetReader, self).__init__(*args, **kwargs) self._blockwiseFileset = None self._opDummyData = OpDummyData(parent=self) def setupOutputs(self): if not os.path.exists(self.DescriptionFilePath.value): raise OpBlockwiseFilesetReader.MissingDatasetError( "Dataset description not found: {}".format(self.DescriptionFilePath.value) ) # Load up the class that does the real work self._blockwiseFileset = BlockwiseFileset(self.DescriptionFilePath.value) # Check for errors in the description file descriptionFields = self._blockwiseFileset.description axes = descriptionFields.axes assert False not in map( lambda a: a in "txyzc", axes ), "Unknown axis type. Known axes: txyzc Your axes:".format(axes) self.Output.meta.shape = tuple(descriptionFields.view_shape) self.Output.meta.dtype = descriptionFields.dtype self.Output.meta.axistags = vigra.defaultAxistags(descriptionFields.axes) drange = descriptionFields.drange if drange is not None: self.Output.meta.drange = drange def execute(self, slot, subindex, roi, result): assert slot == self.Output, "Unknown output slot" try: self._blockwiseFileset.readData((roi.start, roi.stop), result) except BlockwiseFileset.BlockNotReadyError: result[:] = self._opDummyData.execute(slot, subindex, roi, result) return result def propagateDirty(self, slot, subindex, roi): assert slot == self.DescriptionFilePath, "Unknown input slot." self.Output.setDirty(slice(None)) def cleanUp(self): if self._blockwiseFileset is not None: self._blockwiseFileset.close() super(OpBlockwiseFilesetReader, self).cleanUp()
def testBasic(self): graph = Graph() # OpDummyData needs an input array to decide what shape/dtype/axes to make the output a = numpy.ndarray(shape=(2, 100, 100, 100, 3), dtype=numpy.uint32) v = a.view(vigra.VigraArray) v.axistags = vigra.defaultAxistags('txyzc') # OpDummyData provides a simple binary image with a bunch of thick diagonal planes. opData = OpDummyData(graph=graph) opData.Input.setValue(v) assert opData.Output.ready() assert opData.Output.meta.axistags is not None data = opData.Output[:].wait() #logger.debug( "data:\n{}".format( str(data[0,:80:5,:80:5,0,0])) ) # Each diagonal plane should get it's own label... op = OpCachedLabelImage(graph=graph) op.Input.connect(opData.Output) assert op.Output.ready() labels = op.Output[:].wait()
def __init__(self, *args, **kwargs): super(OpBlockwiseFilesetReader, self).__init__(*args, **kwargs) self._blockwiseFileset = None self._opDummyData = OpDummyData(parent=self)
def __init__(self, *args, **kwargs): super(OpBlockwiseFilesetReader, self).__init__(*args, **kwargs) self._blockwiseFileset = None self._opDummyData = OpDummyData( parent=self )
def __init__(self, *args, **kwargs): super(OpExportedImageProvider, self).__init__(*args, **kwargs) self._opReader = None self._opDummyData = OpDummyData(parent=self)