Ë
    îì�i^  ã                   ó¾   — d dl mZ d dl Z d dlZd dlmZmZ d dlmZ ddl	m
Z
 e
sd dlmZ nd dlmZ  G d	„ d
e«      Zd„ Z	 dd„Z	 	 	 	 	 	 	 dd„Z	 	 	 	 	 	 	 dddœd„Zy)é    )Úcombinations_with_replacementN)ÚfiltersÚfeature)Úimg_as_float32é   )Úis_wasm)ÚThreadPoolExecutor)ÚAbstractContextManagerc                   ó   — e Zd Zd„ Zd„ Zd„ Zy)ÚPoolExecutorc                  ó   — y ©N© )ÚselfÚ_Ú__s      ú„/var/www/ITT-ServiceAPI-Services/ITT-Document-Scan/mrzscanner/mrzenv/lib/python3.12/site-packages/skimage/feature/_basic_features.pyÚ__init__zPoolExecutor.__init__   ó   € Øó    c                  ó   — y r   r   )r   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__zPoolExecutor.__exit__   r   r   c                 ó   — t        ||«      S r   )Úmap)r   ÚfnÚ	iterabless      r   r   zPoolExecutor.map   s   € Ü�r˜9Ó%Ð%r   N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r      s   „ ò	ò	ó	&r   r   c           	      óô   — t        t        | j                  «      d«      D ��cg c]2  \  }}t        j                  t        j                  | «      |   |¬«      ‘Œ4 }}}t        j                  |«      }|S c c}}w )Nr   ©Úaxis)r   ÚrangeÚndimÚnpÚgradientr   Úhessian_matrix_eigvals)Úgaussian_filteredÚax0Úax1ÚH_elemsÚeigvalss        r   Ú_texture_filterr0      so   € ô 6´eÐ<M×<RÑ<RÓ6SÐUVÓW÷áˆC�ô 	�‰”B—K‘KÐ 1Ó2°3Ñ7¸cÖBð€Gñ ô ×,Ñ,¨WÓ5€GØ€Nùós   £7A4c                 ó¦   — d}t        j                  | |d¬«      }|r||fz  }|r|t        j                  |«      fz  }|r|g t        |«      ¢­z  }|S )Nr   F)ÚsigmaÚpreserve_range)r   ÚgaussianÚsobelr0   )Úimgr2   Ú	intensityÚedgesÚtextureÚresultsr+   s          r   Ú)_singlescale_basic_features_singlechannelr;   "   sg   € ð €GÜ×(Ñ(¨°EÈ%ÔPÐÙØÐ%Ð'Ñ'ˆÙØ”G—M‘MÐ"3Ó4Ð6Ñ6ˆÙØÐ9”_Ð%6Ó7Ñ9Ñ9ˆØ€Nr   c           	      óþ  ‡ ‡‡‡— t        j                  t        ‰ «      «      Š |€7t        t        j                  |«      t        j                  |«      z
  dz   «      }t        j
                  t        j                  |«      t        j                  |«      |dd¬«      }t        |¬«      5 }	t        |	j                  ˆˆ ˆˆfd„|«      «      }
ddd«       t        j                  j                  
«      }|S # 1 sw Y   Œ*xY w)aV  Features for a single channel nd image.

    Parameters
    ----------
    img : ndarray
        Input image, which can be grayscale or multichannel.
    intensity : bool, default True
        If True, pixel intensities averaged over the different scales
        are added to the feature set.
    edges : bool, default True
        If True, intensities of local gradients averaged over the different
        scales are added to the feature set.
    texture : bool, default True
        If True, eigenvalues of the Hessian matrix after Gaussian blurring
        at different scales are added to the feature set.
    sigma_min : float, optional
        Smallest value of the Gaussian kernel used to average local
        neighborhoods before extracting features.
    sigma_max : float, optional
        Largest value of the Gaussian kernel used to average local
        neighborhoods before extracting features.
    num_sigma : int, optional
        Number of values of the Gaussian kernel between sigma_min and sigma_max.
        If None, sigma_min multiplied by powers of 2 are used.
    workers : int or None, optional
        The number of parallel threads to use. If set to ``None``, the full
        set of available cores are used.

    Returns
    -------
    features : list
        List of features, each element of the list is an array of shape as img.
    Né   r   T)ÚnumÚbaseÚendpoint)Úmax_workersc                 ó$   •— t        ‰| ‰‰‰¬«      S )N)r7   r8   r9   )r;   )Úsr8   r6   r7   r9   s    €€€€r   ú<lambda>z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>i   s   ø€ ÔCØ˜ i°uÀgô€ r   )r(   Úascontiguousarrayr   ÚintÚlog2Úlogspacer   Úlistr   Ú	itertoolsÚchainÚfrom_iterable)r6   r7   r8   r9   Ú	sigma_minÚ	sigma_maxÚ	num_sigmaÚworkersÚsigmasÚexÚ
