
    9i)                     r    S r SSKrSSKJr  SSKJrJr  SSKJ	r	J
r
Jr  SSKJr  SSSS	S
.S jrSSSS.S jrg)zflood_fill.py - in place flood fill algorithm

This module provides a function to fill all equal (or within tolerance) values
connected to a given seed point with a different value.
    N   )crop   )_flood_fill_equal_flood_fill_tolerance)_offsets_to_raveled_neighbors_resolve_neighborhood_set_border_values)numeric_dtype_min_maxF)	footprintconnectivity	tolerancein_placec                V    [        U UUUUS9nU(       d  U R                  5       n X U'   U $ )at  Perform flood filling on an image.

Starting at a specific `seed_point`, connected points equal or within
`tolerance` of the seed value are found, then set to `new_value`.

Parameters
----------
image : ndarray
    An n-dimensional array.
seed_point : tuple or int
    The point in `image` used as the starting point for the flood fill.  If
    the image is 1D, this point may be given as an integer.
new_value : `image` type
    New value to set the entire fill.  This must be chosen in agreement
    with the dtype of `image`.
footprint : ndarray, optional
    The footprint (structuring element) used to determine the neighborhood
    of each evaluated pixel. It must contain only 1's and 0's, have the
    same number of dimensions as `image`. If not given, all adjacent pixels
    are considered as part of the neighborhood (fully connected).
connectivity : int, optional
    A number used to determine the neighborhood of each evaluated pixel.
    Adjacent pixels whose squared distance from the center is less than or
    equal to `connectivity` are considered neighbors. Ignored if
    `footprint` is not None.
tolerance : float or int, optional
    If None (default), adjacent values must be strictly equal to the
    value of `image` at `seed_point` to be filled.  This is fastest.
    If a tolerance is provided, adjacent points with values within plus or
    minus tolerance from the seed point are filled (inclusive).
in_place : bool, optional
    If True, flood filling is applied to `image` in place.  If False, the
    flood filled result is returned without modifying the input `image`
    (default).

Returns
-------
filled : ndarray
    An array with the same shape as `image` is returned, with values in
    areas connected to and equal (or within tolerance of) the seed point
    replaced with `new_value`.

Notes
-----
The conceptual analogy of this operation is the 'paint bucket' tool in many
raster graphics programs.

Examples
--------
>>> from skimage.morphology import flood_fill
>>> image = np.zeros((4, 7), dtype=int)
>>> image[1:3, 1:3] = 1
>>> image[3, 0] = 1
>>> image[1:3, 4:6] = 2
>>> image[3, 6] = 3
>>> image
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 0, 2, 2, 0],
       [0, 1, 1, 0, 2, 2, 0],
       [1, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, with full connectivity (diagonals included):

>>> flood_fill(image, (1, 1), 5)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [5, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, excluding diagonal points (connectivity 1):

>>> flood_fill(image, (1, 1), 5, connectivity=1)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [1, 0, 0, 0, 0, 0, 3]])

Fill with a tolerance:

>>> flood_fill(image, (0, 0), 5, tolerance=1)
array([[5, 5, 5, 5, 5, 5, 5],
       [5, 5, 5, 5, 2, 2, 5],
       [5, 5, 5, 5, 2, 2, 5],
       [5, 5, 5, 5, 5, 5, 3]])
r   r   r   )floodcopy)image
seed_point	new_valuer   r   r   r   masks           ^/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/morphology/_flood_fill.py
flood_fillr      s:    ~ !D 

