
    9i                        S SK rSSKJr  SSKJr  SSKJr  SSKJ	r	J
r
JrJrJrJrJrJr  SS jrSS	 jrSS
.S jr\" SS5      SS j5       rSS jrS rS rSS jrSS jrSS jrS S jrSS jrS!S jr\" SS5      S"S j5       rS#S jrg)$    N   )polygon_clip)require)NP_COPY_IF_NEEDED   )_coords_inside_image_line_line_aa_polygon_ellipse_perimeter_circle_perimeter_circle_perimeter_aa_bezier_curvec                 r   [         R                  S[        U S   5      2S[        U S   5      24   u  pEUu  pgUu  pU[         R                  -  n[         R                  " U5      [         R
                  " U5      pXF-
  XW-
  pX-  X-  -   U-  S-  X-  X-  -
  U	-  S-  -   n[         R                  " US:  5      $ )a  Generate coordinates of points within ellipse bounded by shape.

Parameters
----------
shape :  iterable of ints
    Shape of the input image.  Must be at least length 2. Only the first
    two values are used to determine the extent of the input image.
center : iterable of floats
    (row, column) position of center inside the given shape.
radii : iterable of floats
    Size of two half axes (for row and column)
rotation : float, optional
    Rotation of the ellipse defined by the above, in radians
    in range (-PI, PI), in contra clockwise direction,
    with respect to the column-axis.

Returns
-------
rows : iterable of ints
    Row coordinates representing values within the ellipse.
cols : iterable of ints
    Corresponding column coordinates representing values within the ellipse.
r   r   r   )npogridfloatpisincosnonzero)shapecenterradiirotationr_limc_limr_orgc_orgr_radc_rad	sin_alpha	cos_alpharc	distancess                  Q/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/draw/draw.py_ellipse_in_shaper(      s    0 88AeAh/U58_1DDELELELEH66(+RVVH-=yMU]q-!-/58Q>	
	&%/	
B I ::i!m$$    c                    [         R                  " X/5      n[         R                  " X#/5      nU[         R                  -  n[        U[         R                  " U5      -  5      U[         R
                  " U5      -  -   nU[         R
                  " U5      -  [        U[         R                  " U5      -  5      -   n	[         R                  " X/5      n
[         R                  " Xj-
  5      R                  [        5      n[         R                  " Xj-   5      R                  [        5      nUb^  [         R                  " U[         R                  " SS/5      5      n[         R                  " U[         R                  " USS 5      S-
  5      nXk-
  nX-
  S-   n[        XXu5      u  nnSUR                  l        SUR                  l        XS   -  nUUS   -  nUU4$ )a?	  Generate coordinates of pixels within ellipse.

Parameters
----------
r, c : double
    Centre coordinate of ellipse.
r_radius, c_radius : double
    Minor and major semi-axes. ``(r/r_radius)**2 + (c/c_radius)**2 = 1``.
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output pixel
    coordinates. This is useful for ellipses which exceed the image size.
    By default the full extent of the ellipse are used. Must be at least
    length 2. Only the first two values are used to determine the extent.
rotation : float, optional (default 0.)
    Set the ellipse rotation (rotation) in range (-PI, PI)
    in contra clock wise direction, so PI/2 degree means swap ellipse axis

Returns
-------
rr, cc : ndarray of int
    Pixel coordinates of ellipse.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Examples
--------
>>> from skimage.draw import ellipse
>>> img = np.zeros((10, 12), dtype=np.uint8)
>>> rr, cc = ellipse(5, 6, 3, 5, rotation=np.deg2rad(30))
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)

Notes
-----
The ellipse equation::

    ((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 +
    ((x * sin(alpha) - y * cos(alpha)) / y_radius) ** 2 = 1


Note that the positions of `ellipse` without specified `shape` can have
also, negative values, as this is correct on the plane. On the other hand
using these ellipse positions for an image afterwards may lead to appearing
on the other side of image, because ``image[-1, -1] = image[end-1, end-1]``

>>> rr, cc = ellipse(1, 2, 3, 6)
>>> img = np.zeros((6, 12), dtype=np.uint8)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1]], dtype=uint8)
Nr   r   r   T)r   arrayr   absr   r   ceilastypeintfloormaximumminimumr(   flags	writeable)r$   r%   r_radiusc_radiusr   r   r   r   r_radius_rotc_radius_rot	radii_rot
upper_leftlower_rightshifted_centerbounding_shaperrccs                    r'   ellipser@   6   s~   H XXqfFHHh)*EH x"&&"223hAQ6QQLbffX..Xx@P5P1QQL ,56I+,33C8J((6-.55c:KZZ
BHHaV,<=
jjbhhuRay.AA.EF(N -1N~uOFBBHHBHHQ-B*Q-Br6Mr)   )r   c                $    U u  p4[        X4XU5      $ )a  Generate coordinates of pixels within circle.

Parameters
----------
center : tuple
    Center coordinate of disk.
radius : double
    Radius of disk.
shape : tuple, optional
    Image shape as a tuple of size 2. Determines the maximum
    extent of output pixel coordinates. This is useful for disks that
    exceed the image size. If None, the full extent of the disk is used.
    The  shape might result in negative coordinates and wraparound
    behaviour.

Returns
-------
rr, cc : ndarray of int
    Pixel coordinates of disk.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Examples
--------
>>> import numpy as np
>>> from skimage.draw import disk
>>> shape = (4, 4)
>>> img = np.zeros(shape, dtype=np.uint8)
>>> rr, cc = disk((0, 0), 2, shape=shape)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 0, 0],
       [1, 1, 0, 0],
       [0, 0, 0, 0],
       [0, 0, 0, 0]], dtype=uint8)
>>> img = np.zeros(shape, dtype=np.uint8)
>>> # Negative coordinates in rr and cc perform a wraparound
>>> rr, cc = disk((0, 0), 2, shape=None)
>>> img[rr, cc] = 1
>>> img
array([[1, 1, 0, 1],
       [1, 1, 0, 1],
       [0, 0, 0, 0],
       [1, 1, 0, 1]], dtype=uint8)
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = disk((4, 4), 5)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
       [0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
)r@   )r   radiusr   r$   r%   s        r'   diskrC      s    x DA1//r)   
matplotlibz>=3.3c           	      L   U(       a5  Uc  [        S5      e[        R                  " SSUS   S-
  US   S-
  /5      nOj[        R                  " [        R                  " U 5      [        R                  " U5      [        R                  " U 5      [        R                  " U5      /5      n[        X/UQ76 u  p[        R                  " U 5      R                  [        5      n [        R                  " U5      R                  [        5      n/ / pe[        [        U 5      S-
  5       HC  n[        X   X   XS-      XS-      5      u  pUR                  U5        UR                  U	5        ME     [        R                  " U5      n[        R                  " U5      nUc  XV4$ [        XVU5      $ )ah  Generate polygon perimeter coordinates.

Parameters
----------
r : (N,) ndarray
    Row coordinates of vertices of polygon.
c : (N,) ndarray
    Column coordinates of vertices of polygon.
shape : tuple, optional
    Image shape which is used to determine maximum extents of output pixel
    coordinates. This is useful for polygons that exceed the image size.
    If None, the full extents of the polygon is used.  Must be at least
    length 2. Only the first two values are used to determine the extent of
    the input image.
clip : bool, optional
    Whether to clip the polygon to the provided shape.  If this is set
    to True, the drawn figure will always be a closed polygon with all
    edges visible.

Returns
-------
rr, cc : ndarray of int
    Pixel coordinates of polygon.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Examples
--------
.. testsetup::
    >>> import pytest; _ = pytest.importorskip('matplotlib')

>>> from skimage.draw import polygon_perimeter
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = polygon_perimeter([5, -1, 5, 10],
...                            [-1, 5, 11, 5],
...                            shape=img.shape, clip=True)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 1, 0, 0, 0, 0, 0, 0, 1],
       [0, 0, 0, 1, 0, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 1, 1, 1, 0, 0, 0]], dtype=uint8)

zMust specify clipping shaper   r   )
ValueErrorr   r+   minmaxr   roundr.   r/   rangelenlineextendasarrayr   )
r$   r%   r   clipclip_boxr>   r?   iline_rline_cs
             r'   polygon_perimeterrT      sI   h =:;;88Q58a<qA>?88RVVAYq	266!9bffQiHI (x(DA
3A
3A 3q6A:adAD!E(A!eH=
		&
		& 
 
BB	BB}v#BE22r)   c                    Uu  pEU R                   S:X  a  U S[        R                  4   n [        R                  " US[        S9nU R
                  S   UR
                  S   :w  a  [        SUR
                  S    S35      e[        R                  " U5      (       a  [        R                  " U5      U-  n[        XEU R
                  US	9u  pEnUS[        R                  4   nX#-  nXU4   SU-
  -  nXb-   XU4'   g
)ae  Set pixel color in the image at the given coordinates.

Note that this function modifies the color of the image in-place.
Coordinates that exceed the shape of the image will be ignored.

Parameters
----------
image : (M, N, C) ndarray
    Image
coords : tuple of ((K,) ndarray, (K,) ndarray)
    Row and column coordinates of pixels to be colored.
color : (C,) ndarray
    Color to be assigned to coordinates in the image.
alpha : scalar or (K,) ndarray
    Alpha values used to blend color with image.  0 is transparent,
    1 is opaque.

Examples
--------
>>> from skimage.draw import line, set_color
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = line(1, 1, 20, 20)
>>> set_color(img, (rr, cc), 1)
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]], dtype=uint8)

r   .r   )ndmincopyzColor shape (r   z6) must match last image dimension ({image.shape[-1]}).)valN)
ndimr   newaxisr+   r   r   rF   isscalar	ones_liker   )imagecoordscoloralphar>   r?   valss          r'   	set_colorrc   *  s    J FBzzQc2::o&HHU!*;<E{{2%++b/)EKKN+ ,3 3
 	

 
{{5 R 5((%HMBE#rzz/"EMER=AI&DLEb&Mr)   c                     [        XX#5      $ )a  Generate line pixel coordinates.

Parameters
----------
r0, c0 : int
    Starting position (row, column).
r1, c1 : int
    End position (row, column).

Returns
-------
rr, cc : (N,) ndarray of int
    Indices of pixels that belong to the line.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Notes
-----
Anti-aliased line generator is available with `line_aa`.

Examples
--------
>>> from skimage.draw import line
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = line(1, 1, 8, 8)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
)r	   r0c0r1c1s       r'   rL   rL   k  s    N   r)   c                     [        XX#5      $ )a  Generate anti-aliased line pixel coordinates.

Parameters
----------
r0, c0 : int
    Starting position (row, column).
r1, c1 : int
    End position (row, column).

Returns
-------
rr, cc, val : (N,) ndarray (int, int, float)
    Indices of pixels (`rr`, `cc`) and intensity values (`val`).
    ``img[rr, cc] = val``.

References
----------
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
       http://members.chello.at/easyfilter/Bresenham.pdf

Examples
--------
>>> from skimage.draw import line_aa
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc, val = line_aa(1, 1, 8, 8)
>>> img[rr, cc] = val * 255
>>> img
array([[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0, 255,  74,   0,   0,   0,   0,   0,   0,   0],
       [  0,  74, 255,  74,   0,   0,   0,   0,   0,   0],
       [  0,   0,  74, 255,  74,   0,   0,   0,   0,   0],
       [  0,   0,   0,  74, 255,  74,   0,   0,   0,   0],
       [  0,   0,   0,   0,  74, 255,  74,   0,   0,   0],
       [  0,   0,   0,   0,   0,  74, 255,  74,   0,   0],
       [  0,   0,   0,   0,   0,   0,  74, 255,  74,   0],
       [  0,   0,   0,   0,   0,   0,   0,  74, 255,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)
)r
   re   s       r'   line_aark     s    N BB##r)   c                     [        XU5      $ )al	  Generate coordinates of pixels inside a polygon.

Parameters
----------
r : (N,) array_like
    Row coordinates of the polygon's vertices.
c : (N,) array_like
    Column coordinates of the polygon's vertices.
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output
    pixel coordinates. This is useful for polygons that exceed the image
    size. If None, the full extent of the polygon is used.  Must be at
    least length 2. Only the first two values are used to determine the
    extent of the input image.

Returns
-------
rr, cc : ndarray of int
    Pixel coordinates of polygon.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

See Also
--------
polygon2mask:
    Create a binary mask from a polygon.

Notes
-----
This function ensures that `rr` and `cc` don't contain negative values.
Pixels of the polygon that whose coordinates are smaller 0, are not drawn.

Examples
--------
>>> import skimage as ski
>>> r = np.array([1, 2, 8])
>>> c = np.array([1, 7, 4])
>>> rr, cc = ski.draw.polygon(r, c)
>>> img = np.zeros((10, 10), dtype=int)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])

If the image `shape` is defined and vertices / points of the `polygon` are
outside this coordinate space, only a part (or none at all) of the polygon's
pixels is returned. Shifting the polygon's vertices by an offset can be used
to move the polygon around and potentially draw an arbitrary sub-region of
the polygon.

>>> offset = (2, -4)
>>> rr, cc = ski.draw.polygon(r - offset[0], c - offset[1], shape=img.shape)
>>> img = np.zeros((10, 10), dtype=int)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
)r   )r$   r%   r   s      r'   polygonrm     s    V A%  r)   c                     [        XX#U5      $ )a  Generate circle perimeter coordinates.

Parameters
----------
r, c : int
    Centre coordinate of circle.
radius : int
    Radius of circle.
method : {'bresenham', 'andres'}, optional
    bresenham : Bresenham method (default)
    andres : Andres method
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output
    pixel coordinates. This is useful for circles that exceed the image
    size. If None, the full extent of the circle is used.  Must be at least
    length 2. Only the first two values are used to determine the extent of
    the input image.

Returns
-------
rr, cc : (N,) ndarray of int
    Bresenham and Andres' method:
    Indices of pixels that belong to the circle perimeter.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Notes
-----
Andres method presents the advantage that concentric
circles create a disc whereas Bresenham can make holes. There
is also less distortions when Andres circles are rotated.
Bresenham method is also known as midpoint circle algorithm.
Anti-aliased circle generator is available with `circle_perimeter_aa`.

References
----------
.. [1] J.E. Bresenham, "Algorithm for computer control of a digital
       plotter", IBM Systems journal, 4 (1965) 25-30.
.. [2] E. Andres, "Discrete circles, rings and spheres", Computers &
       Graphics, 18 (1994) 695-706.

Examples
--------
>>> from skimage.draw import circle_perimeter
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = circle_perimeter(4, 4, 3)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
       [0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
)r   )r$   r%   rB   methodr   s        r'   circle_perimeterrp     s    x Q6599r)   c                     [        XX#5      $ )a  Generate anti-aliased circle perimeter coordinates.

