コード例 #1
0
    def test2(self):
        import ants
        import numpy as np

        rgb_img = ants.from_numpy(np.random.randint(
            0, 255, (20, 20, 3)).astype('uint8'),
                                  is_rgb=True)
        vec_img = rgb_img.rgb_to_vector()
        print(ants.allclose(rgb_img, vec_img))

        vec_img = ants.from_numpy(np.random.randint(
            0, 255, (20, 20, 3)).astype('uint8'),
                                  has_components=True)
        rgb_img = vec_img.vector_to_rgb()
        print(ants.allclose(rgb_img, vec_img))
コード例 #2
0
    def test_matrix_to_images(self):
        # def matrix_to_images(data_matrix, mask):
        for img in self.imgs:
            imgmask = img > img.mean()
            data = img[imgmask]
            dataflat = data.reshape(1, -1)
            mat = np.vstack([dataflat, dataflat]).astype('float32')
            imglist = ants.matrix_to_images(mat, imgmask)
            nptest.assert_allclose((img * imgmask).numpy(), imglist[0].numpy())
            nptest.assert_allclose((img * imgmask).numpy(), imglist[1].numpy())
            self.assertTrue(
                ants.image_physical_space_consistency(img, imglist[0]))
            self.assertTrue(
                ants.image_physical_space_consistency(img, imglist[1]))

            # go back to matrix
            mat2 = ants.images_to_matrix(imglist, imgmask)
            nptest.assert_allclose(mat, mat2)

            # test with matrix.ndim > 2
            img = img.clone()
            img.set_direction(img.direction * 2)
            imgmask = img > img.mean()
            arr = (img * imgmask).numpy()
            arr = arr[arr > 0.5]
            arr2 = arr.copy()
            mat = np.stack([arr, arr2])
            imglist = ants.matrix_to_images(mat, imgmask)
            for im in imglist:
                self.assertTrue(ants.allclose(im, imgmask * img))
                self.assertTrue(
                    ants.image_physical_space_consistency(im, imgmask))
コード例 #3
0
    def test_Rotate3D(self):
        for img in self.imgs_3d:
            imgclone = img.clone()
            tx = ants.contrib.Rotate3D((10, -5, 12))
            img_zoom = tx.transform(img)

            # physical space shouldnt change .. ?
            self.assertTrue(
                ants.image_physical_space_consistency(img, img_zoom))
            # assert no unintended changes to passed-in img
            self.assertTrue(
                ants.image_physical_space_consistency(img, imgclone))
            self.assertTrue(ants.allclose(img, imgclone))

            # apply to cloned image to ensure deterministic nature
            img_zoom2 = tx.transform(imgclone)
            self.assertTrue(
                ants.image_physical_space_consistency(img_zoom, img_zoom2))
            self.assertTrue(ants.allclose(img_zoom, img_zoom2))
コード例 #4
0
 def test_allclose(self):
     for img in self.imgs:
         img2 = img.clone()
         self.assertTrue(ants.allclose(img,img2))
         self.assertTrue(ants.allclose(img*6.9, img2*6.9))
         self.assertTrue(not ants.allclose(img, img2*6.9))