o
    ^iz                     @   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   Z/var/www/html/RAG/RAG_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 )axis)npgradient).0ax0ax1gaussian_filteredr   r   
<listcomp>   s    z#_texture_filter.<locals>.<listcomp>r   )r   rangendimr   hessian_matrix_eigvals)r&   H_elems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)sigmapreserve_range)r   gaussiansobelr-   )imgr.   	intensityedgestextureresultsr&   r   r   r   )_singlescale_basic_features_singlechannel"   s   
r7         ?   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baseendpoint)max_workersc                    s   t |  dS )N)r3   r4   r5   )r7   )sr4   r2   r3   r5   r   r   <lambda>i   s    
z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>)r    ascontiguousarrayr   intlog2logspacer
   listr   	itertoolschainfrom_iterable)r2   r3   r4   r5   	sigma_min	sigma_max	num_sigmanum_workerssigmasex
out_sigmasfeaturesr   r@   r   '_mutiscale_basic_features_singlechannel0   s(   ,	rR   )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 ).)r3   r4   r5   rJ   rK   rL   rM   N)rR   )r"   dimr4   imager3   rL   rM   rK   rJ   r5   r   r   	<genexpr>   s    

z,multiscale_basic_features.<locals>.<genexpr>r   )any
ValueErrorr    newaxismoveaxisr(   shaperF   rG   rH   rI   stack)rW   r3   r4   r5   rJ   rK   rL   rM   rS   all_resultsrQ   outr   rV   r   multiscale_basic_featuress   s   9ra   )TTT)TTTr8   r9   NN)rG   r   numpyr    skimager   r   skimage.util.dtyper   _shared._dependency_checksr   concurrent.futuresr   r
   
contextlibr	   r-   r7   rR   ra   r   r   r   r   <module>   s>    

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