
    1-Phz                         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
e          Zd Z	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddddZdS )    )combinations_with_replacementN)filtersfeature)img_as_float32   )is_wasm)ThreadPoolExecutor)AbstractContextManagerc                        e Zd Zd Zd Zd ZdS )PoolExecutorc                     d S N )self___s      _/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/_basic_features.py__init__zPoolExecutor.__init__       D    c                     d S r   r   )r   exc_typeexc_valexc_tbs       r   __exit__zPoolExecutor.__exit__   r   r   c                 "    t          ||          S r   )map)r   fn	iterabless      r   r   zPoolExecutor.map   s    r9%%%r   N)__name__
__module____qualname__r   r   r   r   r   r   r   r      sA        	 	 		 	 		& 	& 	& 	& 	&r   r   c                       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      r   
<listcomp>z#_texture_filter.<locals>.<listcomp>   sL       C 	BK 12237cBBB  r   r   )r   rangendimr   hessian_matrix_eigvals)r,   H_elemseigvalss   `  r   _texture_filterr3      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 )Nr   F)sigmapreserve_range)r   gaussiansobelr3   )imgr5   	intensityedgestextureresultsr,   s          r   )_singlescale_basic_features_singlechannelr>   "   s     G(E%PPP (%'' 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;   r9   r:   r<   s    r   <lambda>z9_mutiscale_basic_features_singlechannel.<locals>.<lambda>i   s"    Ciug   r   )r'   ascontiguousarrayr   intlog2logspacer   listr   	itertoolschainfrom_iterable)r9   r:   r;   r<   	sigma_min	sigma_max	num_sigmanum_workerssigmasex
out_sigmasfeaturess   ````        r   '_mutiscale_basic_features_singlechannelrZ   0   sT   X 
~c22
3
3C	**RWY-?-??!CDD	[
	
	  F 
+	.	.	. 
"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<   rR   rS   rT   rU   N)rZ   )
r)   dimr;   imager:   rT   rU   rS   rR   r<   s
     r   	<genexpr>z,multiscale_basic_features.<locals>.<genexpr>   sh          	0#s(O#		
 		
 		
     r   r%   )any
ValueErrorr'   newaxismoveaxisr.   shaperN   rO   rP   rQ   stack)r`   r:   r;   r<   rR   rS   rT   rU   r[   all_resultsrY   outs   ````````    r   multiscale_basic_featuresrj   s   s   r 	5'*++ 
8
 
 	
 c2:o&			E<44           R))  K IO11+>>??H
(8"
%
%
%CJr   )TTT)TTTr?   r@   NN)rO   r   numpyr'   skimager   r   skimage.util.dtyper   _shared._dependency_checksr   concurrent.futuresr	   r   
contextlibr
   r3   r>   rZ   rj   r   r   r   <module>rq      si   3 3 3 3 3 3         $ $ $ $ $ $ $ $ - - - - - - 0 0 0 0 0 0 &EEEEEEE111111& & & & &- & & &   59     
@ @ @ @J 
S S S S S S S Sr   