def testOutputCrash(self): """ Bare-minimum test: Just make sure we can request the output without crashing. """ slicing = sl[0:1, 0:5, 6:20, 30:40, 0:1] result = self.op.Output[slicing].wait() assert result.shape == slicing2shape(slicing)
def testDeleteLabel2(self): """ Another test to check behavior after deleting an entire label class from the sparse array. This one ensures that different blocks have different max label values before the delete occurs. """ op = self.op slicing = self.slicing data = self.data assert op.maxLabel.value == 2 # Choose slicings that do NOT intersect with any of the previous data or with each other # The goal is to make sure that the data for each slice ends up in a separate block slicing1 = sl[0:1, 60:65, 0:10, 3:7, 0:1] slicing2 = sl[0:1, 90:95, 0:90, 3:7, 0:1] expectedData = self.data[...] labels1 = numpy.ndarray(slicing2shape(slicing1), dtype=numpy.uint8) labels1[...] = 1 op.Input[slicing1] = labels1 expectedData[slicing1] = labels1 labels2 = numpy.ndarray(slicing2shape(slicing2), dtype=numpy.uint8) labels2[...] = 2 op.Input[slicing2] = labels2 expectedData[slicing2] = labels2 # Sanity check: # Does the data contain our new labels? assert (op.Output[...].wait() == expectedData).all() assert expectedData.max() == 2 assert op.maxLabel.value == 2 # Delete label 1 op.deleteLabel.setValue(1) outputData = op.Output[...].wait() # Expected: All 1s removed, all 2s converted to 1s expectedData = numpy.where(expectedData == 1, 0, expectedData) expectedData = numpy.where(expectedData == 2, 1, expectedData) assert (outputData[...] == expectedData[...]).all() assert op.maxLabel.value == expectedData.max() == 1
def testWithSeeds(self): """ Bare-minimum test: Just make sure we can request the output without crashing. """ seeds = numpy.zeros( self.inputData.shape, dtype=numpy.uint32 ) self.op.SeedImage.setValue( seeds ) slicing = sl[0:1, 0:5, 6:20, 30:40, 0:1] result = self.op.Output[slicing].wait() assert result.shape == slicing2shape(slicing)
def testEraseAll(self): """ Test behavior when all labels of a particular class are erased. Note that this is not the same as deleting a label class, but should have the same effect on the output slots. """ op = self.op slicing = self.slicing data = self.data assert op.maxLabel.value == 2 newSlicing = list(slicing) newSlicing[1] = slice(1,2) # Add some new labels for a class that hasn't been seen yet (3) threeData = numpy.ndarray(slicing2shape(newSlicing), dtype=numpy.uint8) threeData[...] = 3 op.Input[newSlicing] = threeData expectedData = data[...] expectedData[newSlicing] = 3 # Sanity check: Are the new labels in the data? assert (op.Output[...].wait() == expectedData).all() assert expectedData.max() == 3 assert op.maxLabel.value == 3 # Now erase all the 3s eraserData = numpy.ones(slicing2shape(newSlicing), dtype=numpy.uint8) * 100 op.Input[newSlicing] = eraserData expectedData = data[...] expectedData[newSlicing] = 0 # The data we erased should be zeros assert (op.Output[...].wait() == expectedData).all() # The maximum label should be reduced, because all the 3s were removed. assert expectedData.max() == 2 assert op.maxLabel.value == 2
def testWithFullSeeds(self): """ If every pixel is seeded, there's nothing for the watershed to do. Output should be a copy of the seeds """ # Random seed data seeds = 4 * numpy.random.random( self.inputData.shape ) seeds = seeds.astype(numpy.uint32) seeds += 1 self.op.SeedImage.setValue( seeds ) slicing = sl[0:1, 0:5, 6:20, 30:40, 0:1] result = self.op.Output[slicing].wait() assert result.shape == slicing2shape(slicing) assert (result == seeds[slicing]).all()
def setup(self): graph = Graph() op = OpSparseLabelArray(graph=graph) arrayshape = numpy.array([1,10,10,10,1]) op.inputs["shape"].setValue( arrayshape ) op.eraser.setValue(100) slicing = sl[0:1, 1:5, 2:6, 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 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 __getitem__( self, slicing ): sl3d = (slicing[1], slicing[2], slicing[3]) ret = np.zeros(slicing2shape(slicing), dtype=self.dtype) ret[0,:,:,:,0] = self.a[tuple(sl3d)] return ret