U
    ?h3                     @   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 Z	dd	 Z
dddddZdddddZdddddZdddddZdS )    N   )gaussian)convert_to_float)resizec                 C   sJ   t | }|dk	r.|| j }|f| jd  }nd}t| |||||d |S )z?Return image with each channel smoothed by the Gaussian filter.N   )outputmodecvalchannel_axis)npZ
empty_likendimr   )imagesigmar   r	   r
   smoothed r   L/var/www/html/venv/lib/python3.8/site-packages/skimage/transform/pyramids.py_smooth
   s    

r   c                 C   s   | dkrt dd S )Nr   z#scale factor must be greater than 1)
ValueError)factorr   r   r   _check_factor   s    r   r   reflectFr
   c                   s   t  t| |}  dk	rD | j  t fddt| jD }ntfdd| jD }|dkrpd d }t| ||| }	t|	||||dd}
|
S )	a6  Smooth and then downsample image.

    Parameters
    ----------
    image : ndarray
        Input image.
    downscale : float, optional
        Downscale factor.
    sigma : float, optional
        Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which
        corresponds to a filter mask twice the size of the scale factor that
        covers more than 99% of the Gaussian distribution.
    order : int, optional
        Order of splines used in interpolation of downsampling. See
        `skimage.transform.warp` for detail.
    mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
        The mode parameter determines how the array borders are handled, where
        cval is the value when mode is equal to 'constant'.
    cval : float, optional
        Value to fill past edges of input if mode is 'constant'.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
        Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : array
        Smoothed and downsampled float image.

    References
    ----------
    .. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf

    Nc                 3   s0   | ](\}}| kr$t |t n|V  qd S Nmathceilfloat.0Zaxdr
   	downscaler   r   	<genexpr>Q   s   z!pyramid_reduce.<locals>.<genexpr>c                 3   s    | ]}t |t  V  qd S r   r   r   r   r!   r   r   r"   V   s     r         @Forderr   r	   Zanti_aliasing)r   r   r   tuple	enumerateshaper   r   )r   r!   r   r'   r   r	   preserve_ranger
   	out_shaper   outr   r    r   pyramid_reduce   s    -


r.   c                   s   t  t| |}  dk	rD | j  t fddt| jD }ntfdd| jD }|dkrpd d }t| ||||dd}	t|	||| }
|
S )	a*  Upsample and then smooth image.

    Parameters
    ----------
    image : ndarray
        Input image.
    upscale : float, optional
        Upscale factor.
    sigma : float, optional
        Sigma for Gaussian filter. Default is `2 * upscale / 6.0` which
        corresponds to a filter mask twice the size of the scale factor that
        covers more than 99% of the Gaussian distribution.
    order : int, optional
        Order of splines used in interpolation of upsampling. See
        `skimage.transform.warp` for detail.
    mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
        The mode parameter determines how the array borders are handled, where
        cval is the value when mode is equal to 'constant'.
    cval : float, optional
        Value to fill past edges of input if mode is 'constant'.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
        Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : array
        Upsampled and smoothed float image.

    References
    ----------
    .. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf

    Nc                 3   s,   | ]$\}}| kr t | n|V  qd S r   r   r   r   r
   upscaler   r   r"      s   z!pyramid_expand.<locals>.<genexpr>c                 3   s   | ]}t  | V  qd S r   r/   r#   )r1   r   r   r"      s     r   r%   Fr&   )r   r   r   r(   r)   r*   r   r   )r   r1   r   r'   r   r	   r+   r
   r,   Zresizedr-   r   r0   r   pyramid_expandc   s"    -


  r2   c             	   c   sp   t | t| |} d}	| j}
