Beispiel #1
0
    def test_lambdad_slicing(self):
        for p in TEST_NDARRAYS:
            img = p(self.imt)
            data = {"img": img}

            def slice_func(x):
                return x[:, :, :6, ::2]

            lambd = Lambdad(keys=data.keys(), func=slice_func)
            expected = {}
            expected = slice_func(data["img"])
            out = lambd(data)
            out_img = out["img"]
            assert_allclose(expected, out_img, type_test=False)
            self.assertIsInstance(out_img, MetaTensor)
            self.assertEqual(len(out_img.applied_operations), 1)
            inv_img = lambd.inverse(out)["img"]
            self.assertIsInstance(inv_img, MetaTensor)
            self.assertEqual(len(inv_img.applied_operations), 0)
Beispiel #2
0
    def test_lambdad_slicing(self):
        img = self.imt
        data = dict()
        data["img"] = img

        def slice_func(x):
            return x[:, :, :6, ::-2]

        lambd = Lambdad(keys=data.keys(), func=slice_func)
        expected = dict()
        expected["img"] = slice_func(data["img"])
        self.assertTrue(np.allclose(expected["img"], lambd(data)["img"]))
Beispiel #3
0
    def test_lambdad_identity(self):
        img = self.imt
        data = dict()
        data["img"] = img

        def identity_func(x):
            return x

        lambd = Lambdad(keys=data.keys(), func=identity_func)
        expected = data
        expected["img"] = identity_func(data["img"])
        self.assertTrue(np.allclose(expected["img"], lambd(data)["img"]))
Beispiel #4
0
    def test_lambdad_slicing(self):
        for p in TEST_NDARRAYS:
            img = p(self.imt)
            data = {"img": img}

            def slice_func(x):
                return x[:, :, :6, ::2]

            lambd = Lambdad(keys=data.keys(), func=slice_func)
            expected = {}
            expected["img"] = slice_func(data["img"])
            assert_allclose(expected["img"], lambd(data)["img"])
    def test_lambdad_identity(self):
        for p in TEST_NDARRAYS:
            img = p(self.imt)
            data = {"img": img, "prop": 1.0}

            def noise_func(x):
                return x + 1.0

            expected = {"img": noise_func(data["img"]), "prop": 1.0}
            ret = Lambdad(keys=["img", "prop"], func=noise_func, overwrite=[True, False])(data)
            assert_allclose(expected["img"], ret["img"])
            assert_allclose(expected["prop"], ret["prop"])
Beispiel #6
0
    def test_lambdad_identity(self):
        img = self.imt
        data = {"img": img, "prop": 1.0}

        def noise_func(x):
            return x + 1.0

        expected = {"img": noise_func(data["img"]), "prop": 1.0}
        ret = Lambdad(keys=["img", "prop"],
                      func=noise_func,
                      overwrite=[True, False])(data)
        self.assertTrue(np.allclose(expected["img"], ret["img"]))
        self.assertTrue(np.allclose(expected["prop"], ret["prop"]))