$KL    r   c          
         [         R                  " U 5      n U R                  R                  SL a  SnO4U R                  R                  SL a  SnO[         R
                  " U 5      n SnSU R                  ;   a#  [         R                  " U R                  [        S9$  [        U5        X   n[        [         R                  " U5      U R                  -  5      n[        X#U R                  SS9n[        S UR                   5       5      n[        [         R                  " U5      U5       VV	s/ s H5  u  p[         R                   " [         R"                  " X-
  5      5      4S	-  PM7     n
nn	[         R$                  " X
S
U R'                  5       S9n[         R(                  " [        X5       VVVs/ s H  u  nu  pX-   PM     snnnUR                  US9n[+        UR                  X'US9n[         R                  " UR                  [         R,                  US9n[/        US	U
S9   Ub  [#        U5      n[1        UR2                  5      u  nn[!        UR5                  5       UR5                  5       U-
  5      n['        UR5                  5       UR5                  5       U-   5      n[7        UR9                  U5      UR9                  U5      UUUUU5        O.[;        UR9                  U5      UR9                  U5      UUU5         [?        UU
SS9RA                  [        5      $ ! [         a    U4n GNf = fs  sn	nf s  snnnf ! [         a+    UR2                  [         R<                  :X  a  [        S5      ee f = f)a  Mask corresponding to a flood fill.

Starting at a specific `seed_point`, connected points equal or within
`tolerance` of the seed value are found.

Parameters
----------
image : ndarray
    An n-dimensional array.
seed_point : tuple or int
    The point in `image` used as the starting point for the flood fill.  If
    the image is 1D, this point may be given as an integer.
footprint : ndarray, optional
    The footprint (structuring element) used to determine the neighborhood
    of each evaluated pixel. It must contain only 1's and 0's, have the
    same number of dimensions as `image`. If not given, all adjacent pixels
    are considered as part of the neighborhood (fully connected).
connectivity : int, optional
    A number used to determine the neighborhood of each evaluated pixel.
    Adjacent pixels whose squared distance from the center is less than or
    equal to `connectivity` are considered neighbors. Ignored if
    `footprint` is not None.
tolerance : float or int, optional
    If None (default), adjacent values must be strictly equal to the
    initial value of `image` at `seed_point`.  This is fastest.  If a value
    is given, a comparison will be done at every point and if within
    tolerance of the initial value will also be filled (inclusive).

Returns
-------
mask : ndarray
    A Boolean array with the same shape as `image` is returned, with True
    values for areas connected to and equal (or within tolerance of) the
    seed point.  All other values are False.

Notes
-----
The conceptual analogy of this operation is the 'paint bucket' tool in many
raster graphics programs.  This function returns just the mask
representing the fill.

If indices are desired rather than masks for memory reasons, the user can
simply run `numpy.nonzero` on the result, save the indices, and discard
this mask.

Examples
--------
>>> from skimage.morphology import flood
>>> image = np.zeros((4, 7), dtype=int)
>>> image[1:3, 1:3] = 1
>>> image[3, 0] = 1
>>> image[1:3, 4:6] = 2
>>> image[3, 6] = 3
>>> image
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 1, 1, 0, 2, 2, 0],
       [0, 1, 1, 0, 2, 2, 0],
       [1, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, with full connectivity (diagonals included):

>>> mask = flood(image, (1, 1))
>>> image_flooded = image.copy()
>>> image_flooded[mask] = 5
>>> image_flooded
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [5, 0, 0, 0, 0, 0, 3]])

Fill connected ones with 5, excluding diagonal points (connectivity 1):

>>> mask = flood(image, (1, 1), connectivity=1)
>>> image_flooded = image.copy()
>>> image_flooded[mask] = 5
>>> image_flooded
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [0, 5, 5, 0, 2, 2, 0],
       [1, 0, 0, 0, 0, 0, 3]])

Fill with a tolerance:

>>> mask = flood(image, (0, 0), tolerance=1)
>>> image_flooded = image.copy()
>>> image_flooded[mask] = 5
>>> image_flooded
array([[5, 5, 5, 5, 5, 5, 5],
       [5, 5, 5, 5, 2, 2, 5],
       [5, 5, 5, 5, 2, 2, 5],
       [5, 5, 5, 5, 5, 5, 3]])
TFCr   )dtypeF)enforce_adjacencyc              3   *   #    U  H	  oS -  v   M     g7f)r   N ).0ss     r   	<genexpr>flood.<locals>.<genexpr>   s     3?a6?s   r   constant)modeconstant_values)order)centerr)   )r   r)   )valueborder_widthzLdtype of `image` is float16 which is not supported, try upcasting to float32)r   )!npasarrayflagsf_contiguousc_contiguousascontiguousarrayshapezerosbooliter	TypeErrortupler	   ndimzipnonzeromaxabspadminravel_multi_indexr   uint8r
   r   r   itemr   ravelr   float16r   view)r   r   r   r   r   r)   
seed_valuer*   idxc	pad_widthworking_imagei	pad_startpad_endravelled_seed_idxneighbor_offsetsr/   	min_value	max_valuelow_tolhigh_tols                         r   r   r      s   | JJuE{{4'		!	!T	)$$U+ 	EKKxx400#Z "Jrzz*-;<J%uI 39??33F 69I9NPV5W5W63sw	 "Q&5W  
 FFz599;M ,,69*6PQ6P212y6PQ
 5YU
 HH]((FEuAI>" II $99I9I#J Iy)..*JOO,=	,IJG9>>+Z__->-JKH!##E*E" ! ##E*E" !$ yu-22488O  # ]
# 	RL  "**,6 
 s1   L *<L-,L3!B+L: -L: L*)L*:5M/)__doc__numpyr-   utilr   _flood_fill_cyr   r   _utilr   r	   r
   _shared.dtyper   r   r   r!   r   r   <module>rZ      sH      D 
 2 k\ +/TT u9r   