Esempio n. 1
0
    def test_ill_coordinates(self):
        with self.assertRaisesRegexp(IndexError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42)},
                img_sizes={
                    'image': (42, 42, 1, 1, 1),
                    'label': (42, 42, 1, 1, 1)
                },
                win_sizes={
                    'image': (23, 23),
                    'label': (40, 32)
                },
                n_samples=10)

        with self.assertRaisesRegexp(TypeError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
                img_sizes={
                    'image': (42, 42, 1, 1, 1),
                    'label': (42, 42, 1, 1, 1)
                },
                win_sizes={
                    'image': (23, 23, 1),
                    'label': (40, 32, 1)
                },
                n_samples='test')

        with self.assertRaisesRegexp(AssertionError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
                img_sizes={'label': (42, 1, 1, 1)},
                win_sizes={'image': (23, 23, 1)},
                n_samples=0)

        with self.assertRaisesRegexp(RuntimeError, ""):
            coords = weighted_spatial_coordinates(subject_id=1,
                                                  data={},
                                                  img_sizes={
                                                      'image':
                                                      (42, 42, 1, 1, 1),
                                                      'label':
                                                      (42, 42, 1, 1, 1)
                                                  },
                                                  win_sizes={
                                                      'image': (23, 23, 1),
                                                      'label': (40, 32, 1)
                                                  },
                                                  n_samples=10)
Esempio n. 2
0
 def test_2D_coordinates(self):
     coords = weighted_spatial_coordinates(
         subject_id=1,
         data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
         img_sizes={
             'image': (42, 42, 1, 1, 1),
             'label': (42, 42, 1, 1, 1)
         },
         win_sizes={
             'image': (23, 23, 1),
             'label': (40, 32, 1)
         },
         n_samples=10)
     self.assertEquals(np.all(coords['image'][:0] == 1), True)
     self.assertEquals(coords['image'].shape, (10, 7))
     self.assertEquals(coords['label'].shape, (10, 7))
     self.assertAllClose((coords['image'][:, 4] + coords['image'][:, 1]),
                         (coords['label'][:, 4] + coords['label'][:, 1]),
                         atol=1.0)
     self.assertAllClose((coords['image'][:, 5] + coords['image'][:, 2]),
                         (coords['label'][:, 5] + coords['label'][:, 2]),
                         atol=1.0)
     self.assertAllClose((coords['image'][:, 6] + coords['image'][:, 3]),
                         (coords['label'][:, 6] + coords['label'][:, 3]),
                         atol=1.0)
    def test_2d_coordinates(self):
        img_size = (32, 17, 1, 1, 1)
        win_size = (31, 3, 1)
        sampling_map = np.zeros(img_size)
        coords = weighted_spatial_coordinates(
            64, img_size, win_size, sampling_map)

        self.assertAllEqual(coords.shape, (64, N_SPATIAL))
        self.assertCoordinatesAreValid(coords, sampling_map)

        # testing high weight location (15, 1, 1, 0, 0)
        sampling_map[15, 1, 0, 0, 0] = 1.0
        coords = weighted_spatial_coordinates(
            64, img_size, win_size, sampling_map)
        self.assertAllEqual(coords.shape, (64, N_SPATIAL))
        self.assertTrue(np.all(coords == [15, 1, 0]))
    def test_1d_coordinates(self):
        img_size = (32, 1, 1, 1, 1)
        win_size = (15, 1, 1)
        sampling_map = np.zeros(img_size)
        coords = weighted_spatial_coordinates(
            10, img_size, win_size, sampling_map)
        self.assertAllEqual(coords.shape, (10, N_SPATIAL))
        self.assertCoordinatesAreValid(coords, sampling_map)

        sampling_map[20, 0, 0] = 0.1
        coords = weighted_spatial_coordinates(
            10, img_size, win_size, sampling_map)
        self.assertAllEqual(coords.shape, (10, N_SPATIAL))
        self.assertTrue(np.all(coords == [20, 0, 0]))

        sampling_map[9, 0, 0] = 0.1
        coords = weighted_spatial_coordinates(
            10, img_size, win_size, sampling_map)
        self.assertAllEqual(coords.shape, (10, N_SPATIAL))
        self.assertTrue(np.all((coords == [20, 0, 0]) | (coords == [9, 0, 0])))
Esempio n. 5
0
    def test_ill_coordinates(self):
        with self.assertRaisesRegexp(IndexError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42)},
                img_sizes={'image': (42, 42, 1, 1, 1),
                           'label': (42, 42, 1, 1, 1)},
                win_sizes={'image': (23, 23),
                           'label': (40, 32)},
                n_samples=10)

        with self.assertRaisesRegexp(TypeError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
                img_sizes={'image': (42, 42, 1, 1, 1),
                           'label': (42, 42, 1, 1, 1)},
                win_sizes={'image': (23, 23, 1),
                           'label': (40, 32, 1)},
                n_samples='test')

        with self.assertRaisesRegexp(AssertionError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
                img_sizes={'label': (42, 1, 1, 1)},
                win_sizes={'image': (23, 23, 1)},
                n_samples=0)

        with self.assertRaisesRegexp(RuntimeError, ""):
            coords = weighted_spatial_coordinates(
                subject_id=1,
                data={},
                img_sizes={'image': (42, 42, 1, 1, 1),
                           'label': (42, 42, 1, 1, 1)},
                win_sizes={'image': (23, 23, 1),
                           'label': (40, 32, 1)},
                n_samples=10)
Esempio n. 6
0
 def test_2D_coordinates(self):
     coords = weighted_spatial_coordinates(
         subject_id=1,
         data={'sampler': np.random.rand(42, 42, 42, 1, 1)},
         img_sizes={'image': (42, 42, 1, 1, 1),
                    'label': (42, 42, 1, 1, 1)},
         win_sizes={'image': (23, 23, 1),
                    'label': (40, 32, 1)},
         n_samples=10)
     self.assertEquals(np.all(coords['image'][:0] == 1), True)
     self.assertEquals(coords['image'].shape, (10, 7))
     self.assertEquals(coords['label'].shape, (10, 7))
     self.assertAllClose(
         (coords['image'][:, 4] + coords['image'][:, 1]),
         (coords['label'][:, 4] + coords['label'][:, 1]), atol=1.0)
     self.assertAllClose(
         (coords['image'][:, 5] + coords['image'][:, 2]),
         (coords['label'][:, 5] + coords['label'][:, 2]), atol=1.0)
     self.assertAllClose(
         (coords['image'][:, 6] + coords['image'][:, 3]),
         (coords['label'][:, 6] + coords['label'][:, 3]), atol=1.0)