scikit-image

Форк
0
67 строк · 2.0 Кб
1
from ._pnpoly import _grid_points_in_poly, _points_in_poly
2

3

4
def grid_points_in_poly(shape, verts, binarize=True):
5
    """Test whether points on a specified grid are inside a polygon.
6

7
    For each ``(r, c)`` coordinate on a grid, i.e. ``(0, 0)``, ``(0, 1)`` etc.,
8
    test whether that point lies inside a polygon.
9

10
    You can control the output type with the `binarize` flag. Please refer to its
11
    documentation for further details.
12

13
    Parameters
14
    ----------
15
    shape : tuple (M, N)
16
        Shape of the grid.
17
    verts : (V, 2) array
18
        Specify the V vertices of the polygon, sorted either clockwise
19
        or anti-clockwise. The first point may (but does not need to be)
20
        duplicated.
21
    binarize: bool
22
        If `True`, the output of the function is a boolean mask.
23
        Otherwise, it is a labeled array. The labels are:
24
        O - outside, 1 - inside, 2 - vertex, 3 - edge.
25

26
    See Also
27
    --------
28
    points_in_poly
29

30
    Returns
31
    -------
32
    mask : (M, N) ndarray
33
        If `binarize` is True, the output is a boolean mask. True means the
34
        corresponding pixel falls inside the polygon.
35
        If `binarize` is False, the output is a labeled array, with pixels
36
        having a label between 0 and 3. The meaning of the values is:
37
        O - outside, 1 - inside, 2 - vertex, 3 - edge.
38

39
    """
40
    output = _grid_points_in_poly(shape, verts)
41
    if binarize:
42
        output = output.astype(bool)
43
    return output
44

45

46
def points_in_poly(points, verts):
47
    """Test whether points lie inside a polygon.
48

49
    Parameters
50
    ----------
51
    points : (K, 2) array
52
        Input points, ``(x, y)``.
53
    verts : (L, 2) array
54
        Vertices of the polygon, sorted either clockwise or anti-clockwise.
55
        The first point may (but does not need to be) duplicated.
56

57
    See Also
58
    --------
59
    grid_points_in_poly
60

61
    Returns
62
    -------
63
    mask : (K,) array of bool
64
        True if corresponding point is inside the polygon.
65

66
    """
67
    return _points_in_poly(points, verts)
68

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.