Ë
     \;jÅ5  ã                   ó°   — 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         úcG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\skimage/transform/pyramids.pyÚ_smoothr   
   s`   € ä�}‰}˜UÓ#€Hð Ðà# e§j¡jÑ0ˆØ�˜EŸJ™J¨™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°\Ò/AŒD�I‰I�aœ% 	Ó*Ñ*Ô+À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%   øè ø€ ÐOÁ;¸aœ$Ÿ)™) A¬¨iÓ(8Ñ$8×9Á;ùó   ƒ+.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 �)Ôä˜U NÓ3€EØÐØ# e§j¡jÑ0ˆÜô 
ä" 5§;¡;Ô/ó
ó 
‰	ô
 ÓOÀ5Ç;Â;ÓOÓOˆ	à€}à�I‘ Ñ#ˆä�u˜e T¨4°Ó>€HÜ
Ø�) 5¨t¸$È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Ò&8ŒD�I‰I�g ‘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   øè ø€ ÐF¹+°Qœ$Ÿ)™) G¨a¡K×0¹+ùs   ƒ"%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 �'ÔÜ˜U NÓ3€EØÐØ# e§j¡jÑ0ˆÜô 
ä" 5§;¡;Ô/ó
ó 
‰	ô
 ÓF¸%¿+º+ÓFÓFˆ	à€}à�G‘˜cÑ!ˆäØˆy ¨D°tÈ5ô€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 �)Ôô ˜U NÓ3€Eà€EØ—K‘K€MàÐØ
‚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<   øè ø€ ð á5‘E�B˜ð 46¸Ò3E”—	‘	˜!œe IÓ.Ñ.Ô/È1ÓLÙ5ùr(   c              3   ó`   •K  — | ]%  }t        j                  |t        ‰«      z  «      –— Œ' y ­wr   r   r*   s     €r   r'   z$pyramid_laplacian.<locals>.<genexpr>‹  s%   øè ø€ ÐUÁ}À!œdŸi™i¨¬E°)Ó,<Ñ(<×=Á}ùr+   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   $  sI  ùè ø€ ôJ �)Ôô ˜U NÓ3€Eà€}à�I‘ Ñ#ˆà—K‘K€Mä˜U E¨4°°|ÓD€NØ
�.Ñ
 Ò àÐØ# e§j¡jÑ0ˆÜ!% mÓ!4ÐØ×"Ñ" <Ô0Ü!&Ð'=Ó!>Ñà!.Ðð �B‚Ü—I‘IœdŸh™h¤sÐ+AÓ'BÀIÓNÓOˆ	ä�yÖ!ˆØÐ#Üô ä& }Ô5óó ‰Iô
 ÓUÁ}ÓUÓUˆIäØØØØØØô
ˆô ! °°t¸TÀ<Ó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   