Ejemplo n.º 1
0
def test_funkce():
    img = np.array([[0, 1, 0, 0],
                    [1, 1, 0, 1],
                    [1, 1, 0, 1],
                    [1, 0, 0, 1]])

    objclass = np.array([[0, 1, 0, 0],
                         [1, 1, 0, 2],
                         [1, 1, 0, 2],
                         [1, 0, 0, 2]])

    moje(img)
    assert (moje(img) == objclass).all()
    img = np.random.rand(100, 100)
    img[img > 0.5] = 1
    img[img != 1] = 0
    img = img.astype(np.uint8)

    objclass = moje(img)
    assert (binarize(objclass) == img).all()
    moje_tridy = getlistofclasses(objclass)
    moje_conncomp = []
    for trida in moje_tridy:
        moje_conncomp.append(getcoordlistofoneclass(objclass, int(trida)))

    num_labels, labels_im = cv2.connectedComponents(img, None, 4)
    assert (binarize(labels_im) == img).all()
    cv_tridy = getlistofclasses(labels_im)
    cv_conncomp = []
    for trida in cv_tridy:
        cv_conncomp.append(getcoordlistofoneclass(objclass, int(trida)))

    moje_conncomp = [i for i in moje_conncomp if np.size(i) > 20]
    cv_conncomp = [i for i in cv_conncomp if np.size(i) > 20]
    assert np.size(moje_conncomp) == np.size(cv_conncomp)
Ejemplo n.º 2
0
def test_remap():
    img = np.array([[0, 1, 0], [1, 1, 1], [1, 1, 0]])
    matrix = np.copy(img)
    matrix[1, 0] = 5
    assert (moje(img, matrix, 2, 1, 5) == np.array([1, 1, 1, 0])).all()
    assert (moje(img, matrix, 1, 1, 5) == [0, 0, 0, 1]).all()
    assert (moje(img, img, 1, 1, 4) == [0, 0, 0, 0]).all()
    assert (moje(np.zeros((3, 3)), matrix, 1, 1, 5) == [1, 1, 1, 1]).all()
Ejemplo n.º 3
0
def test_zaporne_souradnice():
    vec = [0, 0, 0, 0]
    with pytest.raises(Exception):
        moje(
            vec,
            0,
            -1,
            0,
        )
    with pytest.raises(Exception):
        moje(vec, 0, 0, -1)
Ejemplo n.º 4
0
def test_invalid_values():
    with pytest.raises(Exception):
        moje(-1, 5)
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), -1)
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), [1, 2])
    with pytest.raises(Exception):
        moje(np.ones((3, 3, 3, 3)), 1)
    with pytest.raises(Exception):
        moje(np.ones((2, 2, 2)), 1)
Ejemplo n.º 5
0
def test_invalid_values():
    mat = np.ones((2, 2))
    vec = [0, 0]
    with pytest.raises(Exception):  # _na musí být číslo
        moje(mat, mat, 0, 0, vec)
    with pytest.raises(Exception):
        moje(0, mat, 0, 0, 0)
    with pytest.raises(Exception):
        moje(mat, 0, 0, 0, 0)
    with pytest.raises(Exception):  # souřadnice nesmí být vektor
        moje(mat, mat, [0, 0], 0, 0)
    with pytest.raises(Exception):
        moje(mat, mat, 0, [0, 0], 0)
Ejemplo n.º 6
0
def test_function():
    assert (0, 0, 0) == moje([1, 1, 1, 1], 0, 0, 0)
    assert moje([0, 1, 1, 1], 3, 0, 0) == (3, 0, -1)  # cesta po hranách
    assert moje([1, 0, 1, 1], 0, 0, 0) == (0, 1, 0)
    assert moje([1, 1, 0, 1], 1, 0, 0) == (1, 0, 1)
    assert moje([1, 1, 1, 0], 2, 0, 0) == (2, -1, 0)
    assert moje([0, 1, 1, 1], 1, 0, 0) == (3, 0, -1)  # cesta po rozích
    assert moje([1, 0, 1, 1], 2, 0, 0) == (0, 1, 0)
    assert moje([1, 1, 0, 1], 3, 0, 0) == (1, 0, 1)
    assert moje([1, 1, 1, 0], 0, 0, 0) == (2, -1, 0)