out_sigmasÚfeaturess   ````        r   Ú'_mutiscale_basic_features_singlechannelrU   0   sÒ   û€ ôX ×
Ñ
œ~¨cÓ2Ó
3€CØÐÜœŸ™ 	Ó*¬R¯W©W°YÓ-?Ñ?À!ÑCÓDˆ	Ü�[‰[Ü
�‰�	ÓÜ
�‰�	ÓØØØô€Fô 
 'Ô	*ð 
¨bÜØ�F‰Föð ó	ó
ˆ
÷
ô �‰×,Ñ,¨ZÓ8€HØ€O÷
ð 
ús   Â("C3Ã3C<)Úchannel_axisc                ó‚  ‡ ‡‡‡‡‡‡‡— t        ‰‰‰g«      st        d«      ‚|€‰ dt        j                  f   Š d}n|dk7  rt        j                  ‰ |d«      Š ˆˆ ˆˆˆˆˆˆfd„t        ‰ j                  d   «      D «       }	t        t        j                  j                  |	«      «      }
t        j                  |
d¬«      }|S )a¨  Local features for a single- or multi-channel nd image.

    Intensity, gradient intensity and local structure are computed at
    different scales thanks to Gaussian blurring.

    Parameters
    ----------
    image : ndarray
        Input image, which can be grayscale or multichannel.
    intensity : bool, default True
        If True, pixel intensities averaged over the different scales
        are added to the feature set.
    edges : bool, default True
        If True, intensities of local gradients averaged over the different
        scales are added to the feature set.
    texture : bool, default True
        If True, eigenvalues of the Hessian matrix after Gaussian blurring
        at different scales are added to the feature set.
    sigma_min : float, optional
        Smallest value of the Gaussian kernel used to average local
        neighborhoods before extracting features.
    sigma_max : float, optional
        Largest value of the Gaussian kernel used to average local
        neighborhoods before extracting features.
    num_sigma : int, optional
        Number of values of the Gaussian kernel between sigma_min and sigma_max.
        If None, sigma_min multiplied by powers of 2 are used.
    workers : int or None, optional
        The number of parallel threads to use. If set to ``None``, the full
        set of available cores are used.
    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
    -------
    features : np.ndarray
        Array of shape ``image.shape + (n_features,)``. When `channel_axis` is
        not None, all channels are concatenated along the features dimension.
        (i.e. ``n_features == n_features_singlechannel * n_channels``)
    z[At least one of `intensity`, `edges` or `textures`must be True for features to be computed..éÿÿÿÿc              3   óN   •K  — | ]  }t        ‰d |f   ‰‰‰‰‰‰‰	¬«      –— Œ y­w).)r7   r8   r9   rM   rN   rO   rP   N)rU   )
Ú.0Údimr8   Úimager7   rO   rN   rM   r9   rP   s
     €€€€€€€€r   ú	<genexpr>z,multiscale_basic_features.<locals>.<genexpr>·   sE   øè ø€ ò ð ô 	0Ø�#�s�(‰OØØØØØØØ÷		
ð 		
ñùs   ƒ"%r$   )ÚanyÚ
ValueErrorr(   ÚnewaxisÚmoveaxisr&   ÚshaperI   rJ   rK   rL   Ústack)r\   r7   r8   r9   rM   rN   rO   rP   rV   Úall_resultsrT   Úouts   ````````    r   Úmultiscale_basic_featuresrf   s   s³   ÿ€ ôr �	˜5 'Ð*Ô+Üð8ó
ð 	
ð ÐØ�cœ2Ÿ:™:�oÑ&ˆØ‰Ø	˜Ò	Ü—‘˜E <°Ó4ˆ÷ò ô ˜Ÿ™ R™Ó)ô€Kô ”I—O‘O×1Ñ1°+Ó>Ó?€HÜ
�(‰(�8 "Ô
%€CØ€Jr   )TTT)TTTg      à?é   NN)rJ   r   Únumpyr(   Úskimager   r   Úskimage.util.dtyper   Ú_shared._dependency_checksr   Úconcurrent.futuresr	   r   Ú
contextlibr
   r0   r;   rU   rf   r   r   r   ú<module>rn      s‚   ðÝ 3Û Û ß $Ý -Ý 0áÞEå1ô&Ð-ô &òð 59óð  Ø
ØØØØØó@ðJ Ø
ØØØØØðSð õSr   