
    1-Ph-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dS )    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         Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/transform/pyramids.py_smoothr   
   sn    }U##H #ej0EJN+!    O    c                 0    | dk    rt          d          d S )Nr   z#scale factor must be greater than 1)
ValueError)factors    r   _check_factorr       s!    {{>??? {r   reflectFr   c                b   t                     t          | |          } 9| 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

    Nc              3   v   K   | ]3\  }}|k    r$t          j        |t                    z            n|V  4d S Nmathceilfloat.0axdr   	downscales      r   	<genexpr>z!pyramid_reduce.<locals>.<genexpr>_   sa       
 
A 02\/A/ADIa%	***+++q
 
 
 
 
 
r   c              3   `   K   | ](}t          j        |t                    z            V  )d S r   r   r$   r&   r'   s     r   r(   z!pyramid_reduce.<locals>.<genexpr>d   s:      OOa$)Ai(8(8$899OOOOOOr   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_reducer4   %   s    j )UN33E#ej0 
 
 
 
 
"5;//
 
 
 
 
		
 OOOO5;OOOOO	}I#ueT4>>H
)5t$e  C Jr   c                b   t                     t          | |          } 9| 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

    Nc              3   \   K   | ]&\  }}|k    rt          j        |z            n|V  'd S r   r    r!   )r$   r%   r&   r   upscales      r   r(   z!pyramid_expand.<locals>.<genexpr>   sX       
 
A ')L&8&8DIgk"""a
 
 
 
 
 
r   c              3   F   K   | ]}t          j        |z            V  d S r   r7   )r$   r&   r8   s     r   r(   z!pyramid_expand.<locals>.<genexpr>   s1      FFQ$)GaK00FFFFFFr   r   r+   Fr,   )r   r   r   r/   r0   r1   r   r   )r   r8   r	   r-   r   r   r2   r   r3   resizedr
   s    `     `   r   pyramid_expandr;   r   s    j 'UN33E#ej0 
 
 
 
 
"5;//
 
 
 
 
		
 FFFF%+FFFFF	}Gc!yDt5  G '5$l
;
;CJr   c          	   #      K   t          |           t          | |          } d}	| j        }
| }| V  |	|k    r:|	dz  }	t          |||||||          }|
}|}|j        }
|
|k    rdS |V  |	|k    8dS 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   r1   r4   )r   	max_layerr'   r	   r-   r   r   r2   r   layercurrent_shapeprev_layer_imagelayer_image
prev_shapes                 r   pyramid_gaussianrD      s      B ) UN33EEKM
KKK 9


$%
 
 
 #
&#) J&&E+ 9





r   c          	   #     K   t                     t          | |          } |dz  dz  }| j        }	t          | |||          }
| |
z
  V  >| j        z  t          |	          }|                               t          |          }n|	}|dk    r4t          j	        t          j
        t          |                              }t          |          D ]}*t          fdt          |	          D                       }nt          fd|	D                       }t          |
||||d          }t          ||||          }
|j        }	||
z
  V  d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+   r<   c              3   v   K   | ]3\  }}|k    r$t          j        |t                    z            n|V  4d S r   r   r#   s      r   r(   z$pyramid_laplacian.<locals>.<genexpr>  sa        B 463E3E	!eI...///1     r   c              3   `   K   | ](}t          j        |t                    z            V  )d S r   r   r*   s     r   r(   z$pyramid_laplacian.<locals>.<genexpr>  s:      UU!diE),<,<(<==UUUUUUr   Fr,   )r   r   r1   r   r   listpopr/   r    r!   logmaxranger0   r   )r   r>   r'   r	   r-   r   r   r2   r   r@   smoothed_imageshape_without_channelsr?   r3   resized_images     `     `      r   pyramid_laplacianrP   $  s     J ) UN33E}I#KMUE4|DDN
.
    #ej0!%m!4!4""<000!&'=!>!>!. BIdhs+A'B'BINNOO	y!! - -#     &}55    II
 UUUU}UUUUUI
 
 
 !tT<PP%+n,,,,,)- -r   )r   Nr   r   r   F)r<   r   Nr   r   r   F)r    numpyr   _shared.filtersr   _shared.utilsr   _warpsr   r   r   r4   r;   rD   rP    r   r   <module>rV      sz        & & & & & & , , , , , ,        ,@ @ @ 

		
J J J J J J^ 

		
I I I I I I\ 

		
c c c c c cP 

		
t- t- t- t- t- t- t- t-r   