o
    :ήc                     @   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
 d dlmZ dd Z		dd
dZ										dddZe
jdd											dddddZdS )    )combinations_with_replacementN)filtersfeature)img_as_float32)utils)ThreadPoolExecutorc                    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_filtered F/tmp/pip-target-vg8gfxp4/lib/python/skimage/feature/_basic_features.py
<listcomp>   s    z#_texture_filter.<locals>.<listcomp>   )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)preserve_range)r   gaussiansobelr   )imgsigma	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 )	a\  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
        neighbourhoods before extracting features.
    sigma_max : float, optional
        Largest value of the Gaussian kernel used to average local
        neighbourhoods 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)r    r!   r"   )r$   )sr!   r   r    r"   r   r   <lambda>Z   s    
z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>)r
   ascontiguousarrayr   intlog2logspacer   listmap	itertoolschainfrom_iterable)r   r    r!   r"   	sigma_min	sigma_max	num_sigmanum_workerssigmasex
out_sigmasfeaturesr   r-   r   '_mutiscale_basic_features_singlechannel!   s(   ,	r@   r'   )multichannel_positionF)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.
    multichannel : bool, default False
        True if the last dimension corresponds to color channels.
        This argument is deprecated: specify `channel_axis` instead.
    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
        neighbourhoods before extracting features.
    sigma_max : float, optional
        Largest value of the Gaussian kernel used to average local
        neighbourhoods 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"   r8   r9   r:   r;   N)r@   )r   dimr!   imager    r:   r;   r9   r8   r"   r   r   	<genexpr>   s    

z,multiscale_basic_features.<locals>.<genexpr>r   )any
ValueErrorr
   newaxismoveaxisr   shaper3   r5   r6   r7   stack)rF   multichannelr    r!   r"   r8   r9   r:   r;   rB   all_resultsr?   outr   rE   r   multiscale_basic_featuresd   s   >rQ   )TTT)TTTr%   r&   NN)FTTTr%   r&   NN)r5   r   numpyr
   skimager   r   skimage.util.dtyper   skimage._sharedr   concurrent.futuresr   r   r$   r@   deprecate_multichannel_kwargrQ   r   r   r   r   <module>   s<    



C