Example #1
0
    def testMargin(self):
        graph = Graph()
        vol = np.zeros((100, 110, 10), dtype=np.float32)
        # draw a big plus sign
        vol[50:70, :, :] = 1.0
        vol[:, 60:80, :] = 1.0
        vol = vigra.taggedView(vol, axistags="zyx").withAxes(*"tzyxc")
        labels = np.zeros((100, 110, 10), dtype=np.uint32)
        labels[45:75, 55:85, 3:4] = 1
        labels = vigra.taggedView(labels, axistags="zyx").withAxes(*"tzyxc")

        op = OpObjectsSegment(graph=graph)
        piper = OpArrayPiper(graph=graph)
        piper.Input.setValue(vol)
        op.Prediction.connect(piper.Output)
        op.LabelImage.setValue(labels)

        # without margin
        op.MarginZYX.setValue(np.asarray((0, 0, 0)))
        out = op.Output[...].wait()
        out = vigra.taggedView(out, axistags=op.Output.meta.axistags)
        out = out.withAxes(*"zyx")
        vol = vol.withAxes(*"zyx")
        assert_array_equal(out[50:70, 60:80, 3] > 0,
                           vol[50:70, 60:80, 3] > 0.5)
        assert np.all(out[:45, ...] == 0)

        # with margin
        op.MarginZYX.setValue(np.asarray((5, 5, 0)))
        out = op.Output[...].wait()
        out = vigra.taggedView(out, axistags=op.Output.meta.axistags)
        out = out.withAxes(*"zyx")
        assert_array_equal(out[45:75, 55:85, 3] > 0,
                           vol[45:75, 55:85, 3] > 0.5)
        assert np.all(out[:40, ...] == 0)
Example #2
0
        def testBB(self):
            graph = Graph()
            op = OpObjectsSegment(graph=graph)
            piper = OpArrayPiper(graph=graph)
            piper.Input.setValue(self.vol)
            op.Prediction.connect(piper.Output)
            op.LabelImage.setValue(self.labels)

            bbox = op.BoundingBoxes[0, ..., 0].wait()
            assert isinstance(bbox, dict)
Example #3
0
        def testFaulty(self):
            vec = vigra.taggedView(np.zeros((500, ), dtype=np.float32),
                                   axistags=vigra.defaultAxistags('x'))
            graph = Graph()
            op = OpObjectsSegment(graph=graph)
            piper = OpArrayPiper(graph=graph)
            piper.Input.setValue(vec)

            with self.assertRaises(AssertionError):
                op.Prediction.connect(piper.Output)
                op.LabelImage.connect(piper.Output)
    def testComplete(self):
        graph = Graph()
        op = OpObjectsSegment(graph=graph)
        piper = OpArrayPiper(graph=graph)
        piper.Input.setValue(self.vol)
        op.Prediction.connect(piper.Output)
        piper = OpArrayPiper(graph=graph)
        piper.Input.setValue(self.labels)
        op.LabelImage.connect(piper.Output)

        # get whole volume
        out = op.CachedOutput[...].wait()
        out = vigra.taggedView(out, axistags=op.Output.meta.axistags)

        # check whether no new blocks introduced
        mask = np.where(self.labels > 0, 0, 1)
        masked = out * mask
        assert_array_equal(masked, 0 * masked)

        # check whether the interior was labeled 1
        assert np.all(out[:, 22:38, 22:38, 22:38, :] > 0)
        assert np.all(out[:, 62:78, 62:78, 62:78, :] > 0)