예제 #1
0
 def test_map_classes_isomorphic(self):
     '''map_classes should map isomorphic class image back to original.'''
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     result = map_classes(gt2, d)
     assert(np.alltrue(result == gt))
예제 #2
0
 def test_map_class_ids_isomorphic(self):
     '''Test map_class_ids with isomorphic classes.'''
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt, gt2)
     for (i, j) in d.items():
         assert(j == i + 1)
예제 #3
0
 def test_map_class_ids_isomorphic(self):
     '''Test map_class_ids with isomorphic classes.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt, gt2)
     for (i, j) in d.items():
         assert(j == i + 1)
예제 #4
0
 def test_map_class_ids_identity_multiple_unlabeled(self):
     '''Mapping a class image back to itself with unlabeled classes.'''
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt, unlabeled=[2, 4])
     for i in set(gt.ravel()):
         assert(i in d)
     for (i, j) in d.items():
         assert(j == i)
예제 #5
0
 def test_map_class_ids_identity(self):
     '''Mapping a class image back to itself should yield identity map.'''
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt)
     for i in set(gt.ravel()):
         assert(i in d)
     for (i, j) in d.items():
         assert(j == i)
예제 #6
0
 def test_map_allow_unmapped_true(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     result = map_classes(gt2, d, allow_unmapped=True)
     assert(np.alltrue(result[gt2 == 1] == 1))
예제 #7
0
 def test_map_class_ids_isomorphic(self):
     '''Test map_class_ids with isomorphic classes.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt, gt2)
     for (i, j) in d.items():
         assert (j == i + 1)
예제 #8
0
 def test_map_classes_isomorphic(self):
     '''map_classes should map isomorphic class image back to original.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     result = map_classes(gt2, d)
     assert (np.alltrue(result == gt))
예제 #9
0
 def test_map_classes_isomorphic(self):
     '''map_classes should map isomorphic class image back to original.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     result = map_classes(gt2, d)
     assert(np.alltrue(result == gt))
예제 #10
0
 def test_map_class_ids_identity(self):
     '''Mapping a class image back to itself should yield identity map.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt)
     for i in set(gt.ravel()):
         assert (i in d)
     for (i, j) in d.items():
         assert (j == i)
예제 #11
0
 def test_map_class_ids_isomorphic_background(self):
     '''Test map_class_ids with isomorphic classes and background arg.'''
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt, gt2, unlabeled=0)
     assert(d[0] == 0)
     d.pop(0)
     for (i, j) in d.items():
         assert(j == i + 1)
예제 #12
0
 def test_map_class_ids_identity_multiple_unlabeled(self):
     '''Mapping a class image back to itself with unlabeled classes.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt, unlabeled=[2, 4])
     for i in set(gt.ravel()):
         assert(i in d)
     for (i, j) in d.items():
         assert(j == i)
예제 #13
0
 def test_map_class_ids_identity(self):
     '''Mapping a class image back to itself should yield identity map.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt)
     for i in set(gt.ravel()):
         assert(i in d)
     for (i, j) in d.items():
         assert(j == i)
예제 #14
0
 def test_map_class_ids_identity_unlabeled(self):
     '''Mapping a class image back to itself with an unlabeled class.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     d = map_class_ids(gt, gt, unlabeled=0)
     for i in set(gt.ravel()):
         assert (i in d)
     for (i, j) in d.items():
         assert (j == i)
예제 #15
0
 def test_map_allow_unmapped_true(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     from warnings import warn
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     result = map_classes(gt2, d, allow_unmapped=True)
     assert (np.alltrue(result[gt2 == 1] == 1))
예제 #16
0
 def test_map_class_ids_isomorphic_background(self):
     '''Test map_class_ids with isomorphic classes and background arg.'''
     from spectral.algorithms.spatial import map_class_ids
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt, gt2, unlabeled=0)
     assert(d[0] == 0)
     d.pop(0)
     for (i, j) in d.items():
         assert(j == i + 1)
