Ejemplo n.º 1
0
    def test_random_training_tile_by_polling(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/')

        size = (1, 4, 3)
        channels = [0, 1, 2]
        labels = set([1, 2, 3])
        ensure_labelvalue = 2

        c = TiffConnector(img_path, label_path)
        d = Dataset(c)

        # weights_val = np.array(

        weights_val = np.array([[[[0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.]]],
                                [[[0., 0., 0.],
                                  [0., 0., 0.],
                                  [1., 1., 1.],
                                  [1., 1., 1.]]],


                                [[[1., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.]]]])

        np.random.seed(43)
        training_tile = d._random_training_tile_by_polling(
                            size, channels, labels,
                            ensure_labelvalue=ensure_labelvalue)

        assert_array_equal(training_tile.weights, weights_val)

        weights_val = np.array([[[[0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.]]],
                                [[[0., 0., 0.],
                                  [0., 1., 1.],
                                  [0., 1., 1.],
                                  [0., 0., 0.]]],
                                [[[0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 0., 0.],
                                  [0., 1., 0.]]]])

        training_tile = d._random_training_tile_by_polling(
                            size, channels, labels,
                            ensure_labelvalue=None)

        assert_array_equal(training_tile.weights, weights_val)
        np.random.seed(None)
Ejemplo n.º 2
0
    def test_random_training_tile_by_polling_ilastik(self):

        p = os.path.join(base_path, '../test_data/ilastik/dimensionstest')
        img_path = os.path.join(p, 'images')
        label_path = os.path.join(p, 'x15_y10_z2_c4_classes2.ilp')

        size = (1, 1, 1)
        channels = [0, 1, 2, 3]
        labels = set([1, 2])
        ensure_labelvalue = 2

        c = IlastikConnector(img_path, label_path)
        d = Dataset(c)

        np.random.seed(43)
        training_tile = d._random_training_tile_by_polling(
            size, channels, labels, ensure_labelvalue=ensure_labelvalue)
        print(training_tile)

        weights_val = np.array([[[[0.]]], [[[1.]]]])
        assert_array_equal(training_tile.weights, weights_val)