
    |h-4                         d dl Z d dlZddlmZ ddlmZ ddlmZ d Z	d Z
	 	 	 	 	 	 ddd	d
Z	 	 	 	 	 	 ddd	dZ	 	 	 	 	 	 	 ddd	dZ	 	 	 	 	 	 	 ddd	dZy)    N   )gaussian)convert_to_float   )resizec                     t        j                  |       }|#|| j                  z  }|f| j                  dz
  z  }nd}t        | |||||       |S )z?Return image with each channel smoothed by the Gaussian filter.Nr   )sigmaoutmodecvalchannel_axis)np
empty_likendimr   )imager	   r   r   r   smootheds         Y/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/transform/pyramids.py_smoothr   
   s`    }}U#H #ejj0EJJN+! O    c                 $    | dk  rt        d      y )Nr   z#scale factor must be greater than 1)
ValueError)factors    r   _check_factorr       s    {>?? r   r   c                <   t               t        | |      } 8| j                  z  t        fdt	        | j
                        D              }nt        fd| j
                  D              }|dz  dz  }t        | |||      }	t        |	||||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

    c              3   t   K   | ]/  \  }}|k7  r!t        j                  |t              z        n| 1 y wNmathceilfloat.0axdr   	downscales      r   	<genexpr>z!pyramid_reduce.<locals>.<genexpr>_   s<      
A 02\/ADIIa%	**+qH
   58c              3   `   K   | ]%  }t        j                  |t              z         ' y wr   r   r#   r%   r&   s     r   r'   z!pyramid_reduce.<locals>.<genexpr>d   s$     Oa$))Ai(8$89O   +.r         @Forderr   r   anti_aliasing)r   r   r   tuple	enumerateshaper   r   )r   r&   r	   r.   r   r   preserve_ranger   	out_shaper   r
   s    `     `   r   pyramid_reducer5   %   s    j )UN3E#ejj0 
"5;;/
 
	
 O5;;OO	}I#ueT4>H
)5t$eC Jr   c                <   t               t        | |      } 8| j                  z  t        fdt	        | j
                        D              }nt        fd| j
                  D              }|dz  dz  }t        | ||||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

    c              3   b   K   | ]&  \  }}|k7  rt        j                  |z        n| ( y wr   r   r    )r#   r$   r%   r   upscales      r   r'   z!pyramid_expand.<locals>.<genexpr>   s6      
A ')L&8DIIgk"a?
s   ,/c              3   N   K   | ]  }t        j                  |z          y wr   r8   )r#   r%   r9   s     r   r'   z!pyramid_expand.<locals>.<genexpr>   s     FQ$))GaK0Fs   "%r   r,   Fr-   )r   r   r   r0   r1   r2   r   r   )r   r9   r	   r.   r   r   r3   r   r4   resizedr
   s    `     `   r   pyramid_expandr<   r   s    j 'UN3E#ejj0 
"5;;/
 
	
 F%++FF	}Gc!yDt5G '5$l
;CJr   c          	   #      K   t        |       t        | |      } d}	| j                  }
| }|  |	|k7  r8|	dz  }	t        |||||||      }|
}|}|j                  }
|
|k(  ry| |	|k7  r7yyw)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   r2   r5   )r   	max_layerr&   r	   r.   r   r   r3   r   layercurrent_shapeprev_layer_imagelayer_image
prev_shapes                 r   pyramid_gaussianrD      s     B ) UN3EEKKM
K 9

$%
 #
&#)) J&+ 9
s   A'A,*A,c          	   #   j  K   t               t        | |      } |dz  dz  }| j                  }	t        | |||      }
| |
z
   7| j                  z  t        |	      }|j                         t        |      }n|	}|dk(  r2t        j                  t        j                  t        |                  }t        |      D ]j  }t        fdt        |	      D              }nt        fd|	D              }t        |
||||d      }t        ||||      }
|j                  }	||
z
   l yw)	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,   c              3   t   K   | ]/  \  }}|k7  r!t        j                  |t              z        n| 1 y wr   r   r"   s      r   r'   z$pyramid_laplacian.<locals>.<genexpr>  s<      B 463E		!eI../1Lr(   c              3   `   K   | ]%  }t        j                  |t              z         ' y wr   r   r*   s     r   r'   z$pyramid_laplacian.<locals>.<genexpr>  s$     U!diiE),<(<=Ur+   Fr-   )r   r   r2   r   r   listpopr0   r   r    logmaxranger1   r   )r   r>   r&   r	   r.   r   r   r3   r   r@   smoothed_imageshape_without_channelsr?   r4   resized_images     `     `      r   pyramid_laplacianrQ   $  sN    J ) UN3E}I#KKMUE4|DN
.
  #ejj0!%m!4""<0!&'=!>!. BIIdhhs+A'BINO	y! -# &}5 I
 U}UUI
 !tT<P%++n,,)-s   D/D3)r   Nr   reflectr   F)rF   r   Nr   rR   r   F)r   numpyr   _shared.filtersr   _shared.utilsr   _warpsr   r   r   r5   r<   rD   rQ    r   r   <module>rX      s      & , ,@ 

		
J J^ 

		
I I\ 

		
c cP 

		
t- t-r   