Beispiel #1
0
 def test_resample_numpy_copy_subvolume(self):
     """
     Simply copy a sub-volume
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (2, 3, 4), (4, 5, 6),
                       (1, 1, 1))
     t_expected = t[2:4, 3:5, 4:6]
     assert (t_r == t_expected).all()
Beispiel #2
0
 def test_resample_torch_id(self):
     """
     identity
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8))
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (0, 0, 0), (10, 9, 8),
                       (1, 1, 1),
                       interpolation_mode='nearest')
     assert np.abs(t.float() - t_r).max() < 1e-5
Beispiel #3
0
 def test_resample_torch_id(self):
     """
     identity
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8))
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (0, 0, 0), (10, 9, 8),
                       (1, 1, 1),
                       constant_value=42,
                       order=0)
     assert (t == t_r).all()
Beispiel #4
0
 def test_resample_numpy_copy_subvolume(self):
     """
     Simply copy a sub-volume
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (2, 3, 4), (4, 5, 6),
                       (1, 1, 1),
                       align_corners=False)
     t_expected = t[2:4, 3:5, 4:6]
     assert np.abs(t_r - t_expected).max() < 1e-5
Beispiel #5
0
    def test_resample_numpy_with_background(self):
        """
        Simply copy a sub-volume with background voxels
        """
        t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
        t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (2, 3, 4), (4, 5, 20),
                          (1, 1, 1),
                          constant_value=42)
        t_r_valid = t_r[:, :, :2]
        t_expected = t[2:4, 3:5, 4:6]
        assert (t_r_valid == t_expected).all()

        # outside voxel should be background value
        t_r_background = t_r[:, :, 4:]
        assert (t_r_background == 42).all()
Beispiel #6
0
    def test_resample_numpy_with_background(self):
        """
        Simply copy a sub-volume with background voxels
        """
        t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
        t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (2, 3, 4), (4, 5, 20),
                          (1, 1, 1),
                          align_corners=False)
        t_r_valid = t_r[:, :, :2]
        t_expected = t[2:4, 3:5, 4:6]
        assert np.abs((t_r_valid - t_expected)).max() < 1e-5

        # outside voxel should be background value
        t_r_background = t_r[:, :, 4:]
        assert (t_r_background == 0).all()
Beispiel #7
0
 def test_resample_numpy_interpolate_x(self):
     """
     Interpolate in x axis
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (0, 0, 0), (10, 9, 8),
                       (1, 1, 0.49999),
                       interpolation_mode='nearest')
     assert t_r.shape == (10, 9, 8 * 2)
     for z in range(t_r.shape[0]):
         for y in range(t_r.shape[1]):
             for x in range(t_r.shape[2] -
                            1):  # avoid the background value at the end
                 v = t_r[z, y, x]
                 v_expected = t[z, y, x // 2]
                 assert abs(v - v_expected) < 1e-4
Beispiel #8
0
 def test_resample_numpy_interpolate_x(self):
     """
     Interpolate in x axis
     """
     t = torch.arange(10 * 9 * 8).reshape((10, 9, 8)).numpy()
     t_r = resample_3d(t, (1, 1, 1), (0, 0, 0), (0, 0, 0), (10, 9, 8),
                       (1, 1, 0.49999),
                       constant_value=42,
                       order=0)
     assert t_r.shape == (10, 9, 8 * 2)
     for z in range(t_r.shape[0]):
         for y in range(t_r.shape[1]):
             for x in range(t_r.shape[2] -
                            1):  # avoid the background value at the end
                 v = t_r[z, y, x]
                 v_expected = t[z, y, x // 2]
                 assert v == v_expected