o
    jz                     @   s   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
 d
eZdd Z	dddZ							dddZ							dddddZdS )    )combinations_with_replacementN)filtersfeature)img_as_float32   )is_wasm)ThreadPoolExecutor)AbstractContextManagerc                   @   s$   e Zd Zdd Zdd Zdd ZdS )PoolExecutorc                 O      d S N )self___r   r   `/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/skimage/feature/_basic_features.py__init__      zPoolExecutor.__init__c                 C   r   r   r   )r   exc_typeexc_valexc_tbr   r   r   __exit__   r   zPoolExecutor.__exit__c                 C   s
   t ||S r   )map)r   fn	iterablesr   r   r   r      s   
zPoolExecutor.mapN)__name__
__module____qualname__r   r   r   r   r   r   r   r
      s    r
   c                    s,    fddt t jdD }t|}|S )Nc                    s(   g | ]\}}t jt  | |d qS )Zaxis)npZgradient).0Zax0Zax1gaussian_filteredr   r   
<listcomp>   s    z#_texture_filter.<locals>.<listcomp>r   )r   rangendimr   Zhessian_matrix_eigvals)r"   ZH_elemsZeigvalsr   r!   r   _texture_filter   s
   

r&   Tc                 C   sP   d}t j| |dd}|r||f7 }|r|t |f7 }|r&|g t|R 7 }|S )Nr   F)sigmaZpreserve_range)r   ZgaussianZsobelr&   )imgr'   	intensityedgestextureresultsr"   r   r   r   )_singlescale_basic_features_singlechannel"   s   
r-         ?   c                    s   t t|du rtt |t | d }t jt |t ||ddd}t|d}	t|	 fdd|}
W d   n1 sHw   Y  t	j
|
}|S )	aZ  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.
    num_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baseZendpoint)max_workersc                    s   t |  dS )N)r)   r*   r+   )r-   )sr*   r(   r)   r+   r   r   <lambda>i   s    
z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>)r   Zascontiguousarrayr   intlog2Zlogspacer
   listr   	itertoolschainfrom_iterable)r(   r)   r*   r+   	sigma_min	sigma_max	num_sigmanum_workersZsigmasexZ
out_sigmasfeaturesr   r5   r   '_mutiscale_basic_features_singlechannel0   s(   ,	rC   )channel_axisc                   s   t  gstd|du rdtjf d}n|dkr$t|d fddtjd D }	ttj	
|	}
tj|
d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.
    num_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.N.c                 3   s0    | ]}t d |f  dV  qdS ).)r)   r*   r+   r=   r>   r?   r@   N)rC   )r    dimr*   imager)   r?   r@   r>   r=   r+   r   r   	<genexpr>   s    

z,multiscale_basic_features.<locals>.<genexpr>r   )any
ValueErrorr   ZnewaxisZmoveaxisr$   shaper9   r:   r;   r<   stack)rH   r)   r*   r+   r=   r>   r?   r@   rD   Zall_resultsrB   outr   rG   r   multiscale_basic_featuress   s   9rO   )TTT)TTTr.   r/   NN)r:   r   numpyr   Zskimager   r   Zskimage.util.dtyper   Z_shared._dependency_checksr   concurrent.futuresr   r
   
contextlibr	   r&   r-   rC   rO   r   r   r   r   <module>   s>    


E
