U
    ?h                     @   st   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
 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)ThreadPoolExecutorc                    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_filtered Q/var/www/html/venv/lib/python3.8/site-packages/skimage/feature/_basic_features.py
<listcomp>
   s   z#_texture_filter.<locals>.<listcomp>   )r   rangendimr   Zhessian_matrix_eigvals)r   ZH_elemsZeigvalsr   r
   r   _texture_filter	   s
    

r   Tc                 C   sL   d}t j| |dd}|r"||f7 }|r6|t |f7 }|rH|t|7 }|S )Nr   F)Zpreserve_range)r   ZgaussianZsobelr   )imgsigma	intensityedgestextureresultsr   r   r   r   )_singlescale_basic_features_singlechannel   s    
r         ?   c              	      s   t t|dkr2tt |t | d }t jt |t ||ddd}t|d$}	t|	 fdd|}
W 5 Q R X 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>Y   s       z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>)r   Zascontiguousarrayr   intlog2Zlogspacer   listmap	itertoolschainfrom_iterable)r   r   r   r   	sigma_min	sigma_max	num_sigmanum_workersZsigmasexZ
out_sigmasfeaturesr   r!   r   '_mutiscale_basic_features_singlechannel    s&    ,r0   )channel_axisc                   s   t  gstd|dkr2dtjf d}n|dkrHt|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   s.   | ]&}t d |f  dV  qdS ).)r   r   r   r*   r+   r,   r-   N)r0   )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   shaper%   r'   r(   r)   stack)r5   r   r   r   r*   r+   r,   r-   r1   Zall_resultsr/   outr   r4   r   multiscale_basic_featuresc   s    9r<   )TTT)TTTr   r   NN)TTTr   r   NN)r'   r   numpyr   Zskimager   r   Zskimage.util.dtyper   concurrent.futuresr   r   r   r0   r<   r   r   r   r   <module>   s8   
     
       
E       
