
    9i>                         S SK r S SKrSSKJrJrJr	  SSK
Jr  S rS rS rS	 r\" \\\\S
9r\" \R'                  5       5      rS r         SSS.S jjrg)    N   )polygondiskellipse   )warnc                    [        US   U S   -
  US   5      US   -
  n[        US   U S   -
  US   5      US   -
  nUS   UR                  [        SU5      5      -   S-
  nUS   UR                  [        SU5      5      -   S-
  n[        U S   U S   U-   U S   U-   U S   /U S   U S   U S   U-   U S   U-   /5      nSU S   U S   U-   S-   4U S   U S   U-   S-   444n	X4$ )al  Generate a mask for a filled rectangle shape.

The height and width of the rectangle are generated randomly.

Parameters
----------
point : tuple
    The row and column of the top left corner of the rectangle.
image : tuple
    The height, width and depth of the image into which the shape
    is placed.
shape : tuple
    The minimum and maximum size of the shape to fit.
random : `numpy.random.Generator`

    The random state to use for random sampling.

Raises
------
ArithmeticError
    When a shape cannot be fit into the image with the given starting
    coordinates. This usually means the image dimensions are too small or
    shape dimensions too large.

Returns
-------
label : tuple
    A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
    bounding box coordinates of the shape.
indices : 2-D array
    A mask of indices that the shape fills.

r   r   	rectangle)minintegersmaxdraw_polygon)
pointimageshaperandomavailable_widthavailable_heightrcr
   labels
             [/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/draw/_random_shapes.py_generate_rectangle_maskr   	   s@   D %(U1X-uQx858CO58eAh.a9E!HD 	a6??3q*:#;<<q@Aa6??3q/#:;;a?A!H!HqL!HqL!H		
 !H!H!HqL!HqL		
I E!HeAhlQ&67%(E!HqLSTDT9UVWE    c           	         US   S:X  d	  US   S:X  a  [        S5      eUS   S-  nUS   S-  nU S   nUS   U S   -
  nU S   nUS   U S   -
  n	[        XgXU5      U-
  n
U
S:  a  [        S5      e[        XCR	                  [        SU
5      5      -   5      n[        U S   U S   4U5      nSU S   U-
  S-   U S   U-   4U S   U-
  S-   U S   U-   444nX4$ )a_  Generate a mask for a filled circle shape.

The radius of the circle is generated randomly.

Parameters
----------
point : tuple
    The row and column of the top left corner of the rectangle.
image : tuple
    The height, width and depth of the image into which the shape is placed.
shape : tuple
    The minimum and maximum size and color of the shape to fit.
random : `numpy.random.Generator`
    The random state to use for random sampling.

Raises
------
ArithmeticError
    When a shape cannot be fit into the image with the given starting
    coordinates. This usually means the image dimensions are too small or
    shape dimensions too large.

Returns
-------
label : tuple
    A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
    bounding box coordinates of the shape.
indices : 2-D array
    A mask of indices that the shape fills.
r   r   zsize must be > 1 for circles       @cannot fit shape to imagecircle)
ValueErrorr   ArithmeticErrorintr   r   	draw_disk)r   r   r   r   
min_radius
max_radiusleftrighttopbottomavailable_radiusradiusr   r   s                 r   _generate_circle_maskr+   D   s/   > Qx1}aA788qSJqSJ8D!HuQxE
(C1Xa F4Z@:M!9::ooc!5E.FGGHF eAha)62D 	1X"E!Hv$561X"E!Hv$56	
E ;r   c                    US   S:X  d	  US   S:X  a  [        S5      e[        US   U S   -
  U S   US   5      US   -
  nUS   UR                  [        SU5      5      -   S-
  n[	        [
        R                  " [
        R                  " S5      U-  5      5      n[        U S   U S   U-
  U S   /U S   U S   US-  -   U S   U-   /5      nSU S   U-
  U S   S-   4U S   U S   U-   S-   444nXx4$ )a  Generate a mask for a filled equilateral triangle shape.

The length of the sides of the triangle is generated randomly.

Parameters
----------
point : tuple
    The row and column of the top left corner of a up-pointing triangle.
image : tuple
    The height, width and depth of the image into which the shape
    is placed.
shape : tuple
    The minimum and maximum size and color of the shape to fit.
random : `numpy.random.Generator`
    The random state to use for random sampling.

Raises
------
ArithmeticError
    When a shape cannot be fit into the image with the given starting
    coordinates. This usually means the image dimensions are too small or
    shape dimensions too large.

Returns
-------
label : tuple
    A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
    bounding box coordinates of the shape.
indices : 2-D array
    A mask of indices that the shape fills.

r   r   z#dimension must be > 1 for trianglesg      ?r   triangle)	r   r   r   r   r!   npceilsqrtr   )	r   r   r   r   available_sidesidetriangle_heightr-   r   s	            r   _generate_triangle_maskr4      s3   B Qx1}aA>??qE!H,eAhaAE!HLN8fooc!^&<==AD"''"'''"2T"9:;O!H!H&!H	
 !H!Htqy !HtO	
H 	
(_
$eAhl	3eAha4RS@S5TUE
 ?r   c           	         US   S:X  d	  US   S:X  a  [        S5      eUS   S-  nUS   S-  nU S   nUS   U S   -
  nU S   nUS   U S   -
  n	[        XgXU5      n
X:  a  [        S5      eUR                  XJS-   5      nUR                  XJS-   5      nUR                  [        R
                  * [        R
                  5      n[        U S   U S   UUUSS US9n[        R                  " [        X5      5      n[        R                  " US   5      n[        R                  " US   5      S-   n[        R                  " US   5      n[        R                  " US   5      S-   nS	UU4UU444nUU4$ )
a  Generate a mask for a filled ellipse shape.

The rotation, major and minor semi-axes of the ellipse are generated
randomly.

Parameters
----------
point : tuple
    The row and column of the top left corner of the rectangle.
image : tuple
    The height, width and depth of the image into which the shape is
    placed.
shape : tuple
    The minimum and maximum size and color of the shape to fit.
random : `numpy.random.Generator`
    The random state to use for random sampling.

Raises
------
ArithmeticError
    When a shape cannot be fit into the image with the given starting
    coordinates. This usually means the image dimensions are too small or
    shape dimensions too large.

Returns
-------
label : tuple
    A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
    bounding box coordinates of the shape.
indices : 2-D array
    A mask of indices that the shape fills.
r   r   zsize must be > 1 for ellipsesr   r   Nr   )r   rotationr   )
r   r   r    uniformr.   pidraw_ellipsemathr/   r   )r   r   r   r   r#   r$   r%   r&   r'   r(   r)   r_radiusc_radiusr6   r   min_xmax_xmin_ymax_yr   s                       r   _generate_ellipse_maskrA      s   B Qx1}aA899qCJqCJ8D!HuQxE
(C1Xa F4Z@$9::
 ~~jQ*>?H~~jQ*>?H~~ruufbee,HaaBQiG 3x23JFF71:EFF71:"EFF71:EFF71:"E%%89EE>r   )r
   r   r-   r   c           	          US:X  a  U4nO[        U5      S:X  a  X!-  nU Vs/ s H  oCR                  US   US   S-   U S9PM     nn[        R                  " U5      $ s  snf )aB  Generate an array of random colors.

Parameters
----------
num_colors : int
    Number of colors to generate.
num_channels : int
    Number of elements representing color.
intensity_range : {tuple of tuples of ints, tuple of ints}, optional
    The range of values to sample pixel values from. For grayscale images
    the format is (min, max). For multichannel - ((min, max),) if the
    ranges are equal across the channels, and
    ((min_0, max_0), ... (min_N, max_N)) if they differ.
random : `numpy.random.Generator`
    The random state to use for random sampling.

Raises
------
ValueError
    When the `intensity_range` is not in the interval (0, 255).

Returns
-------
colors : array
    An array of shape (num_colors, num_channels), where the values for
    each channel are drawn from the corresponding `intensity_range`.

r   r   )size)lenr   r.   	transpose)
num_colorsnum_channelsintensity_ranger   r   colorss         r   _generate_random_colorsrJ     sk    : q*,	_		")8HWX1ooadAaD1H:o>FX<< Ys   #A)channel_axisc          	         X0S   :  d  X0S   :  a  [        S5      eU=(       d    [        U S   U S   5      nUc  SnUc  US:X  a  SOSnO9US:X  a  U4OUnU H(  nU H  nSUs=::  a  S::  a  M  O  Sn[        U5      e   M*     [        R                  R	                  U
5      n
UnU S   U S   U4n [        R
                  " U S[        R                  S9n[        R                  " U [        S9n/ nU
R                  X!S-   5      n[        UXWU
5      nX44n[        U5       H  nUc  U
R                  [        5      nO	[        U   n[        U	5       H  nU
R                  [        SU S   U-
  5      5      nU
R                  [        SU S   U-
  5      5      nUU4n U" UXU
5      u  nnU(       d  UU   R!                  5       (       a  Mx  UU   UU'   S	UU'   UR#                  U5          M     [%        S
5        M     Uc  [        R&                  " USS9nUU4$ [        R(                  " USU5      nUU4$ ! [         a    / n M  f = f)a  Generate an image with random shapes, labeled with bounding boxes.

The image is populated with random shapes with random sizes, random
locations, and random colors, with or without overlap.

Shapes have random (row, col) starting coordinates and random sizes bounded
by `min_size` and `max_size`. It can occur that a randomly generated shape
will not fit the image at all. In that case, the algorithm will try again
with new starting coordinates a certain number of times. However, it also
means that some shapes may be skipped altogether. In that case, this
function will generate fewer shapes than requested.

Parameters
----------
image_shape : tuple
    The number of rows and columns of the image to generate.
max_shapes : int
    The maximum number of shapes to (attempt to) fit into the shape.
min_shapes : int, optional
    The minimum number of shapes to (attempt to) fit into the shape.
min_size : int, optional
    The minimum dimension of each shape to fit into the image.
max_size : int, optional
    The maximum dimension of each shape to fit into the image.
num_channels : int, optional
    Number of channels in the generated image. If 1, generate monochrome
    images, else color images with multiple channels. Ignored if
    ``multichannel`` is set to False.
shape : {rectangle, circle, triangle, ellipse, None} str, optional
    The name of the shape to generate or `None` to pick random ones.
intensity_range : {tuple of tuples of uint8, tuple of uint8}, optional
    The range of values to sample pixel values from. For grayscale
    images the format is (min, max). For multichannel - ((min, max),)
    if the ranges are equal across the channels, and
    ((min_0, max_0), ... (min_N, max_N)) if they differ. As the
    function supports generation of uint8 arrays only, the maximum
    range is (0, 255). If None, set to (0, 254) for each channel
    reserving color of intensity = 255 for background.
allow_overlap : bool, optional
    If `True`, allow shapes to overlap.
num_trials : int, optional
    How often to attempt to fit a shape into the image before skipping it.
rng : {`numpy.random.Generator`, int}, optional
    Pseudo-random number generator.
    By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
    If `rng` is an int, it is used to seed the generator.
channel_axis : int or None, optional
    If None, the image is assumed to be a grayscale (single channel) image.
    Otherwise, this parameter indicates which axis of the array corresponds
    to channels.

    .. versionadded:: 0.19
       ``channel_axis`` was added in 0.19.

Returns
-------
image : uint8 array
    An image with the fitted shapes.
labels : list
    A list of labels, one per shape in the image. Each label is a
    (category, ((r0, r1), (c0, c1))) tuple specifying the category and
    bounding box coordinates of the shape.

Examples
--------
>>> import skimage.draw
>>> image, labels = skimage.draw.random_shapes((32, 32), max_shapes=3)
>>> image # doctest: +SKIP
array([
   [[255, 255, 255],
    [255, 255, 255],
    [255, 255, 255],
    ...,
    [255, 255, 255],
    [255, 255, 255],
    [255, 255, 255]]], dtype=uint8)
>>> labels # doctest: +SKIP
[('circle', ((22, 18), (25, 21))),
 ('triangle', ((5, 6), (13, 13)))]
r   r   z3Minimum dimension must be less than ncols and nrowsr      )rN      z1Intensity range must lie within (0, 255) interval)dtypeTzJCould not fit any shapes to image, consider reducing the minimum dimensionr   )axisrK   )r   r   r.   r   default_rngfulluint8zerosboolr   rJ   rangechoiceSHAPE_CHOICESSHAPE_GENERATORSr    anyappendr   squeezemoveaxis)image_shape
max_shapes
min_shapesmin_sizemax_sizerG   r   rH   allow_overlap
num_trialsrngrL   tmpintensity_pair	intensitymsg
user_shaper   filledlabels
num_shapesrI   	shape_idxshape_generator_columnrowr   indicesr   s                                 r   random_shapesrv   0  s_   ~ a. H1~$=NOO>3{1~{1~>H&2a&7([$0A$5 ?!N+	Y-#-MC$S/) , " ))


$CJq>;q><@KGGKBHH5EXXk.FFjq.9J$ZPSTF E:&	!jj7O.z:Oz"A\\#aQ()B"CDF,,s1k!nx&?@AC&ME!0C!P F7O$7$7$9$9!'	!2g"&we$! #$ :/ '8 

5q) &= E2|4&=+ # s   H//H?>H?)	r   r   N   NNFd   N)r:   numpyr.   drawr   r   r   r"   r   r9   _shared.utilsr   r   r+   r4   rA   dictr[   listvaluesrZ   rJ   rv    r   r   <module>r      s      U U  8v;|7tBL & $"	  %,,./" P 
[ [r   