def test_set_augmentation(self): img_path = os.path.join(base_path, '../test_data/tiffconnector_1/im/') label_path = os.path.join(base_path, '../test_data/tiffconnector_1/labels/') c = TiffConnector(img_path, label_path) d = Dataset(c) size = (1, 3, 4) pad = (1, 2, 2) m = TrainingBatch(d, size, padding_zxy=pad) self.assertEqual(m.augmentation, {'flip'}) m.augment_by_rotation(True) self.assertEqual(m.augmentation, {'flip', 'rotate'}) self.assertEqual(m.rotation_range, (-45, 45)) m.augment_by_shear(True) self.assertEqual(m.augmentation, {'flip', 'rotate', 'shear'}) self.assertEqual(m.shear_range, (-5, 5)) m.augment_by_flipping(False) self.assertEqual(m.augmentation, {'rotate', 'shear'})
def test_get_ilastik_weights2(self): pth = os.path.join(base_path, '../test_data/ilastik/dimensionstest') img_path = os.path.join(pth, 'images') lbl_path = os.path.join(pth, 'x15_y10_z2_c4_classes2.ilp') c = IlastikConnector(img_path, lbl_path) d = Dataset(c) size = (2, 15, 10) # this is the size of the whole image pad = (0, 0, 0) m = TrainingBatch(d, size, padding_zxy=pad) m.augment_by_flipping(False) mini = next(m) weights = mini.weights() print(weights[0, :, :, :, :]) # all samples of the batch should be identical, # because tilesize=imsize assert_array_equal(weights[0, :, :, :, :], weights[1, :, :, :, :]) # weight positions from labelvalue 1 and 2 pos = [[0, 0, 2, 1], [0, 0, 2, 1], [0, 0, 8, 6], [0, 0, 9, 6], [0, 1, 4, 3], [1, 0, 2, 2], [1, 0, 3, 2], [1, 0, 8, 7], [1, 0, 9, 7]] for p in pos: self.assertEqual(weights[0, p[0], p[1], p[2], p[3]], 1) self.assertEqual(weights[1, p[0], p[1], p[2], p[3]], 1)
def test_get_ilastik_weights(self): img_path = os.path.join(base_path, '../test_data/ilastik') lbl_path = os.path.join(base_path, '../test_data/ilastik/ilastik-1.2.ilp') c = IlastikConnector(img_path, lbl_path) d = Dataset(c) size = (8, 2, 4) pad = (0, 0, 0) m = TrainingBatch(d, size, padding_zxy=pad) m.augment_by_flipping(False) mini = next(m) weights = mini.weights() # label 1 at position (4,1,3) self.assertTrue(weights[0, 0, 4, 1, 3] == 1) # label 2 at position (1,1,1) self.assertTrue(weights[0, 1, 1, 1, 1] == 1) # label 3 at position (1,1,1) self.assertTrue(weights[0, 2, 7, 1, 1] == 1)