Ejemplo n.º 7
0
def test_ones():  # pro každý pixel byla zapsána souřadnice
    matrix = np.ones((50, 75))
    testmatrix = np.zeros(np.shape(matrix))
    coords = moje(matrix, 1)
    for coord in coords:
        testmatrix[coord[0]][coord[1]] = 1
    assert (testmatrix == matrix).all()
Ejemplo n.º 8
0
def test_find_one():
    matrix = np.zeros((3, 3))
    matrix[0, 1] = 1
    matrix[1, 2] = 2
    matrix[2, 2] = 2
    matrix[0, 0] = 1
    assert (moje([[1, 0], [2, 1]], matrix) == [[1], [2]]).all()
Ejemplo n.º 9
0
def test_invalid_values():
    with pytest.raises(Exception):
        moje(-1, 0)
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), 0)
    with pytest.raises(Exception):
        moje(np.ones((2, 2, 2)), 0)
    with pytest.raises(Exception):
        moje(np.ones((1, 2)), [1, 2])
Ejemplo n.º 10
0
def test_remap():
    img = np.array([[0, 1, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 0, 1]])

    objclass = np.array([[0, 2, 0, 0], [2, 2, 2, 2], [2, 1, 0, 5],
                         [2, 0, 0, 2]])

    moje(img, objclass, [[3, 1], [3, 2]], 0)
    assert (objclass == np.array([[0, 5, 0, 0], [5, 5, 5, 5], [5, 5, 0, 5],
                                  [5, 0, 0, 2]])).all()
    img = np.array([[0, 1, 0, 0], [1, 1, 1, 1], [1, 1, 0, 1], [1, 0, 0, 1]])

    objclass = np.array([[0, 2, 0, 0], [2, 2, 2, 2], [2, 1, 0, 2],
                         [5, 0, 0, 2]])

    moje(img, objclass, [[0, 2], [0, 3]], 0)
    assert (objclass == np.array([[0, 5, 0, 0], [5, 5, 5, 5], [5, 5, 0, 5],
                                  [5, 0, 0, 2]])).all()
Ejemplo n.º 11
0
def test_invalid_values():
    mat = np.ones((2, 2))
    vec = [0, 0]
    with pytest.raises(Exception):  # _na musí být číslo
        moje(mat, mat, vec, vec)
    with pytest.raises(Exception):
        moje(0, mat, vec, 0)
    with pytest.raises(Exception):
        moje(mat, 0, vec, 0)
    with pytest.raises(Exception):
        moje(mat, mat, 0, 0)
Ejemplo n.º 12
0
def test_invalid_values():
    with pytest.raises(Exception):  # nesmí být číslo, musí mít správný rozměr
        moje(-1, np.ones((2, 2)))
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), -1)
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), np.ones((3, 3, 3)))
Ejemplo n.º 13
0
def test_img_only_ones_or_zeros():
    mat = np.ones((2, 2))
    mat[1, 1] = 5
    with pytest.raises(Exception):
        moje(mat)
Ejemplo n.º 14
0
def test_invalid_values():
    with pytest.raises(Exception):  # img musí být 2d matice
        moje(0)
    with pytest.raises(Exception):
        moje(np.zeros((2, 2, 2)))
Ejemplo n.º 15
0
def test_remap():
    img = np.array([[0, 1, 0], [1, 1, 1], [1, 1, 0]])
    matrix = img * 2
    moje(matrix / 2, matrix, [2, 1], 5)
    assert (matrix == np.array(img * 5)).all()
Ejemplo n.º 16
0
def test_find_one():
    matrix = np.zeros(3)
    matrix[1] = 5
    assert moje(matrix, 5)
    assert moje(matrix, 0)
    assert not (moje(matrix, 1))
Ejemplo n.º 17
0
def test_zaporne_souradnice():
    with pytest.raises(Exception):
        moje([-1, 1], np.ones((2, 2)))
    with pytest.raises(Exception):
        moje([1, -1], np.ones((2, 2)))
