
    1-Ph1                         d dl Zd ZefdZdS )    Nc                   	 t          j        |           } t          |           }t          j        t          j        |                     }t          j        |           }t          t          j        |                     }||k    rt          d          f|z  S t          j        |||z  d|z  z  d          }||k     	                                r|t          |          D ]l}||         ||<   t          t          j        ||dz   d                             }||z  d||z
  dz
  z  z  ||dz   d<   ||k                                    r nm|dz                      t                    }t          j        |                              t                    }d t          ||          D             	t!          	fd|D                       		S )	a  Find `n_points` regularly spaced along `ar_shape`.

    The returned points (as slices) should be as close to cubically-spaced as
    possible. Essentially, the points are spaced by the Nth root of the input
    array size, where N is the number of dimensions. However, if an array
    dimension cannot fit a full step size, it is "discarded", and the
    computation is done for only the remaining dimensions.

    Parameters
    ----------
    ar_shape : array-like of ints
        The shape of the space embedding the grid. ``len(ar_shape)`` is the
        number of dimensions.
    n_points : int
        The (approximate) number of points to embed in the space.

    Returns
    -------
    slices : tuple of slice objects
        A slice along each dimension of `ar_shape`, such that the intersection
        of all the slices give the coordinates of regularly spaced points.

        .. versionchanged:: 0.14.1
            In scikit-image 0.14.1 and 0.15, the return type was changed from a
            list to a tuple to ensure `compatibility with Numpy 1.15`_ and
            higher. If your code requires the returned result to be a list, you
            may convert the output of this function to a list with:

            >>> result = list(regular_grid(ar_shape=(3, 20, 40), n_points=8))

            .. _compatibility with NumPy 1.15: https://github.com/numpy/numpy/blob/master/doc/release/1.15.0-notes.rst#deprecations

    Examples
    --------
    >>> ar = np.zeros((20, 40))
    >>> g = regular_grid(ar.shape, 8)
    >>> g
    (slice(5, None, 10), slice(5, None, 10))
    >>> ar[g] = 1
    >>> ar.sum()
    8.0
    >>> ar = np.zeros((20, 40))
    >>> g = regular_grid(ar.shape, 32)
    >>> g
    (slice(2, None, 5), slice(2, None, 5))
    >>> ar[g] = 1
    >>> ar.sum()
    32.0
    >>> ar = np.zeros((3, 20, 40))
    >>> g = regular_grid(ar.shape, 8)
    >>> g
    (slice(1, None, 3), slice(5, None, 10), slice(5, None, 10))
    >>> ar[g] = 1
    >>> ar.sum()
    8.0
    Ng      ?float64dtype      c                 6    g | ]\  }}t          |d |          S N)slice).0startsteps      Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/util/_regular_grid.py
<listcomp>z regular_grid.<locals>.<listcomp>N   s(    QQQ;5$eE4&&QQQ    c              3   (   K   | ]}|         V  d S r
    )r   islicess     r   	<genexpr>zregular_grid.<locals>.<genexpr>O   s'      666!9666666r   )np
asanyarraylenargsortsortfloatprodr   fullanyrangeallastypeintroundziptuple)
ar_shapen_pointsndimunsort_dim_idxssorted_dims
space_size	stepsizesdimstartsr   s
            @r   regular_gridr0      s   r }X&&Hx==DjH!5!566O'(##Krwx(())JXd~$$zH4#*EYWWWIi$$&& ;; 	 	C(-IcNrw{3799'=>>??J$.$9sdSjSTn?U#VIcAgii y(--// 1n$$S))F##**3//IQQ#fi:P:PQQQF6666o66666FMr   c                     t          | |          }t          j        | |          }dt          j        t          j        ||         j                  ||         j                  z   ||<   |S )ae  Return an image with ~`n_points` regularly-spaced nonzero pixels.

    Parameters
    ----------
    ar_shape : tuple of int
        The shape of the desired output image.
    n_points : int
        The desired number of nonzero points.
    dtype : numpy data type, optional
        The desired data type of the output.

    Returns
    -------
    seed_img : array of int or bool
        The desired image.

    Examples
    --------
    >>> regular_seeds((5, 5), 4)
    array([[0, 0, 0, 0, 0],
           [0, 1, 0, 2, 0],
           [0, 0, 0, 0, 0],
           [0, 3, 0, 4, 0],
           [0, 0, 0, 0, 0]])
    r   r   )r0   r   zerosreshapearangesizeshape)r'   r(   r   gridseed_imgs        r   regular_seedsr9   S   sg    4 (++Dx...H
	(4.%&&(<  HTN Or   )numpyr   r0   r#   r9   r   r   r   <module>r;      sG       L L L^ -0      r   