
    9is!                     .    S /r SSKrSSKJr  S rSS jrg)random_noise    N   )img_as_floatc                    U S:X  a  [         R                  " U[        S9$ U S:X  a  [         R                  " U[        S9$ UR	                  U5      U :*  $ )a  
Bernoulli trials at a given probability of a given size.

This function is meant as a lower-memory alternative to calls such as
`np.random.choice([True, False], size=image.shape, p=[p, 1-p])`.
While `np.random.choice` can handle many classes, for the 2-class case
(Bernoulli trials), this function is much more efficient.

Parameters
----------
p : float
    The probability that any given trial returns `True`.
shape : int or tuple of ints
    The shape of the ndarray to return.
rng : `numpy.random.Generator`
    ``Generator`` instance, typically obtained via `np.random.default_rng()`.

Returns
-------
out : ndarray[bool]
    The results of Bernoulli trials in the given `size` where success
    occurs with probability `p`.
r   )dtyper   )npzerosboolonesrandom)pshaperngs      R/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/util/noise.py
_bernoullir      sH    0 	AvxxT**AvwwuD))::e!!    c                    UR                  5       nU R                  5       S:  a  SnOSn[        U 5      n [        R                  R                  U5      nSSSSSSSS	.nSS
SS[        R                  " U 5      S
-   S.nSS/S/S/SS// S.nU H"  n	XXa      ;  d  M  [        U	 SXU       35      e   XU       H  n
UR                  XU
   5        M     US:X  a,  UR                  US   US   S-  U R                  5      nX-   nGOUS:X  aB  US   S:*  R                  5       (       a  [        S5      eXR                  SUS   S-  5      -   nGO_US:X  a  [        [        R                  " U 5      5      nS[        R                  " [        R                  " U5      5      -  nUS:X  a  U R!                  5       nU S-   US-   -  n UR#                  X-  5      [%        U5      -  nUS:X  a  UWS-   -  S-
  nOUS:X  a  ['        U SX$S   SS9nOUS:X  a  ['        U SX$S   SS9nOUS:X  aV  U R)                  5       nUS   nUS   n[+        XR                  US9n[+        UU R                  US9nU) nS UUU-  '   X\UU-  '   O3US!:X  a-  UR                  US   US   S-  U R                  5      nX U-  -   nU(       a  [        R,                  " WUS5      nW$ )"a  
Function to add random noise of various types to a floating-point image.

Parameters
----------
image : ndarray
    Input image data. Will be converted to float.
mode : str, optional
    One of the following strings, selecting the type of noise to add:

    'gaussian' (default)
        Gaussian-distributed additive noise.
    'localvar'
        Gaussian-distributed additive noise, with specified local variance
        at each point of `image`.
    'poisson'
        Poisson-distributed noise generated from the data.
    'salt'
        Replaces random pixels with 1.
    'pepper'
        Replaces random pixels with 0 (for unsigned images) or -1 (for
        signed images).
    's&p'
        Replaces random pixels with either 1 or `low_val`, where `low_val`
        is 0 for unsigned images or -1 for signed images.
    'speckle'
        Multiplicative noise using ``out = image + n * image``, where ``n``
        is Gaussian noise with specified mean & variance.
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.
clip : bool, optional
    If True (default), the output will be clipped after noise applied
    for modes `'speckle'`, `'poisson'`, and `'gaussian'`. This is
    needed to maintain the proper image data range. If False, clipping
    is not applied, and the output may extend beyond the range [-1, 1].
mean : float, optional
    Mean of random distribution. Used in 'gaussian' and 'speckle'.
    Default : 0.
var : float, optional
    Variance of random distribution. Used in 'gaussian' and 'speckle'.
    Note: variance = (standard deviation) ** 2. Default : 0.01
local_vars : ndarray, optional
    Array of positive floats, same shape as `image`, defining the local
    variance at every image point. Used in 'localvar'.
amount : float, optional
    Proportion of image pixels to replace with noise on range [0, 1].
    Used in 'salt', 'pepper', and 'salt & pepper'. Default : 0.05
salt_vs_pepper : float, optional
    Proportion of salt vs. pepper noise for 's&p' on range [0, 1].
    Higher values represent more salt. Default : 0.5 (equal amounts)

Returns
-------
out : ndarray
    Output floating-point image data on range [0, 1] or [-1, 1] if the
    input `image` was unsigned or signed, respectively.

Notes
-----
Speckle, Poisson, Localvar, and Gaussian noise may generate noise outside
the valid image range. The default is to clip (not alias) these values,
but they may be preserved by setting `clip=False`. Note that in this case
the output may contain values outside the ranges [0, 1] or [-1, 1].
Use this option with care.

Because of the prevalence of exclusively positive floating-point images in
intermediate calculations, it is not possible to intuit if an input is
signed based on dtype alone. Instead, negative values are explicitly
searched for. Only if found does this function assume signed input.
Unexpected results only occur in rare, poorly exposes cases (e.g. if all
values are above 50 percent gray in a signed `image`). In this event,
manually scaling the input to the positive domain will solve the problem.

The Poisson distribution is only defined for positive integers. To apply
this noise type, the number of unique values in the image is found and
the next round power of two is used to scale up the floating-point result,
after which it is scaled back down to the floating-point image range.

To generate Poisson noise against a signed image, the signed image is
temporarily converted to an unsigned image in the floating point domain,
Poisson noise is generated, then it is returned to the original range.

r   g      g        gaussian_valueslocalvar_valuespoisson_values	sp_values
s&p_values)gaussianlocalvarpoissonsaltpeppers&pspeckleg{Gz?g?g      ?)meanvaramountsalt_vs_pepper
local_varsr    r!   r$   r"   r#   )r   r   r   r   r   z! keyword not in allowed keywords r   r   z'All values of `local_vars` must be > 0.r      g      ?r   r   )moder   r"   r#   r   )r   r   r   )lowerminr   r   r   default_rng
zeros_like
ValueError
setdefaultnormalr   anylenuniqueceillog2maxr   floatr   copyr   clip)imager&   r   r6   kwargslow_clipallowedtypes
kwdefaultsallowedkwargskeykwnoiseoutvalsold_maxr   qflippedsaltedpeppereds                       r   r   r   '   s3   l ::<D yy{QE
))


$C &%#$L mmE*T1J #E?(>Z!12M L$677%8 d!3457   ./"n- 0 z

6&>6%=C+?Mm		< A%**,,FGG jjF<$8C$?@@		299U#$BGGBGGDM** tiikGS[Ws]3E kk%,'%+5 t3'#-C	3h/?PS
 
	3h/?PS
 
jjl8#$Q5Au{{47 !Gf"*Gh		

6&>6%=C+?Mem# ggc8S)Jr   )r   NT)__all__numpyr   r   r   r   r    r   r   <module>rJ      s    
  ">Br   