Ejemplo n.º 18
0
def test_img_only_ones_or_zeros():
    vec = [[0, 0], [1, 1]]
    mat = np.ones((2, 2))
    mat[1, 1] = 5
    with pytest.raises(Exception):
        moje(mat, mat, vec, 0)
Ejemplo n.º 19
0
def test_dim_of_return_value():
    assert np.shape(np.ones((10, 5))) == np.shape(moje(np.ones((10, 5))))
Ejemplo n.º 20
0
def test_ones_and_zeros():
    assert (moje(np.ones((50, 75))) == [1])
    assert (np.size(moje(np.zeros((50, 75)))) == 0)
Ejemplo n.º 21
0
def test_dim_of_return_value():
    assert 1 == np.shape(moje(np.random.rand(50, 75)))[1]
Ejemplo n.º 22
0
def test_empty_list():
    assert not (moje([], 0))
Ejemplo n.º 23
0
def test_dim_of_return_value():
    assert np.shape(moje(np.ones((3, 3)), 1, 1))[1] == 2
Ejemplo n.º 24
0
def test_empty_neighbors():
    with pytest.raises(Exception):
        moje([], np.ones((2, 2)))
Ejemplo n.º 25
0
def test_dim_of_return_value():
    assert np.shape(np.ones(
        (10, 5, 3)))[:-1] == np.shape(moje(np.ones((10, 5, 3)), 55))
Ejemplo n.º 26
0
def test_invalid_values():
    mat = np.ones((2, 2))
    vec = [[0, 0], [1, 1]]
    with pytest.raises(Exception):  # beginneighbor musí být číslo
        moje(mat, mat, vec, [1, 2, 3, 4])
    with pytest.raises(Exception):  # beginneighbor nesmí být větší jak
        moje(mat, mat, vec, 2)  # max řádek neighbors
    with pytest.raises(Exception):
        moje(mat, mat, vec, -2)
    with pytest.raises(Exception):  # img musí být 2d matice
        moje(0, mat, vec, 0)
    with pytest.raises(Exception):  # objclass musí být 2d matice
        moje(mat, 0, vec, 0)
    with pytest.raises(Exception):  # neighbors musí být mattice se
        moje(mat, mat, 0, 0)  # souřadnicemi
Ejemplo n.º 27
0
def test_zaporne_souradnice():
    mat = np.ones((2, 2))
    with pytest.raises(Exception):
        moje(mat, mat, [-1, 0], 0)
    with pytest.raises(Exception):
        moje(mat, mat, [0, -1], 0)
Ejemplo n.º 28
0
def test_ones_and_zeros():
    assert (np.ones((50, 75)) == moje(np.ones((50, 75)))).all()
    assert (np.zeros((50, 75)) == moje(np.zeros((50, 75)))).all()
Ejemplo n.º 29
0
def test_ones_and_zeros():
    assert (moje(np.ones((3, 3)), 1, 1) == [[0, 1], [1, 0]])
    assert (np.size(moje(np.zeros((3, 3)), 1, 1)) == 0)
Ejemplo n.º 30
0
def test_invalid_values():
    vec = [0, 0, 0, 0]
    with pytest.raises(Exception):  # edges musí být list o 4 prvcích
        moje([1, 0], 0, 0, 0)
    with pytest.raises(Exception):
        moje(np.ones((2, 2)), 0, 0, 0)
    with pytest.raises(Exception):
        moje(0, 0, 0, 0)
    with pytest.raises(Exception):  # lastedge musí ležet v množině {0,1,2,3}
        moje(vec, -1, 0, 0)
    with pytest.raises(Exception):  # lastedge musí být číslo
        moje(vec, np.ones((2, 2)), 0, 0)
    with pytest.raises(Exception):  # souřadnice nesmí být vektor
        moje(vec, 0, [0, 0], 0)
    with pytest.raises(Exception):
        moje(vec, 0, 0, [0, 0])
    with pytest.raises(Exception):  # edges není binární
        moje([1, 5, 1, 1], 0, 0, 0)