Ë
    \;jÅ=  ã                   óä   — d Z ddlmZmZmZ 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ej$                  fd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z G d„ dej6                  «      Zy)zn
Augmenters that apply artistic image filters.

List of augmenters:

    * :class:`Cartoon`

Added in 0.4.0.

é    )Úprint_functionÚdivisionÚabsolute_importN)Ú_normalize_cv2_input_arr_é   )Úmeta)Úcoloré   )Údtypes)Ú
parametersé   ç      ð?g       @Tc                 ó^  — t        j                  | dgg d¢d¬«       | j                  dk(  r| j                  d   dk(  sJ d| j                  ›d�«       ‚t	        t        t        j                  |«      «      d	«      }t	        |d
«      }t	        |d
«      }t	        | j                  dd «      dk  }t        | |«      } t        j                  | «      }|rt        d|z  «      }	t        d|z  «      }
nt        d|z  «      }	t        d|z  «      }
|dk  r| }n"t        j                  t        | «      |	|
|¬«       |rt        |||«      }nt        |||«      }|}|dkD  dz  j                  t        j                   «      }|rt#        |ddd¬«      }t#        |ddd¬«      }t%        t'        ||«      ||«      S )aE	  Convert the style of an image to a more cartoonish one.

    This function was primarily designed for images with a size of ``200``
    to ``800`` pixels. Smaller or larger images may cause issues.

    Note that the quality of the results can currently not compete with
    learned style transfer, let alone human-made images. A lack of detected
    edges or also too many detected edges are probably the most significant
    drawbacks.

    This method is loosely based on the one proposed in
    https://stackoverflow.com/a/11614479/3760780

    Added in 0.4.0.

    **Supported dtypes**:

        * ``uint8``: yes; fully tested
        * ``uint16``: no
        * ``uint32``: no
        * ``uint64``: no
        * ``int8``: no
        * ``int16``: no
        * ``int32``: no
        * ``int64``: no
        * ``float16``: no
        * ``float32``: no
        * ``float64``: no
        * ``float128``: no
        * ``bool``: no

    Parameters
    ----------
    image : ndarray
        A ``(H,W,3) uint8`` image array.

    blur_ksize : int, optional
        Kernel size of the median blur filter applied initially to the input
        image. Expected to be an odd value and ``>=0``. If an even value,
        thn automatically increased to an odd one. If ``<=1``, no blur will
        be applied.

    segmentation_size : float, optional
        Size multiplier to decrease/increase the base size of the initial
        mean-shift segmentation of the image. Expected to be ``>=0``.
        Note that the base size is increased by roughly a factor of two for
        images with height and/or width ``>=400``.

    edge_prevalence : float, optional
        Multiplier for the prevalance of edges. Higher values lead to more
        edges. Note that the default value of ``1.0`` is already fairly
        conservative, so there is limit effect from lowerin it further.

    saturation : float, optional
        Multiplier for the saturation. Set to ``1.0`` to not change the
        image's saturation.

    suppress_edges : bool, optional
        Whether to run edge suppression to remove blobs containing too many
        or too few edge pixels.

    from_colorspace : str, optional
        The source colorspace. Use one of ``imgaug.augmenters.color.CSPACE_*``.
        Defaults to ``RGB``.

    Returns
    -------
    ndarray
        Image in cartoonish style.

    Úuint8)ÚboolÚuint16Úuint32Úuint64Úuint128Úuint256Úint8Úint16Úint32Úint64Úint128Úint256Úfloat16Úfloat32Úfloat64Úfloat96Úfloat128Úfloat256N)ÚallowedÚ
disallowedÚ	augmenterr   r
   z+Expected to get a (H,W,C) image, got shape Ú.r   ç        r   i�  é
   é   é   é(   )ÚspÚsrÚdstéd   éÿ   é   F)Úinverseé   T)ÚiadtÚgate_dtypesÚndimÚshapeÚmaxÚintÚnpÚroundÚ_blur_medianÚ
