
    6Dh_               
          S r SSKrSSKJr  \R
                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  \R                  4
r\ V s0 s H9  o \R!                  U 5      R"                  \R!                  U 5      R$                  4_M;     sn r\R(                  S\R*                  S\R,                  S\R.                  S0r\R3                  \5        \R5                  5       r\R3                  S \R9                  5        5       5        \R3                  SSS	\\R(                     \\R.                     S
.5        SS jrS rSS jrgs  sn f )zVendored code from scikit-image in order to limit the number of dependencies
Extracted from scikit-image/skimage/exposure/exposure.py
    N)warn)FT)   c              #   B   #    U  H  u  pUR                   U4v   M     g 7f)N)__name__).0dlimitss      M/var/www/html/env/lib/python3.13/site-packages/plotly/express/imshow_utils.py	<genexpr>r       s     M9LIAAJJ'9Ls   )r   i  )r   i  )r   i?  )uint10uint12uint14boolfloatc                     US:X  a  U R                   R                  nUS:X  a/  [        R                  " U 5      n[        R                  " U 5      nX44$ U[
        ;   a  [
        U   u  p4U(       a  SnX44$ Uu  p4X44$ )a
  Return image intensity range (min, max) based on desired value type.

Parameters
----------
image : array
    Input image.
range_values : str or 2-tuple, optional
    The image intensity range is configured by this parameter.
    The possible values for this parameter are enumerated below.

    'image'
        Return image min/max as the range.
    'dtype'
        Return min/max of the image's dtype as the range.
    dtype-name
        Return intensity range based on desired `dtype`. Must be valid key
        in `DTYPE_RANGE`. Note: `image` is ignored for this range type.
    2-tuple
        Return `range_values` as min/max intensities. Note that there's no
        reason to use this function if you just want to specify the
        intensity range explicitly. This option is included for functions
        that use `intensity_range` to support all desired range types.

clip_negative : bool, optional
    If True, clip the negative range (i.e. return 0 for min intensity)
    even if the image dtype allows negative values.
dtypeimager   )r   typenpminmaxDTYPE_RANGE)r   range_valuesclip_negativei_mini_maxs        r   intensity_ranger   ,   s    8 w{{''wuu < 
	$"<0E < $<    c                 `   [        U 5      [        [        [        R                  4;   a  [        R
                  $ [        U 5      [         :X  a  U $ U [        ;   a!   [        R                  " U 5      R                   $ [        S[        U 5      -  5      e! [         a    [        R                  s $ f = f)a  Determine the output dtype for rescale_intensity.

The dtype is determined according to the following rules:
- if ``dtype_or_range`` is a dtype, that is the output dtype.
- if ``dtype_or_range`` is a dtype string, that is the dtype used, unless
  it is not a NumPy data type (e.g. 'uint12' for 12-bit unsigned integers),
  in which case the data type that can contain it will be used
  (e.g. uint16 in this case).
- if ``dtype_or_range`` is a pair of values, the output data type will be
  float.

Parameters
----------
dtype_or_range : type, string, or 2-tuple of int/float
    The desired range for the output, expressed as either a NumPy dtype or
    as a (min, max) pair of numbers.

Returns
-------
out_dtype : type
    The data type appropriate for the desired output.
z]Incorrect value for out_range, should be a valid image data type or a pair of values, got %s.)r   listtupler   ndarrayfloat_r   r   	TypeErroruint16
ValueErrorstr)dtype_or_ranges    r   _output_dtyper*   W   s    . NeRZZ88yyNt#$	88N+000
 025n2EF
 	
	  	99	s   B B-,B-c           	         US;   a   [        U R                  R                  5      nO[        U5      n[        [        [        X5      5      u  pE[        [        [        XUS:  S95      u  pg[        R                  " [        R                  " XEXg/5      5      (       a
  [        SSS9  [        R                  " XU5      n XE:w  a&  X-
  XT-
  -  n [        R                  " XU-
  -  U-   US9$ [        R                  " XU5      R                  U5      $ )a  Return image after stretching or shrinking its intensity levels.

The desired intensity range of the input and output, `in_range` and
`out_range` respectively, are used to stretch or shrink the intensity range
of the input image. See examples below.

Parameters
----------
image : array
    Image array.
in_range, out_range : str or 2-tuple, optional
    Min and max intensity values of input and output image.
    The possible values for this parameter are enumerated below.

    'image'
        Use image min/max as the intensity range.
    'dtype'
        Use min/max of the image's dtype as the intensity range.
    dtype-name
        Use intensity range based on desired `dtype`. Must be valid key
        in `DTYPE_RANGE`.
    2-tuple
        Use `range_values` as explicit min/max intensities.

Returns
-------
out : array
    Image array after rescaling its intensity. This image is the same dtype
    as the input image.

Notes
-----
.. versionchanged:: 0.17
    The dtype of the output array has changed to match the output dtype, or
    float if the output range is specified by a pair of floats.

See Also
--------
equalize_hist

Examples
--------
By default, the min/max intensities of the input image are stretched to
the limits allowed by the image's dtype, since `in_range` defaults to
'image' and `out_range` defaults to 'dtype':

>>> image = np.array([51, 102, 153], dtype=np.uint8)
>>> rescale_intensity(image)
array([  0, 127, 255], dtype=uint8)

It's easy to accidentally convert an image dtype from uint8 to float:

>>> 1.0 * image
array([ 51., 102., 153.])

Use `rescale_intensity` to rescale to the proper range for float dtypes:

>>> image_float = 1.0 * image
>>> rescale_intensity(image_float)
array([0. , 0.5, 1. ])

To maintain the low contrast of the original, use the `in_range` parameter:

>>> rescale_intensity(image_float, in_range=(0, 255))
array([0.2, 0.4, 0.6])

If the min/max value of `in_range` is more/less than the min/max image
intensity, then the intensity levels are clipped:

>>> rescale_intensity(image_float, in_range=(0, 102))
array([0.5, 1. , 1. ])

If you have an image with signed integers but want to rescale the image to
just the positive range, use the `out_range` parameter. In that case, the
output dtype will be float:

>>> image = np.array([-10, 0, 10], dtype=np.int8)
>>> rescale_intensity(image, out_range=(0, 127))
array([  0. ,  63.5, 127. ])

To get the desired range with a specific dtype, use ``.astype()``:

>>> rescale_intensity(image, out_range=(0, 127)).astype(np.int8)
array([  0,  63, 127], dtype=int8)

If the input image is constant, the output will be clipped directly to the
output range:
>>> image = np.array([130, 130, 130], dtype=np.int32)
>>> rescale_intensity(image, out_range=(0, 127)).astype(np.int32)
array([127, 127, 127], dtype=int32)
)r   r   r   )r   zOne or more intensity levels are NaN. Rescaling will broadcast NaN to the full image. Provide intensity levels yourself to avoid this. E.g. with np.nanmin(image), np.nanmax(image).   )
stacklevel)r   )r*   r   r   mapr   r   r   anyisnanr   clipasarrayastype)r   in_range	out_range	out_dtypeiminimaxominomaxs           r   rescale_intensityr;      s    x &&!%++"2"23	!),	UOE<=JDu	KJD 
vvbhhD/011H 		
 GGE&E|$+.zz%$;/$6iHHwwuD)00;;r   )r   F)r   r   ) __doc__numpyr   warningsr   byteubyteshortushortintcuintcint_uintlonglong	ulonglong_integer_typesiinfor   r   _integer_rangesbool_float16float32float64dtype_rangeupdatecopyr   itemsr   r*   r;   )ts   0r   <module>rU      sN     GGHHHHIIGGHHGGGGKKLL CQQ.Qrxx{88.QHHmJJJJJJ	   ? #     M9J9J9LM M      BHH%RZZ((V)
Xt<] Rs   A E<