Parameters
----------
r, c : int
    Centre coordinate of circle.
radius : int
    Radius of circle.
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output
    pixel coordinates. This is useful for circles that exceed the image
    size. If None, the full extent of the circle is used.  Must be at least
    length 2. Only the first two values are used to determine the extent of
    the input image.

Returns
-------
rr, cc, val : (N,) ndarray (int, int, float)
    Indices of pixels (`rr`, `cc`) and intensity values (`val`).
    ``img[rr, cc] = val``.

Notes
-----
Wu's method draws anti-aliased circle. This implementation doesn't use
lookup table optimization.

Use the function ``draw.set_color`` to apply ``circle_perimeter_aa``
results to color images.

References
----------
.. [1] X. Wu, "An efficient antialiasing technique", In ACM SIGGRAPH
       Computer Graphics, 25 (1991) 143-152.

Examples
--------
>>> from skimage.draw import circle_perimeter_aa
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc, val = circle_perimeter_aa(4, 4, 3)
>>> img[rr, cc] = val * 255
>>> img
array([[  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,  60, 211, 255, 211,  60,   0,   0,   0],
       [  0,  60, 194,  43,   0,  43, 194,  60,   0,   0],
       [  0, 211,  43,   0,   0,   0,  43, 211,   0,   0],
       [  0, 255,   0,   0,   0,   0,   0, 255,   0,   0],
       [  0, 211,  43,   0,   0,   0,  43, 211,   0,   0],
       [  0,  60, 194,  43,   0,  43, 194,  60,   0,   0],
       [  0,   0,  60, 211, 255, 211,  60,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
       [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)

>>> from skimage import data, draw
>>> image = data.chelsea()
>>> rr, cc, val = draw.circle_perimeter_aa(r=100, c=100, radius=75)
>>> draw.set_color(image, (rr, cc), [1, 0, 0], alpha=val)
)r   )r$   r%   rB   r   s       r'   circle_perimeter_aarr   L  s    t  f44r)   c                     [        XX#XE5      $ )a[	  Generate ellipse perimeter coordinates.

Parameters
----------
r, c : int
    Centre coordinate of ellipse.
r_radius, c_radius : int
    Minor and major semi-axes. ``(r/r_radius)**2 + (c/c_radius)**2 = 1``.
orientation : double, optional
    Major axis orientation in clockwise direction as radians.
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output
    pixel coordinates. This is useful for ellipses that exceed the image
    size. If None, the full extent of the ellipse is used.  Must be at
    least length 2. Only the first two values are used to determine the
    extent of the input image.

Returns
-------
rr, cc : (N,) ndarray of int
    Indices of pixels that belong to the ellipse perimeter.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

References
----------
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
       http://members.chello.at/easyfilter/Bresenham.pdf

Examples
--------
>>> from skimage.draw import ellipse_perimeter
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = ellipse_perimeter(5, 5, 3, 4)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
       [0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
       [0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)


Note that the positions of `ellipse` without specified `shape` can have
also, negative values, as this is correct on the plane. On the other hand
using these ellipse positions for an image afterwards may lead to appearing
on the other side of image, because ``image[-1, -1] = image[end-1, end-1]``

>>> rr, cc = ellipse_perimeter(2, 3, 4, 5)
>>> img = np.zeros((9, 12), dtype=np.uint8)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
       [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
       [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]], dtype=uint8)
)r   )r$   r%   r5   r6   orientationr   s         r'   ellipse_perimeterru     s    H aHKKr)   c           
          [        XX#XEXg5      $ )a  Generate Bezier curve coordinates.

Parameters
----------
r0, c0 : int
    Coordinates of the first control point.
r1, c1 : int
    Coordinates of the middle control point.
r2, c2 : int
    Coordinates of the last control point.
weight : double
    Middle control point weight, it describes the line tension.
shape : tuple, optional
    Image shape which is used to determine the maximum extent of output
    pixel coordinates. This is useful for curves that exceed the image
    size. If None, the full extent of the curve is used.

Returns
-------
rr, cc : (N,) ndarray of int
    Indices of pixels that belong to the Bezier curve.
    May be used to directly index into an array, e.g.
    ``img[rr, cc] = 1``.

Notes
-----
The algorithm is the rational quadratic algorithm presented in
reference [1]_.

References
----------
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
       http://members.chello.at/easyfilter/Bresenham.pdf

Examples
--------
>>> import numpy as np
>>> from skimage.draw import bezier_curve
>>> img = np.zeros((10, 10), dtype=np.uint8)
>>> rr, cc = bezier_curve(1, 5, 5, -2, 8, 8, 2)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
)r   )rf   rg   rh   ri   r2c2weightr   s           r'   bezier_curverz     s    l ??r)   c           
         [        XUS9u  pEUbS  [        U 5      n[        R                  " USU U5      n[        R                  " [        R
                  " USU 5      U5      n[        R                  " [        [        U5      [        U5      5       VVs/ s H  u  px[        R                  " Xx5      PM     snn6 n	U	$ s  snnf )a	  Generate coordinates of pixels within a rectangle.

Parameters
----------
start : tuple
    Origin point of the rectangle, e.g., ``([plane,] row, column)``.
end : tuple
    End point of the rectangle ``([plane,] row, column)``.
    For a 2D matrix, the slice defined by the rectangle is
    ``[start:(end+1)]``.
    Either `end` or `extent` must be specified.
extent : tuple
    The extent (size) of the drawn rectangle.  E.g.,
    ``([num_planes,] num_rows, num_cols)``.
    Either `end` or `extent` must be specified.
    A negative extent is valid, and will result in a rectangle
    going along the opposite direction. If extent is negative, the
    `start` point is not included.
shape : tuple, optional
    Image shape used to determine the maximum bounds of the output
    coordinates. This is useful for clipping rectangles that exceed
    the image size. By default, no clipping is done.

Returns
-------
coords : array of int, shape (Ndim, Npoints)
    The coordinates of all pixels in the rectangle.

Notes
-----
This function can be applied to N-dimensional images, by passing `start` and
`end` or `extent` as tuples of length N.

Examples
--------
>>> import numpy as np
>>> from skimage.draw import rectangle
>>> img = np.zeros((5, 5), dtype=np.uint8)
>>> start = (1, 1)
>>> extent = (3, 3)
>>> rr, cc = rectangle(start, extent=extent, shape=img.shape)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]], dtype=uint8)


>>> img = np.zeros((5, 5), dtype=np.uint8)
>>> start = (0, 1)
>>> end = (3, 3)
>>> rr, cc = rectangle(start, end=end, shape=img.shape)
>>> img[rr, cc] = 1
>>> img
array([[0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 1, 1, 1, 0],
       [0, 0, 0, 0, 0]], dtype=uint8)

>>> import numpy as np
>>> from skimage.draw import rectangle
>>> img = np.zeros((6, 6), dtype=np.uint8)
>>> start = (3, 3)
>>>
>>> rr, cc = rectangle(start, extent=(2, 2))
>>> img[rr, cc] = 1
>>> rr, cc = rectangle(start, extent=(-2, 2))
>>> img[rr, cc] = 2
>>> rr, cc = rectangle(start, extent=(-2, -2))
>>> img[rr, cc] = 3
>>> rr, cc = rectangle(start, extent=(2, -2))
>>> img[rr, cc] = 4
>>> print(img)
[[0 0 0 0 0 0]
 [0 3 3 2 2 0]
 [0 3 3 2 2 0]
 [0 4 4 1 1 0]
 [0 4 4 1 1 0]
 [0 0 0 0 0 0]]

startendextentr   )
_rectangle_slicerK   r   r2   r1   
zeros_likemeshgridziptuplearange)
r}   r~   r   r   tlbrn_dimstenr_   s
             r'   	rectangler   	  s    j E6BFBE
ZZa+ZZeAen5r:[[3uRy%PR);TU;T299R,;TUVFM Vs   "B=
c                     [        XUS9u  pVUS-  nUS   US   US   US   US   /nUS   US   US   US   US   /n[        XxX4S9$ )a  Generate coordinates of pixels that are exactly around a rectangle.

Parameters
----------
start : tuple
    Origin point of the inner rectangle, e.g., ``(row, column)``.
end : tuple
    End point of the inner rectangle ``(row, column)``.
    For a 2D matrix, the slice defined by inner the rectangle is
    ``[start:(end+1)]``.
    Either `end` or `extent` must be specified.
extent : tuple
    The extent (size) of the inner rectangle.  E.g.,
    ``(num_rows, num_cols)``.
    Either `end` or `extent` must be specified.
    Negative extents are permitted. See `rectangle` to better
    understand how they behave.
shape : tuple, optional
    Image shape used to determine the maximum bounds of the output
    coordinates. This is useful for clipping perimeters that exceed
    the image size. By default, no clipping is done.  Must be at least
    length 2. Only the first two values are used to determine the extent of
    the input image.
clip : bool, optional
    Whether to clip the perimeter to the provided shape. If this is set
    to True, the drawn figure will always be a closed polygon with all
    edges visible.

Returns
-------
coords : array of int, shape (2, Npoints)
    The coordinates of all pixels in the rectangle.

Examples
--------
.. testsetup::
    >>> import pytest; _ = pytest.importorskip('matplotlib')

>>> import numpy as np
>>> from skimage.draw import rectangle_perimeter
>>> img = np.zeros((5, 6), dtype=np.uint8)
>>> start = (2, 3)
>>> end = (3, 4)
>>> rr, cc = rectangle_perimeter(start, end=end, shape=img.shape)
>>> img[rr, cc] = 1
>>> img
array([[0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1],
       [0, 0, 1, 0, 0, 1],
       [0, 0, 1, 0, 0, 1],
       [0, 0, 1, 1, 1, 1]], dtype=uint8)

>>> img = np.zeros((5, 5), dtype=np.uint8)
>>> r, c = rectangle_perimeter(start, (10, 10), shape=img.shape, clip=True)
>>> img[r, c] = 1
>>> img
array([[0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1],
       [0, 0, 1, 0, 1],
       [0, 0, 1, 0, 1],
       [0, 0, 1, 1, 1]], dtype=uint8)

r|   r   r   )r   rO   )r   rT   )	r}   r~   r   r   rO   top_leftbottom_rightr$   r%   s	            r'   rectangle_perimeterr   h  sr    B .E6RHMH	!hqk<?LOXa[QA	!l1o|AXa[QAQ::r)   c                    Uc  Uc  [        S5      eUb  Ub  [        S5      eUb-  [        R                  " U 5      [        R                  " U5      -   n[        R                  " X5      n[        R                  " X5      n[        R
                  " U5      R                  [        5      n[        R
                  " U5      R                  [        5      nUc  US-  nX44$ )a(  Return the slice ``(top_left, bottom_right)`` of the rectangle.

Returns
-------
(top_left, bottom_right)
    The slice you would need to select the region in the rectangle defined
    by the parameters.
    Select it like:

    ``rect[top_left[0]:bottom_right[0], top_left[1]:bottom_right[1]]``
z'Either `end` or `extent` must be given.z'Cannot provide both `end` and `extent`.r   )rF   r   rN   r2   r1   rI   r.   r/   )r}   r~   r   r   r   s        r'   r   r     s     {v~BCC
6-BCCjj"**V"44zz%%H::e)Lxx!((-H88L)005L~##r)   )        )Nr   )NF)r   )N)	bresenhamN)r   N)NNN)NNNF)NN) numpyr   _shared._geometryr   _shared.version_requirementsr   _shared.compatr   _drawr   r	   r
   r   r   r   r   r   r(   r@   rC   rT   rc   rL   rk   rm   rp   rr   ru   rz   r   r   r    r)   r'   <module>r      s     , 2 .	 	 	!%H_D #' =0@ 	wN3  N3b>!B'!T'$TK!\<:~:5zDLN6@r\~ 	wE;  E;P$r)   