예제 #17
0
 def test_map_allow_unmapped_true(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     from warnings import warn
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     result = map_classes(gt2, d, allow_unmapped=True)
     assert(np.alltrue(result[gt2 == 1] == 1))
예제 #18
0
 def test_map_fails_allow_unmapped_false(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     try:
         result = map_classes(gt2, d)
     except ValueError:
         pass
     else:
         assert(False)
예제 #19
0
    def test_map_class_ids_dest_gt_src(self):
        '''Test map_class_ids with more classes in dest image.'''
        gt = np.array(self.gt)

        (i, j) = (100, 30)
        old_label = gt[i, j]
        new_label = max(set(gt.ravel())) + 10
        gt2 = np.array(gt)
        gt2[i, j] = new_label
        
        d = map_class_ids(gt, gt2)
        for (i, j) in d.items():
            assert(j == i)
예제 #20
0
 def test_map_fails_allow_unmapped_false(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     from warnings import warn
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     try:
         result = map_classes(gt2, d)
     except ValueError:
         pass
     else:
         assert (False)
예제 #21
0
 def test_map_fails_allow_unmapped_false(self):
     '''map_classes should raise ValueError if image has unmapped value.'''
     from spectral.algorithms.spatial import map_class_ids, map_classes
     from warnings import warn
     gt = np.array(self.gt)
     gt2 = gt + 1
     d = map_class_ids(gt2, gt)
     d.pop(1)
     try:
         result = map_classes(gt2, d)
     except ValueError:
         pass
     else:
         assert(False)
예제 #22
0
    def test_map_class_ids_dest_gt_src(self):
        '''Test map_class_ids with more classes in dest image.'''
        from spectral.algorithms.spatial import map_class_ids
        gt = np.array(self.gt)

        (i, j) = (100, 30)
        old_label = gt[i, j]
        new_label = max(set(gt.ravel())) + 10
        gt2 = np.array(gt)
        gt2[i, j] = new_label
        
        d = map_class_ids(gt, gt2)
        for (i, j) in d.items():
            assert(j == i)
예제 #23
0
    def test_map_class_ids_src_gt_dest(self):
        '''Test map_class_ids with more classes in source image.'''
        from spectral.algorithms.spatial import map_class_ids
        gt = np.array(self.gt)

        (i, j) = (100, 30)
        old_label = gt[i, j]
        new_label = max(set(gt.ravel())) + 10
        gt2 = np.array(gt)
        gt2[i, j] = new_label

        d = map_class_ids(gt2, gt)
        assert (d[new_label] == new_label)
        d.pop(new_label)
        for (i, j) in d.items():
            assert (j == i)
예제 #24
0
    def test_map_class_ids_src_gt_dest(self):
        '''Test map_class_ids with more classes in source image.'''
        gt = np.array(self.gt)

        (i, j) = (100, 30)
        old_label = gt[i, j]
        new_label = max(set(gt.ravel())) + 10
        gt2 = np.array(gt)
        gt2[i, j] = new_label
        
        d = map_class_ids(gt2, gt)
        # There are enough pixels for each class that a new single-pixel class
        # should not be mapped to one of the existing classes.
        assert(d[new_label] not in gt)
        d.pop(new_label)
        for (i, j) in d.items():
            assert(j == i)
예제 #25
0
    def test_map_class_ids_src_gt_dest(self):
        '''Test map_class_ids with more classes in source image.'''
        from spectral.algorithms.spatial import map_class_ids
        gt = np.array(self.gt)

        (i, j) = (100, 30)
        old_label = gt[i, j]
        new_label = max(set(gt.ravel())) + 10
        gt2 = np.array(gt)
        gt2[i, j] = new_label
        
        d = map_class_ids(gt2, gt)
        # There are enough pixels for each class that a new single-pixel class
        # should not be mapped to one of the existing classes.
        assert(d[new_label] not in gt)
        d.pop(new_label)
        for (i, j) in d.items():
            assert(j == i)