Esempio n. 1
0
    def test_ill_case(self):
        rotate_fn = Rotate(10, True)
        with self.assertRaises(ValueError):  # wrong shape
            rotate_fn(self.imt)

        rotate_fn = Rotate(10, keep_size=False)
        with self.assertRaises(ValueError):  # wrong mode
            rotate_fn(self.imt[0], mode="trilinear")
    def test_ill_case(self):
        for p in TEST_NDARRAYS:
            rotate_fn = Rotate(10, True)
            with self.assertRaises(ValueError):  # wrong shape
                rotate_fn(p(self.imt))

            rotate_fn = Rotate(10, keep_size=False)
            with self.assertRaises(ValueError):  # wrong mode
                rotate_fn(p(self.imt[0]), mode="trilinear")
Esempio n. 3
0
    def test_correct_results(self, angle, keep_size, mode, padding_mode,
                             align_corners):
        rotate_fn = Rotate([angle, 0, 0], keep_size, mode, padding_mode,
                           align_corners)
        rotated = rotate_fn(self.imt[0])
        if keep_size:
            np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
        _order = 0 if mode == "nearest" else 1
        if padding_mode == "border":
            _mode = "nearest"
        elif padding_mode == "reflection":
            _mode = "reflect"
        else:
            _mode = "constant"

        expected = list()
        for channel in self.imt[0]:
            expected.append(
                scipy.ndimage.rotate(
                    channel,
                    -np.rad2deg(angle),
                    (1, 2),
                    not keep_size,
                    order=_order,
                    mode=_mode,
                    prefilter=False,
                ))
        expected = np.stack(expected).astype(np.float32)
        np.testing.assert_allclose(expected, rotated, atol=1e-1)
    def test_correct_results(self, im_type, angle, keep_size, mode,
                             padding_mode, align_corners):
        rotate_fn = Rotate([angle, 0, 0], keep_size, mode, padding_mode,
                           align_corners)
        rotated = rotate_fn(im_type(self.imt[0]))
        if keep_size:
            np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
        _order = 0 if mode == "nearest" else 1
        if padding_mode == "border":
            _mode = "nearest"
        elif padding_mode == "reflection":
            _mode = "reflect"
        else:
            _mode = "constant"

        expected = []
        for channel in self.imt[0]:
            expected.append(
                scipy.ndimage.rotate(channel,
                                     -np.rad2deg(angle), (1, 2),
                                     not keep_size,
                                     order=_order,
                                     mode=_mode,
                                     prefilter=False))
        expected = np.stack(expected).astype(np.float32)
        rotated = rotated.cpu() if isinstance(rotated,
                                              torch.Tensor) else rotated
        n_good = np.sum(np.isclose(expected, rotated, atol=1e-3))
        self.assertLessEqual(expected.size - n_good, 5,
                             "diff at most 5 pixels")
 def test_correct_shape(self, im_type, angle, mode, padding_mode,
                        align_corners):
     rotate_fn = Rotate(angle, True, align_corners=align_corners)
     rotated = rotate_fn(im_type(self.imt[0]),
                         mode=mode,
                         padding_mode=padding_mode)
     np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
Esempio n. 6
0
 def test_correct_shape(self, im_type, angle, mode, padding_mode, align_corners):
     rotate_fn = Rotate(angle, True, align_corners=align_corners, dtype=np.float64)
     im = im_type(self.imt[0])
     set_track_meta(False)
     rotated = rotate_fn(im, mode=mode, padding_mode=padding_mode)
     self.assertNotIsInstance(rotated, MetaTensor)
     np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
     set_track_meta(True)
     rotated = rotate_fn(im, mode=mode, padding_mode=padding_mode)
     np.testing.assert_allclose(self.imt[0].shape, rotated.shape)
     test_local_inversion(rotate_fn, rotated, im)
Esempio n. 7
0
 def test_correct_results(self, angle, spatial_axes, reshape, order, mode, cval, prefilter):
     rotate_fn = Rotate(angle, spatial_axes, reshape, order, mode, cval, prefilter)
     rotated = rotate_fn(self.imt[0])
     expected = list()
     for channel in self.imt[0]:
         expected.append(
             scipy.ndimage.rotate(
                 channel, angle, spatial_axes, reshape, order=order, mode=mode, cval=cval, prefilter=prefilter
             )
         )
     expected = np.stack(expected).astype(np.float32)
     self.assertTrue(np.allclose(expected, rotated))
Esempio n. 8
0
 def test_correct_shape(self, angle, order, mode, align_corners):
     rotate_fn = Rotate(angle, True, align_corners)
     rotated = rotate_fn(self.imt[0], interp_order=order, mode=mode)
     np.testing.assert_allclose(self.imt[0].shape, rotated.shape)