| }| V  |	|krl|	d7 }	t|||||||d}|
}|}|j}
|
|krdql|V  q&dS )a  Yield images of the Gaussian pyramid formed by the input image.

    Recursively applies the `pyramid_reduce` function to the image, and yields
    the downscaled images.

    Note that the first image of the pyramid will be the original, unscaled
    image. The total number of images is `max_layer + 1`. In case all layers
    are computed, the last image is either a one-pixel image or the image where
    the reduction does not change its shape.

    Parameters
    ----------
    image : ndarray
        Input image.
    max_layer : int, optional
        Number of layers for the pyramid. 0th layer is the original image.
        Default is -1 which builds all possible layers.
    downscale : float, optional
        Downscale factor.
    sigma : float, optional
        Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which
        corresponds to a filter mask twice the size of the scale factor that
        covers more than 99% of the Gaussian distribution.
    order : int, optional
        Order of splines used in interpolation of downsampling. See
        `skimage.transform.warp` for detail.
    mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
        The mode parameter determines how the array borders are handled, where
        cval is the value when mode is equal to 'constant'.
    cval : float, optional
        Value to fill past edges of input if mode is 'constant'.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
        Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    pyramid : generator
        Generator yielding pyramid layers as float images.

    References
    ----------
    .. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf

    r   r   r   N)r   r   r*   r.   )r   	max_layerr!   r   r'   r   r	   r+   r
   layercurrent_shapeZprev_layer_imageZlayer_imageZ
prev_shaper   r   r   pyramid_gaussian   s&    8

  r7   c             	   #   s  t  t| |} |dkr&d d }| j}	t| ||| }
| |
 V   dk	rt | j  t|	}|  t|}n|	}|dkrt	t
t|}t|D ]t} dk	rt fddt|	D }ntfdd|	D }t|
||||dd	}t|||| }
|j}	||
 V  qdS )
ag	  Yield images of the laplacian pyramid formed by the input image.

    Each layer contains the difference between the downsampled and the
    downsampled, smoothed image::

        layer = resize(prev_layer) - smooth(resize(prev_layer))

    Note that the first image of the pyramid will be the difference between the
    original, unscaled image and its smoothed version. The total number of
    images is `max_layer + 1`. In case all layers are computed, the last image
    is either a one-pixel image or the image where the reduction does not
    change its shape.

    Parameters
    ----------
    image : ndarray
        Input image.
    max_layer : int, optional
        Number of layers for the pyramid. 0th layer is the original image.
        Default is -1 which builds all possible layers.
    downscale : float, optional
        Downscale factor.
    sigma : float, optional
        Sigma for Gaussian filter. Default is `2 * downscale / 6.0` which
        corresponds to a filter mask twice the size of the scale factor that
        covers more than 99% of the Gaussian distribution.
    order : int, optional
        Order of splines used in interpolation of downsampling. See
        `skimage.transform.warp` for detail.
    mode : {'reflect', 'constant', 'edge', 'symmetric', 'wrap'}, optional
        The mode parameter determines how the array borders are handled, where
        cval is the value when mode is equal to 'constant'.
    cval : float, optional
        Value to fill past edges of input if mode is 'constant'.
    preserve_range : bool, optional
        Whether to keep the original range of values. Otherwise, the input
        image is converted according to the conventions of `img_as_float`.
        Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
    channel_axis : int or None, optional
        If None, the image is assumed to be a grayscale (single channel) image.
        Otherwise, this parameter indicates which axis of the array corresponds
        to channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    pyramid : generator
        Generator yielding pyramid layers as float images.

    References
    ----------
    .. [1] http://persci.mit.edu/pub_pdfs/pyramid83.pdf
    .. [2] http://sepwww.stanford.edu/data/media/public/sep/morgan/texturematch/paper_html/node3.html

    Nr   r%   r3   c                 3   s0   | ](\}}| kr$t |t n|V  qd S r   r   r   r    r   r   r"   V  s   z$pyramid_laplacian.<locals>.<genexpr>c                 3   s    | ]}t |t  V  qd S r   r   r#   r$   r   r   r"   [  s   Fr&   )r   r   r*   r   r   listpopr(   r   r   logmaxranger)   r   )r   r4   r!   r   r'   r   r	   r+   r
   r6   Zsmoothed_imageZshape_without_channelsr5   r,   Zresized_imager   r    r   pyramid_laplacian   sB    <





  
r=   )r   Nr   r   r   F)r   Nr   r   r   F)r3   r   Nr   r   r   F)r3   r   Nr   r   r   F)r   numpyr   Z_shared.filtersr   Z_shared.utilsr   Z	transformr   r   r   r.   r2   r7   r=   r   r   r   r   <module>   sD        D     C     V     