zeros_likeÚcv2ÚpyrMeanShiftFilteringr   Ú_find_edges_cannyÚ_find_edges_laplacianÚastyper   Ú_suppress_edge_blobsÚ	_saturateÚ_blend_edges)ÚimageÚ
blur_ksizeÚsegmentation_sizeÚ
saturationÚedge_prevalenceÚsuppress_edgesÚfrom_colorspaceÚis_small_imageÚ	image_segÚspatial_window_radiusÚcolor_window_radiusÚ	edges_rawÚedgess                úcG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\imgaug/augmenters/artistic.pyÚstylize_cartoonrT      sÉ  € ôV 	×ÑØØ�	ò ð
 õð �:‰:˜Š?˜uŸ{™{¨1™~°Ò2ñ KØ<A¿K»KÐIóKÐ2ô ”SœŸ™ *Ó-Ó.°Ó2€JÜÐ-¨sÓ3ÐÜ�Z Ó%€Jä˜Ÿ™ Q qÐ)Ó*¨SÑ0€Nä˜ 
Ó+€EÜ—‘˜eÓ$€IáÜ # BÐ):Ñ$:Ó ;ÐÜ! "Ð'8Ñ"8Ó9Ñä # BÐ):Ñ$:Ó ;ÐÜ! "Ð'8Ñ"8Ó9Ðà˜AÒØ‰	ä×!Ñ!Ô";¸EÓ"BØ%:Ø%8Ø&/õ	1ñ
 Ü% iØ&5Ø&5ó7‰	ô *¨)Ø*9Ø*9ó;ˆ	ð €Eà�c‰k˜SÑ ×(Ñ(¬¯©Ó2€Eáô % U¨A¨q¸%Ô@ˆô % U¨A¨q¸$Ô?ˆä”\ )¨UÓ3ØØ$ó&ð &ó    c                 óø   — t        j                  t        j                  | «      t         j                  |¬«      }|d   }t        t        dd|z  z  «      d«      }t        j                  t        |«      ||«      }|S )N©Úto_colorspacerL   ©.r   éÈ   r   éþ   )
ÚcolorlibÚchange_colorspace_r:   ÚcopyÚCSPACE_GRAYÚminr9   r>   ÚCannyr   )rF   Úedge_multiplierrL   Ú
image_grayÚthreshrR   s         rS   r@   r@   £   sm   € Ü×,Ñ,¬R¯W©W°U«^Ü;C×;OÑ;OØ=LôN€Jð ˜FÑ#€JÜ”�S˜A˜oÑ-Ñ.Ó/°Ó5€FÜ�I‰IÔ/°
Ó;¸VÀVÓL€EØ€LrU   c           
      ól  — t        j                  t        j                  | «      t         j                  |¬«      }|d   }t        j                  t        |dz  «      t
        j                  «      }t        j                  |«      }|dz  }t        j                  |t        t        dd|z  z  «      d«      «      }t        j                  |d|«      |z  }t        j                  t        j                  |d	z  «      d
d«      j                  t        j                   «      }t#        |d«      }t%        |d«      }|S )NrW   rY   ç     ào@r
   éZ   r   éc   r'   r0   r   r   é2   )r\   r]   r:   r^   r_   r>   Ú	Laplacianr   ÚCV_64FÚabsÚ
