Ejemplo n.º 1
0
 def test_value(self):
     key = "img"
     for p in TEST_NDARRAYS:
         shifter = ShiftIntensityd(keys=[key], offset=1.0)
         result = shifter({key: p(self.imt)})
         expected = self.imt + 1.0
         assert_allclose(result[key], p(expected))
Ejemplo n.º 2
0
 def test_value(self):
     key = "img"
     factor = np.random.rand()
     offset = np.std(self.imt) * factor
     shifter = ShiftIntensityd(keys=[key], offset=offset)
     expected = shifter({key: self.imt})
     std_shifter = StdShiftIntensityd(keys=[key], factor=factor)
     result = std_shifter({key: self.imt})
     np.testing.assert_allclose(result[key], expected[key], rtol=1e-5)
Ejemplo n.º 3
0
    def test_factor(self):
        key = "img"
        stats = IntensityStatsd(keys=key, ops="max", key_prefix="orig")
        shifter = ShiftIntensityd(keys=[key], offset=1.0, factor_key=["orig_max"])
        data = {key: self.imt, PostFix.meta(key): {"affine": None}}

        result = shifter(stats(data))
        expected = self.imt + 1.0 * np.nanmax(self.imt)
        np.testing.assert_allclose(result[key], expected)
Ejemplo n.º 4
0
import os
import tempfile
import unittest

import nibabel as nib
import numpy as np
from parameterized import parameterized

from monai.data import CacheNTransDataset
from monai.transforms import LoadNiftid, ShiftIntensityd

TEST_CASE_1 = [
    [
        LoadNiftid(keys="image"),
        ShiftIntensityd(keys="image", offset=1.0),
        ShiftIntensityd(keys="image", offset=2.0),
        ShiftIntensityd(keys="image", offset=3.0),
    ],
    (128, 128, 128),
]


class TestCacheNTransDataset(unittest.TestCase):
    @parameterized.expand([TEST_CASE_1])
    def test_n_trans(self, transform, expected_shape):
        data_array = np.random.randint(0, 2, size=[128, 128, 128])
        test_image = nib.Nifti1Image(data_array, np.eye(4))
        with tempfile.TemporaryDirectory() as tempdir:
            nib.save(test_image, os.path.join(tempdir, "test_image.nii.gz"))
            test_data = [{"image": os.path.join(tempdir, "test_image.nii.gz")}]
Ejemplo n.º 5
0
 def test_value(self):
     key = "img"
     shifter = ShiftIntensityd(keys=[key], offset=1.0)
     result = shifter({key: self.imt})
     expected = self.imt + 1.0
     np.testing.assert_allclose(result[key], expected)