
    a6d                         d dl Z d dlZddlmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZ g d	ZddZ	 	 ddZddZddZddZd ZdS )    N   )warn)is_low_contrast)rgb2grayrgba2rgbcall_plugin   )file_or_url_context)imreadimsaveimshowshowimread_collectionimshow_collectionFc                    t          | t          j                  r!t          |                                           } |9t          | d          r)|                                                     d          rd}t          |           5 } t          d| fd|i|}ddd           n# 1 swxY w Y   t          |d          s|S |j
        dk    r{|j        d	         d
vr;|j        d         d
v r,t          j        |d	d          }t          j        |dd          }|r/|j        d         dk    rt          |          }t          |          }|S )a  Load an image from file.

    Parameters
    ----------
    fname : str or pathlib.Path
        Image file name, e.g. ``test.jpg`` or URL.
    as_gray : bool, optional
        If True, convert color images to gray-scale (64-bit floats).
        Images that are already in gray-scale format are not converted.
    plugin : str, optional
        Name of plugin to use.  By default, the different plugins are
        tried (starting with imageio) until a suitable
        candidate is found.  If not given and fname is a tiff file, the
        tifffile plugin will be used.

    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.

    Returns
    -------
    img_array : ndarray
        The different color bands/channels are stored in the
        third dimension, such that a gray-image is MxN, an
        RGB-image MxNx3 and an RGBA-image MxNx4.

    Nlowerz.tiffz.tiftifffiler   pluginndimr   )      r   )
isinstancepathlibPathstrresolvehasattrr   endswithr   r	   r   shapenpswapaxesr   r   )fnameas_grayr   plugin_argsimgs        .lib/python3.11/site-packages/skimage/io/_io.pyr   r      s   : %&& %EMMOO$$~'%11~;;==!!"344 	 F	U	#	# Iu(EHH&HKHHI I I I I I I I I I I I I I I 3 

x!||9R=&&39R=F+B+B+c2r**C+c2r**C 	 y|q  smm3--CJs   B##B'*B'Tc                 $    t          d| |fd|i|S )a  
    Load a collection of images.

    Parameters
    ----------
    load_pattern : str or list
        List of objects to load. These are usually filenames, but may
        vary depending on the currently active plugin.  See the docstring
        for ``ImageCollection`` for the default behaviour of this parameter.
    conserve_memory : bool, optional
        If True, never keep more than one in memory at a specific
        time.  Otherwise, images will be cached once they are loaded.

    Returns
    -------
    ic : ImageCollection
        Collection of images.

    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.

    r   r   r   )load_patternconserve_memoryr   r)   s       r+   r   r   G   s2    4 *L/ 5 5$5(35 5 5    c                    t          | t          j                  r!t          |                                           } |9t          | d          r)|                                                     d          rd}|j        t          k    r,t          |  dd           |                    d          d	z  }|r!t          |          rt          |  d
           t          d| |fd|i|S )a  Save an image to file.

    Parameters
    ----------
    fname : str or pathlib.Path
        Target filename.
    arr : ndarray of shape (M,N) or (M,N,3) or (M,N,4)
        Image data.
    plugin : str, optional
        Name of plugin to use.  By default, the different plugins are
        tried (starting with imageio) until a suitable
        candidate is found.  If not given and fname is a tiff file, the
        tifffile plugin will be used.
    check_contrast : bool, optional
        Check for low contrast and print warning (default: True).

    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.

    Notes
    -----
    When saving a JPEG, the compression ratio may be controlled using the
    ``quality`` keyword argument which is an integer with values in [1, 100]
    where 1 is worst quality and smallest file size, and 100 is best quality
    and largest file size (default 75).  This is only available when using
    the PIL and imageio plugins.
    Nr   r   r   z~ is a boolean image: setting True to 255 and False to 0. To silence this warning, please convert the image using img_as_ubyte.r   )
stackleveluint8   z is a low contrast imager   r   )r   r   r   r    r!   r"   r   r#   dtypeboolr   astyper   r	   )r'   arrr   check_contrastr)   s        r+   r   r   e   s   < %&& %EMMOO$$~'%11~;;==!!"344 	 F
yD   )*	, 	, 	, 	, jj!!C' 1/#.. 1///000xJJFJkJJJr/   c                 p    t          | t                    rt          d| |          } t          d| fd|i|S )a  Display an image.

    Parameters
    ----------
    arr : ndarray or str
        Image data or name of image file.
    plugin : str
        Name of plugin to use.  By default, the different plugins are
        tried (starting with imageio) until a suitable
        candidate is found.

    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.

    r   )r   r   r   )r   r    r	   )r7   r   r)   s      r+   r   r      sG    $ #s 8(C777xCCVC{CCCr/   c                 "    t          d| fd|i|S )ap  Display a collection of images.

    Parameters
    ----------
    ic : ImageCollection
        Collection to display.
    plugin : str
        Name of plugin to use.  By default, the different plugins are
        tried until a suitable candidate is found.

    Other Parameters
    ----------------
    plugin_args : keywords
        Passed to the given plugin.

    r   r   r   )icr   r)   s      r+   r   r      s"    " *BMMvMMMMr/   c                       t          d          S )a  Display pending images.

    Launch the event loop of the current gui plugin, and display all
    pending images, queued via `imshow`. This is required when using
    `imshow` from non-interactive scripts.

    A call to `show` will block execution of code until all windows
    have been closed.

    Examples
    --------
    >>> import skimage.io as io

    >>> rng = np.random.default_rng()
    >>> for i in range(4):
    ...     ax_im = io.imshow(rng.random((50, 50)))
    >>> io.show() # doctest: +SKIP

    	_app_showr    r/   r+   r   r      s    ( {###r/   )FN)TN)NT)N)r   numpyr%   _shared.utilsr   exposurer   color.colorconvr   r   io.manage_pluginsr	   utilr   __all__r   r   r   r   r   r   r>   r/   r+   <module>rF      s                    & & & & & & 0 0 0 0 0 0 0 0 + + + + + + % % % % % %5 5 54 4 4 4n 59!5 5 5 5<*K *K *K *KZD D D D.N N N N($ $ $ $ $r/   