percentiler`   r9   Úclipr;   rB   r   r<   Ú
_threshold)rF   rb   rL   rc   Úedges_fÚvmaxÚedges_uint8s          rS   rA   rA   ®   sö   € Ü×,Ñ,¬R¯W©W°U«^Ü;C×;OÑ;OØ=LôN€Jð ˜FÑ#€JÜ�m‰mÔ5°jÀ5Ñ6HÓIÜŸJ™Jó(€Gä�f‰f�W‹o€GØ˜‰l€GÜ�=‰=˜¤#¤c¨"°°/Ñ0AÑ*BÓ&CÀRÓ"HÓI€DÜ�g‰g�g˜s DÓ)¨DÑ0€Gä—'‘'œ"Ÿ(™( 7¨S¡=Ó1°1°eÓ<×CÑCÄBÇHÁHÓM€KÜ˜{¨AÓ.€KÜ˜[¨"Ó-€KØÐrU   c                 óh   — |dz  dk(  r|dz  }|dk  r| S t        j                  t        | «      |«      S )Nr
   r   r   )r>   Ú
medianBlurr   )rF   Úksizes     rS   r<   r<   Á   s9   € Øˆq�y�A‚~Ø�‰
ˆØ�‚zØˆÜ�>‰>Ô3°EÓ:¸EÓBÐBrU   c                 óD   — | |k  }t        j                  | «      }d||<   |S )Nr   )r:   r^   )rF   rd   ÚmaskÚresults       rS   ro   ro   Ê   s&   € Ø�F‰N€DÜ�W‰W�U‹^€FØ€Fˆ4�LØ€MrU   c                 óè   — t        j                  ||ft         j                  ¬«      }t        j                  t        | dz  «      d|«      }|r||k  }n||k\  }t        j                  | «      } d| |<   | S )N)Údtyperf   éÿÿÿÿr   )r:   Úonesr   r>   Úfilter2Dr   r^   )rR   Úsizerd   r2   ÚkernelÚcountsrw   s          rS   rC   rC   Ò   sg   € Ü�W‰W�d˜D�\¬¯©Ô4€FÜ�\‰\Ô3°E¸E±MÓBÀBÈÓO€FáØ˜‘‰à˜&Ñ ˆä�G‰G�E‹N€EØ€Eˆ$�KØ€LrU   c                 óÔ  — t        j                  | «      } t        j                  |dd¬«      r| S t        j                  | t        j
                  |¬«      }|d d …d d …df   }t        j                  |j                  t         j                  «      |z  dd«      j                  t         j                  «      }||d d …d d …df<   t        j                  ||t        j
                  ¬«      }|S )Nr   g{®Gáz„?)ÚatolrW   r   r   r0   )
r:   r^   Úiscloser\   r]   Ú
CSPACE_HSVrn   rB   r   r   )rF   ÚfactorrL   ÚhsvÚsatÚ	image_sats         rS   rD   rD   á   s½   € Ü�G‰G�E‹N€EÜ	‡z�z�&˜# DÕ)Øˆä
×
%Ñ
% eÜ4<×4GÑ4GØ6EôG€Cð Ša’�Aˆg‰,€CÜ
�'‰'�#—*‘*œRŸX™XÓ&¨Ñ/°°CÓ
8×
?Ñ
?ÄÇÁÓ
I€CØ€CŠŠ1ˆaˆ�LÜ×+Ñ+¨CØ:IÜ<D×<OÑ<OôQ€Ið ÐrU   c                 óø   — d|dz  z
  }t        j                  |dt         j                  f   d«      }t        j                  t        j                  | |z  «      dd«      j                  t         j                  «      S )Nr   rf   .)r   r   r   r'   )r:   ÚtileÚnewaxisrn   r;   rB   r   )rF   Úimage_edgess     rS   rE   rE   ó   se   € Ø˜ uÑ,Ñ-€KÜ—'‘'˜+ c¬2¯:©: oÑ6¸	ÓB€KÜ�7‰7Ü
�‰�˜Ñ$Ó%ØˆUó÷ �fŒR�X‰XÓðrU   c            	       ó\   ‡ — e Zd ZdZddddej
                  ddddf	ˆ fd„	Zd	„ Zd
„ Zd„ Z	ˆ xZ
S )ÚCartoonaþ  Convert the style of images to a more cartoonish one.

    This augmenter was primarily designed for images with a size of ``200``
    to ``800`` pixels. Smaller or larger images may cause issues.

    Note that the quality of the results can currently not compete with
    learned style transfer, let alone human-made images. A lack of detected
    edges or also too many detected edges are probably the most significant
    drawbacks.

    Added in 0.4.0.

    **Supported dtypes**:

    See :func:`~imgaug.augmenters.artistic.stylize_cartoon`.

    Parameters
    ----------
    blur_ksize : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Median filter kernel size.
        See :func:`~imgaug.augmenters.artistic.stylize_cartoon` for details.

            * If ``number``: That value will be used for all images.
            * If ``tuple (a, b) of number``: A random value will be uniformly
              sampled per image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked per image from the
              ``list``.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values, where ``N`` is the number of
              images.

    segmentation_size : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Mean-Shift segmentation size multiplier.
        See :func:`~imgaug.augmenters.artistic.stylize_cartoon` for details.

            * If ``number``: That value will be used for all images.
            * If ``tuple (a, b) of number``: A random value will be uniformly
              sampled per image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked per image from the
              ``list``.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values, where ``N`` is the number of
              images.

    saturation : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Saturation multiplier.
        See :func:`~imgaug.augmenters.artistic.stylize_cartoon` for details.

            * If ``number``: That value will be used for all images.
            * If ``tuple (a, b) of number``: A random value will be uniformly
              sampled per image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked per image from the
              ``list``.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values, where ``N`` is the number of
              images.

    edge_prevalence : number or tuple of number or list of number or imgaug.parameters.StochasticParameter, optional
        Multiplier for the prevalence of edges.
        See :func:`~imgaug.augmenters.artistic.stylize_cartoon` for details.

            * If ``number``: That value will be used for all images.
            * If ``tuple (a, b) of number``: A random value will be uniformly
              sampled per image from the interval ``[a, b)``.
            * If ``list``: A random value will be picked per image from the
              ``list``.
            * If ``StochasticParameter``: The parameter will be queried once
              per batch for ``(N,)`` values, where ``N`` is the number of
              images.

    from_colorspace : str, optional
        The source colorspace. Use one of ``imgaug.augmenters.color.CSPACE_*``.
        Defaults to ``RGB``.

    seed : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    name : None or str, optional
        See :func:`~imgaug.augmenters.meta.Augmenter.__init__`.

    random_state : None or int or imgaug.random.RNG or numpy.random.Generator or numpy.random.BitGenerator or numpy.random.SeedSequence or numpy.random.RandomState, optional
        Old name for parameter `seed`.
        Its usage will not yet cause a deprecation warning,
        but it is still recommended to use `seed` now.
        Outdated since 0.4.0.

    deterministic : bool, optional
        Deprecated since 0.4.0.
        See method ``to_deterministic()`` for an alternative and for
        details about what the "deterministic mode" actually does.

    Examples
    --------
    >>> import imgaug.augmenters as iaa
    >>> aug = iaa.Cartoon()

    Create an example image, then apply a cartoon filter to it.

    >>> aug = iaa.Cartoon(blur_ksize=3, segmentation_size=1.0,
    >>>                   saturation=2.0, edge_prevalence=1.0)

    Create a non-stochastic cartoon augmenter that produces decent-looking
    images.

    )r   r3   )gš™™™™™é?g333333ó?)g      ø?g      @)gÍÌÌÌÌÌì?gš™™™™™ñ?NÚ
deprecatedc
                 ó:  •— t         t        | �  ||||	¬«       t        j                  |dddd¬«      | _        t        j                  |dddd¬«      | _        t        j                  |dddd¬«      | _        t        j                  |d	ddd¬«      | _        || _	        y )
N)ÚseedÚnameÚrandom_stateÚdeterministicrG   )r   NT)Úvalue_rangeÚtuple_to_uniformÚlist_to_choicerH   )r'   NrI   rJ   )
ÚsuperrŽ   Ú__init__ÚiapÚhandle_continuous_paramrG   rH   rI   rJ   rL   )ÚselfrG   rH   rI   rJ   rL   r‘   r’   r“   r”   Ú	__class__s             €rS   r™   zCartoon.__init__h  s²   ø€ ô
 	Œg�tÑ%Ø˜DØ%°]ð 	&ô 	Dô ×5Ñ5Ø˜°)Ø!°$ô8ˆŒô "%×!<Ñ!<ØÐ2ÀØ!°$ô"8ˆÔô ×5Ñ5Ø˜°+Ø!°$ô8ˆŒô  #×:Ñ:ØÐ.¸KØ!°$ô 8ˆÔð  /ˆÕrU   c           	      óè   — |j                   �e| j                  ||«      }t        |j                   «      D ];  \  }}t        ||d   |   |d   |   |d   |   |d   |   | j                  ¬«      |d<   Œ= |S )Nr   r   r
   r   ©rG   rH   rI   rJ   rL   .)ÚimagesÚ_draw_samplesÚ	enumeraterT   rL   )rœ   Úbatchr“   ÚparentsÚhooksÚsamplesÚirF   s           rS   Ú_augment_batch_zCartoon._augment_batch_€  s‚   € Ø�<‰<Ð#Ø×(Ñ(¨°Ó=ˆGÜ% e§l¡lÖ3‘��5Ü,ØØ& q™z¨!™}Ø&-¨a¡j°¡mØ& q™z¨!™}Ø$+¨A¡J¨q¡MØ$(×$8Ñ$8ô��c’
ð 4ð ˆrU   c                 ó  — |j                   }| j                  j                  |f|¬«      | j                  j                  |f|¬«      | j                  j                  |f|¬«      | j
                  j                  |f|¬«      fS )N)r“   )Únb_rowsrG   Údraw_samplesrH   rI   rJ   )rœ   r£   r“   rª   s       rS   r¡   zCartoon._draw_samples�  s‰   € Ø—-‘-ˆà�O‰O×(Ñ(¨'¨À,Ð(ÓOØ×"Ñ"×/Ñ/°°
Ø=Ið 0ó Kà�O‰O×(Ñ(¨'¨À,Ð(ÓOØ× Ñ ×-Ñ-¨w¨jØ;Gð .ó Ið
ð 	
rU   c                 ót   — | j                   | j                  | j                  | j                  | j                  gS )z=See :func:`~imgaug.augmenters.meta.Augmenter.get_parameters`.rŸ   )rœ   s    rS   Úget_parameterszCartoon.get_parameters›  s2   € à—‘ ×!7Ñ!7¸¿¹Ø×$Ñ$ d×&:Ñ&:ð<ð 	<rU   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r\   Ú
CSPACE_RGBr™   r¨   r¡   r­   Ú__classcell__)r�   s   @rS   rŽ   rŽ   ü   s=   ø„ ñhðV #)¸JØ&¸
Ø!)×!4Ñ!4Ø Ø*¸,õ	/ò0ò	
ö<rU   rŽ   )r±   Ú
__future__r   r   r   Únumpyr:   r>   Úimgaug.imgaugr   Ú r   r	   r\   r   r4   r   rš   r²   rT   r@   rA   r<   ro   rC   rD   rE   Ú	AugmenterrŽ   © rU   rS   Ú<module>rº      s}   ðñ	÷ AÑ @ã Û 
å 3Ý Ý Ý Ý  ð '(¸3Ø"°CØ#'Ø$,×$7Ñ$7óG&òVòò&Còòòò$ôb<ˆd�n‰nõ b<rU   