
    |hz                         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y)    )combinations_with_replacementN)filtersfeature)img_as_float32   )is_wasm)ThreadPoolExecutor)AbstractContextManagerc                       e Zd Zd Zd Zd Zy)PoolExecutorc                      y N )self___s      ^/var/www/html/test/engine/venv/lib/python3.12/site-packages/skimage/feature/_basic_features.py__init__zPoolExecutor.__init__           c                      y 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      s    			&r   r   c           	          t        t        | j                        d      D cg c]2  \  }}t        j                  t        j                  |       |   |      4 }}}t        j                  |      }|S c c}}w )Nr   axis)r   rangendimnpgradientr   hessian_matrix_eigvals)gaussian_filteredax0ax1H_elemseigvalss        r   _texture_filterr0      so     6e<M<R<R6SUVWC 	BKK 1237cBG  ,,W5GNs   7A4c                     d}t        j                  | |d      }|r||fz  }|r|t        j                  |      fz  }|r|g t        |      z  }|S )Nr   F)sigmapreserve_range)r   gaussiansobelr0   )imgr2   	intensityedgestextureresultsr+   s          r   )_singlescale_basic_features_singlechannelr;   "   sg     G((E%P%''GMM"34669_%6799Nr   c           	          t        j                  t                      |7t        t        j                  |      t        j                  |      z
  dz         }t        j
                  t        j                  |      t        j                  |      |dd      }t        |      5 }	t        |	j                   fd|            }
ddd       t        j                  j                  
      }|S # 1 sw Y   *xY w)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)r7   r8   r9   )r;   )sr8   r6   r7   r9   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)r6   r7   r8   r9   	sigma_min	sigma_max	num_sigmanum_workerssigmasex
out_sigmasfeaturess   ````        r   '_mutiscale_basic_features_singlechannelrU   0   s    X 

~c2
3C	*RWWY-??!CD	[[
	
	F 
+	. 
"FF 	


 ,,Z8HO
 
s   ("C33C<)channel_axisc                    t        g      st        d      | dt        j                  f    d}n|dk7  rt        j                   |d        fdt         j                  d         D        }	t        t        j                  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..c              3   N   K   | ]  }t        d |f   	        yw).)r7   r8   r9   rM   rN   rO   rP   N)rU   )
.0dimr8   imager7   rO   rP   rN   rM   r9   s
     r   	<genexpr>z,multiscale_basic_features.<locals>.<genexpr>   sE        	0#s(O#		
 		
s   "%r$   )any
ValueErrorr(   newaxismoveaxisr&   shaperI   rJ   rK   rL   stack)r\   r7   r8   r9   rM   rN   rO   rP   rV   all_resultsrT   outs   ````````    r   multiscale_basic_featuresrf   s   s    r 	5'*+8
 	
 c2::o&		E<4  R)K IOO11+>?H
((8"
%CJr   )TTT)TTTg      ?   NN)rJ   r   numpyr(   skimager   r   skimage.util.dtyper   _shared._dependency_checksr   concurrent.futuresr	   r   
contextlibr
   r0   r;   rU   rf   r   r   r   <module>rn      s    3   $ - 0E1&- & 59  
@J 
S Sr   