Esempio n. 1
0
    def __call__(self, data: Any):
        if self.depth:
            img, seg = create_test_image_3d(
                self.height,
                self.width,
                self.depth,
                self.num_objs,
                self.rad_max,
                self.rad_min,
                self.noise_max,
                self.num_seg_classes,
                self.channel_dim,
                self.random_state,
            )
        else:
            img, seg = create_test_image_2d(
                self.height,
                self.width,
                self.num_objs,
                self.rad_max,
                self.rad_min,
                self.noise_max,
                self.num_seg_classes,
                self.channel_dim,
                self.random_state,
            )

        return img, seg
Esempio n. 2
0
    def setUp(self):
        im, msk = create_test_image_2d(self.im_shape[0], self.im_shape[1], 4,
                                       20, 0, self.num_classes)

        self.imt = im[None, None]
        self.seg1 = (msk[None, None] > 0).astype(np.float32)
        self.segn = msk[None, None]
Esempio n. 3
0
 def __getitem__(self, _unused_id):
     im, seg = create_test_image_2d(128,
                                    128,
                                    noise_max=1,
                                    num_objs=4,
                                    num_seg_classes=1)
     return im[None], seg[None].astype(np.float32)
Esempio n. 4
0
 def test_make_nifti(self, params):
     im, _ = create_test_image_2d(100, 88)
     created_file = make_nifti_image(im, verbose=True, **params)
     self.assertTrue(os.path.isfile(created_file))
Esempio n. 5
0
from unittest.case import skipUnless

import torch
from parameterized import parameterized

from monai.data.synthetic import create_test_image_2d, create_test_image_3d
from monai.transforms.utils_pytorch_numpy_unification import moveaxis
from monai.utils.module import optional_import
from monai.visualize.utils import blend_images
from tests.utils import TEST_NDARRAYS

plt, has_matplotlib = optional_import("matplotlib.pyplot")

TESTS = []
for p in TEST_NDARRAYS:
    image, label = create_test_image_2d(100, 101)
    TESTS.append((p(image), p(label)))

    image, label = create_test_image_3d(100, 101, 102)
    TESTS.append((p(image), p(label)))


@skipUnless(has_matplotlib, "Matplotlib required")
class TestBlendImages(unittest.TestCase):
    @parameterized.expand(TESTS)
    def test_blend(self, image, label):
        blended = blend_images(image[None], label[None])
        self.assertEqual(type(image), type(blended))
        if isinstance(blended, torch.Tensor):
            self.assertEqual(blended.device, image.device)
            blended = blended.cpu().numpy()
Esempio n. 6
0
from monai.data.synthetic import create_test_image_2d, create_test_image_3d
from monai.transforms.utils_pytorch_numpy_unification import moveaxis
from monai.utils.module import optional_import
from monai.visualize.utils import blend_images
from tests.utils import TEST_NDARRAYS

plt, has_matplotlib = optional_import("matplotlib.pyplot")


def get_alpha(img):
    return 0.5 * np.arange(img.size).reshape(img.shape) / img.size


TESTS = []
for p in TEST_NDARRAYS:
    image, label = create_test_image_2d(100, 101, channel_dim=0)
    TESTS.append((p(image), p(label), 0.5))
    TESTS.append((p(image), p(label), p(get_alpha(image))))

    image, label = create_test_image_3d(100, 101, 102, channel_dim=0)
    TESTS.append((p(image), p(label), 0.5))
    TESTS.append((p(image), p(label), p(get_alpha(image))))


@skipUnless(has_matplotlib, "Matplotlib required")
class TestBlendImages(unittest.TestCase):
    @parameterized.expand(TESTS)
    def test_blend(self, image, label, alpha):
        blended = blend_images(image, label, alpha)
        self.assertEqual(type(image), type(blended))
        if isinstance(blended, torch.Tensor):