
    a6d                         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 Z	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddddZdS )    )combinations_with_replacementN)filtersfeature)img_as_float32)ThreadPoolExecutorc                       fdt          t           j                  d          D             }t          j        |          }|S )Nc                 r    g | ]3\  }}t          j        t          j                  |         |           4S )axis)npgradient).0ax0ax1gaussian_filtereds      ?lib/python3.11/site-packages/skimage/feature/_basic_features.py
<listcomp>z#_texture_filter.<locals>.<listcomp>
   sL       C 	BK 12237cBBB         )r   rangendimr   hessian_matrix_eigvals)r   H_elemseigvalss   `  r   _texture_filterr   	   sY       5e<M<R6S6SUVWW  G ,W55GNr   Tc                     d}t          j        | |d          }|r||fz  }|r|t          j        |          fz  }|r|g t          |          R z  }|S )N F)preserve_range)r   gaussiansobelr   )imgsigma	intensityedgestextureresultsr   s          r   )_singlescale_basic_features_singlechannelr'      s     G(eEJJJ (%'' 7GM"34466 :9_%677999Nr         ?   c           	           t          j        t                                |9t          t          j        |          t          j        |          z
  dz             }t          j        t          j        |          t          j        |          |dd          }t          |          5 }	t          |	                     fd|                    }
ddd           n# 1 swxY w 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                 ,    t          |           S )N)r#   r$   r%   )r'   )sr$   r!   r#   r%   s    r   <lambda>z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>Y   s"    Ciug   r   )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featuress   ````        r   '_mutiscale_basic_features_singlechannelrD       sT   X 
~c22
3
3C	**RWY-?-??!CDD	[
	
	  F 
	4	4	4 
FF       	 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ,,Z88HOs   .*C$$C(+C()channel_axisc                    t          g          st          d          | dt          j        f          d}n|dk    rt          j         |d            fdt           j        d                   D             }	t          t          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.
    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   V   K   | ]#}t          d |f         	          V  $dS ).)r#   r$   r%   r<   r=   r>   r?   N)rD   )
r   dimr$   imager#   r>   r?   r=   r<   r%   s
     r   	<genexpr>z,multiscale_basic_features.<locals>.<genexpr>   sh          	0#s(O#		
 		
 		
     r   r
   )any
ValueErrorr   newaxismoveaxisr   shaper7   r9   r:   r;   stack)rJ   r#   r$   r%   r<   r=   r>   r?   rE   all_resultsrC   outs   ````````    r   multiscale_basic_featuresrT   c   s   r 	5'*++ 
8
 
 	
 c2:o&			E<44           R))  K IO11+>>??H
(8"
%
%
%CJr   )TTT)TTTr(   r)   NN)r9   r   numpyr   skimager   r   skimage.util.dtyper   concurrent.futuresr   r   r'   rD   rT   r   r   r   <module>rY      s   3 3 3 3 3 3         $ $ $ $ $ $ $ $ - - - - - - 1 1 1 1 1 1   59     
@ @ @ @J 
S S S S S S S Sr   