B
    \                 @   s   d dl Zd dlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ d	d
ddddgZddd	ZdddZddd
ZdddZdddZdd ZdS )    N   )call_plugin)rgb2gray   )file_or_url_context)is_low_contrast)warnimreadimsaveimshowshowimread_collectionimshow_collectionFc          	   K   s   d|  kr |d|}td |dk	r4|}td |dkrXt| drX|  drXd}t| } td| fd	|i|}W dQ R X t|d
s|S |jdkr|j	d dkr|j	d dkrt
|dd}t
|dd}|rt|}|S )a  Load an image from file.

    Parameters
    ----------
    fname : string
        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 the Python Imaging Library) 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.
    flatten : bool
        Backward compatible keyword, superseded by `as_gray`.

    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.

    Zas_greyz3`as_grey` has been deprecated in favor of `as_gray`NzQ`flatten` has been deprecated in favor of `as_gray` and will be removed in v0.16.lower)z.tiffz.tiftifffiler	   pluginndimr   )      )keyspopr   hasattrr   endswithr   r   r   shapenpZswapaxesr   )fnameZas_grayr   Zflattenplugin_argsZimg r    -lib/python3.7/site-packages/skimage/io/_io.pyr	      s(     
 

Tc             K   s   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   )Zload_patternZconserve_memoryr   r   r    r    r!   r   N   s    c             K   sf   |dkr$t | dr$|  dr$d}t|r8td|   |jtkrNtd|   td| |fd|i|S )	a  Save an image to file.

    Parameters
    ----------
    fname : str
        Target filename.
    arr : ndarray of shape (M,N) or (M,N,3) or (M,N,4)
        Image data.
    plugin : str
        Name of plugin to use.  By default, the different plugins are
        tried (starting with the Python Imaging Library) 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.

    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   )z.tiffz.tifr   z%s is a low contrast imagez7%s is a boolean image: setting True to 1 and False to 0r
   r   )r   r   r   r   r   Zdtypeboolr   )r   arrr   r   r    r    r!   r
   l   s    
c             K   s0   t | tjrtd| |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 the Python Imaging Library) until a suitable
        candidate is found.

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

    r	   )r   r   r   )
isinstancesixZstring_typesr   )r#   r   r   r    r    r!   r      s    c             K   s   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   )Zicr   r   r    r    r!   r      s    c               C   s   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

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

    Z	_app_show)r   r    r    r    r!   r      s    )FNN)TN)N)N)N)Znumpyr   r%   Zio.manage_pluginsr   Zcolorr   utilr   Zexposurer   Z_shared.utilsr   __all__r	   r   r
   r   r   r   r    r    r    r!   <module>   s   
? 

&

