def testFromDataset2(self): shape = (500, 500, 500) vol = np.zeros(shape, dtype=np.uint8) vol = vigra.taggedView(vol, axistags="zxy") centers = [(45, 15), (45, 350), (360, 50)] extent = (10, 10) shift = (1, 1) zrange = np.arange(0, 20) zsteps = np.arange(5, 455, 50) for x, y in centers: for z in zsteps: for t in zrange: sx = x + t * shift[0] sy = y + t * shift[1] vol[zsteps + t, sx - extent[0] : sx + extent[0], sy - extent[0] : sy + extent[0]] = 255 vol = vol.withAxes(*"zyx") # step by step op = OpLazyCC(graph=Graph()) op.Input.setValue(vol) op.ChunkShape.setValue((64, 64, 64)) out1 = np.zeros(op.Output.meta.shape, dtype=op.Output.meta.dtype) for z in reversed(list(range(500))): out1[..., z : z + 1] = op.Output[..., z : z + 1].wait() vigra.writeHDF5(out1, "/tmp/data.h5", "data") out2 = vigra.analysis.labelVolumeWithBackground(vol) assertEquivalentLabeling(out1.view(np.ndarray), out2.view(np.ndarray))
def testFromDataset2(self): shape = (500, 500, 500) vol = np.zeros(shape, dtype=np.uint8) vol = vigra.taggedView(vol, axistags="zxy") centers = [(45, 15), (45, 350), (360, 50)] extent = (10, 10) shift = (1, 1) zrange = np.arange(0, 20) zsteps = np.arange(5, 455, 50) for x, y in centers: for z in zsteps: for t in zrange: sx = x + t * shift[0] sy = y + t * shift[1] vol[zsteps + t, sx - extent[0]:sx + extent[0], sy - extent[0]:sy + extent[0]] = 255 vol = vol.withAxes(*"zyx") # step by step op = OpLazyCC(graph=Graph()) op.Input.setValue(vol) op.ChunkShape.setValue((64, 64, 64)) out1 = np.zeros(op.Output.meta.shape, dtype=op.Output.meta.dtype) for z in reversed(list(range(500))): out1[..., z:z + 1] = op.Output[..., z:z + 1].wait() vigra.writeHDF5(out1, "/tmp/data.h5", "data") out2 = vigra.analysis.labelVolumeWithBackground(vol) assertEquivalentLabeling(out1.view(np.ndarray), out2.view(np.ndarray))
def testSingletonZ(self): vol = np.zeros((82, 70, 1, 5, 5), dtype=np.uint8) vol = vigra.taggedView(vol, axistags='xyzct') blocks = np.zeros(vol.shape, dtype=np.uint8) blocks[30:50, 40:60, :, 2:4, 3:5] = 1 blocks[30:50, 40:60, :, 2:4, 0:2] = 2 blocks[60:70, 30:40, :, :, :] = 3 vol[blocks == 1] = 255 vol[blocks == 2] = 255 vol[blocks == 3] = 255 op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) op.Input.setValue(vol) out = op.Output[...].wait() tags = op.Output.meta.getTaggedShape() print(tags) out = vigra.taggedView(out, axistags="".join([s for s in tags])) for c in range(out.shape[3]): for t in range(out.shape[4]): print("t={}, c={}".format(t, c)) assertEquivalentLabeling(blocks[..., c, t], out[..., c, t])
def testFromDataset(self): shape = (500, 500, 500) vol = np.zeros(shape, dtype=np.uint8) vol = vigra.taggedView(vol, axistags='zxy') centers = [(45, 15), (45, 350), (360, 50)] extent = (10, 10) shift = (1, 1) zrange = np.arange(0, 20) zsteps = np.arange(5, 455, 50) for x, y in centers: for z in zsteps: for t in zrange: sx = x+t*shift[0] sy = y+t*shift[1] vol[zsteps + t, sx-extent[0]:sx+extent[0], sy-extent[0]:sy+extent[0]] = 255 vol = vol.withAxes(*'zyx') # all at once op = OpLazyCC(graph=Graph()) op.Input.setValue(vol) op.ChunkShape.setValue((64, 64, 64)) out1 = op.Output[...].wait() out2 = vigra.analysis.labelVolumeWithBackground(vol) assertEquivalentLabeling(out1.view(np.ndarray), out2.view(np.ndarray))
def testFromDataset(self): shape = (500, 500, 500) vol = np.zeros(shape, dtype=np.uint8) vol = vigra.taggedView(vol, axistags='zxy') centers = [(45, 15), (45, 350), (360, 50)] extent = (10, 10) shift = (1, 1) zrange = np.arange(0, 20) zsteps = np.arange(5, 455, 50) for x, y in centers: for z in zsteps: for t in zrange: sx = x+t*shift[0] sy = y+t*shift[1] vol[zsteps + t, sx-extent[0]:sx+extent[0], sy-extent[0]:sy+extent[0]] = 255 vol = vol.withAxes(*'xyz') # all at once op = OpLazyCC(graph=Graph()) op.Input.setValue(vol) op.ChunkShape.setValue((64, 64, 64)) out1 = op.Output[...].wait() out2 = vigra.analysis.labelVolumeWithBackground(vol) assertEquivalentLabeling(out1.view(np.ndarray), out2.view(np.ndarray))
def testCorrectLabeling(self): vol = np.zeros((1000, 100, 10)) vol = vol.astype(np.uint8) vol = vigra.taggedView(vol, axistags="zyx") vol[20:40, 10:30, 2:4] = 1 op = OpLazyCC(graph=Graph()) op.Input.setValue(vol) op.ChunkShape.setValue((100, 10, 10)) out = op.Output[...].wait() out = vigra.taggedView(out, axistags=op.Output.meta.axistags) assertEquivalentLabeling(vol, out)
def testCorrectLabeling(self): vol = np.zeros((1000, 100, 10)) vol = vol.astype(np.uint8) vol = vigra.taggedView(vol, axistags="xyz") vol[20:40, 10:30, 2:4] = 1 op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) op.Input.setValue(vol) out = op.Output[...].wait() tags = op.Output.meta.getTaggedShape() out = vigra.taggedView(out, axistags="".join([s for s in tags])) assertEquivalentLabeling(vol, out)
def testCorrectLabeling(self): vol = np.zeros((1000, 100, 10)) vol = vol.astype(np.uint8) vol = vigra.taggedView(vol, axistags='xyz') vol[20:40, 10:30, 2:4] = 1 op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) op.Input.setValue(vol) out = op.Output[...].wait() tags = op.Output.meta.getTaggedShape() out = vigra.taggedView(out, axistags="".join([s for s in tags])) assertEquivalentLabeling(vol, out)
def testSingletonZ(self): vol = np.zeros((1, 70, 82), dtype=np.uint8) vol = vigra.taggedView(vol, axistags="zyx") blocks = np.zeros(vol.shape, dtype=np.uint8) blocks[:, 30:50, 40:60] = 1 blocks[:, 60:70, 30:40] = 3 blocks = vigra.taggedView(blocks, axistags="zyx") vol[blocks > 0] = 255 op = OpLazyCC(graph=Graph()) op.ChunkShape.setValue((1, 25, 30)) op.Input.setValue(vol) out = op.Output[...].wait() out = vigra.taggedView(out, axistags=op.Output.meta.axistags) np.set_printoptions(threshold=sys.maxsize, linewidth=200) assertEquivalentLabeling(blocks, out)
def testSingletonZ(self): vol = np.zeros((1, 70, 82), dtype=np.uint8) vol = vigra.taggedView(vol, axistags="zyx") blocks = np.zeros(vol.shape, dtype=np.uint8) blocks[:, 30:50, 40:60] = 1 blocks[:, 60:70, 30:40] = 3 blocks = vigra.taggedView(blocks, axistags="zyx") vol[blocks > 0] = 255 op = OpLazyCC(graph=Graph()) op.ChunkShape.setValue((1, 25, 30)) op.Input.setValue(vol) out = op.Output[...].wait() out = vigra.taggedView(out, axistags=op.Output.meta.axistags) np.set_printoptions(threshold=np.nan, linewidth=200) assertEquivalentLabeling(blocks, out)
def testSingletonZ(self): vol = np.zeros((82, 70, 1), dtype=np.uint8) vol = vigra.taggedView(vol, axistags='xyz') blocks = np.zeros(vol.shape, dtype=np.uint8) blocks[30:50, 40:60, :] = 1 blocks[60:70, 30:40, :] = 3 blocks = vigra.taggedView(blocks, axistags='xyz') vol[blocks > 0] = 255 op = OpLazyCC(graph=Graph()) op.ChunkShape.setValue((30, 25, 1)) op.Input.setValue(vol) out = op.Output[...].wait() out = vigra.taggedView(out, axistags=op.Output.meta.axistags) np.set_printoptions(threshold=np.nan, linewidth=200) print(out[..., 0]) print(blocks[..., 0]) assertEquivalentLabeling(blocks, out)
def testDtypeUint16(self): vol = np.zeros((82, 70, 75, 5, 5), dtype=np.uint16) vol = vigra.taggedView(vol, axistags="xyzct") blocks = np.zeros(vol.shape, dtype=np.uint8) blocks[30:50, 40:60, 50:70, 2:4, 3:5] = 1 blocks[30:50, 40:60, 50:70, 2:4, 0:2] = 2 blocks[60:70, 30:40, 10:33, :, :] = 3 vol[blocks == 1] = 255 vol[blocks == 2] = 255 vol[blocks == 3] = 255 op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) op.Input.setValue(vol) out = op.Output[...].wait() tags = op.Output.meta.getTaggedShape() out = vigra.taggedView(out, axistags="".join([s for s in tags])) for c in range(out.shape[3]): for t in range(out.shape[4]): assertEquivalentLabeling(blocks[..., c, t], out[..., c, t])
def testBackground(self): vol = np.zeros((1000, 100, 10)) vol = vol.astype(np.uint8) vol = vigra.taggedView(vol, axistags='xyz') vol[20:40, 10:30, 2:4] = 1 op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) op.Background.setValue(1) op.Input.setValue(vol) out = op.Output[...].wait() tags = op.Output.meta.getTaggedShape() out = vigra.taggedView(out, axistags="".join([s for s in tags])) assert np.all(out[20:40, 10:30, 2:4] == 0) assertEquivalentLabeling(1-vol, out) vol = vol.withAxes(*'xyzct') vol = np.concatenate(3*(vol,), axis=3) vol = np.concatenate(4*(vol,), axis=4) vol = vigra.taggedView(vol, axistags='xyzct') assert len(vol.shape) == 5 assert vol.shape[3] == 3 assert vol.shape[4] == 4 #op = OpLabelVolume(graph=Graph()) op.Method.setValue(self.method) bg = np.asarray([[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 0, 1]], dtype=np.uint8) bg = vigra.taggedView(bg, axistags='ct') assert len(bg.shape) == 2 assert bg.shape[0] == 3 assert bg.shape[1] == 4 op.Background.setValue(bg) op.Input.setValue(vol) for c in range(bg.shape[0]): for t in range(bg.shape[1]): out = op.Output[..., c, t].wait() out = vigra.taggedView(out, axistags=op.Output.meta.axistags) if bg[c, t]: assertEquivalentLabeling(1-vol[..., c, t], out.squeeze()) else: assertEquivalentLabeling(vol[..., c, t], out.squeeze())