
    1-Ph.                         d dl Zd dlmZmZmZ ddlmZ ddlm	Z	 ddl
mZmZ ddlmZ dd	lmZmZmZ dd
lmZ g dZg dZg dZg dZd Zd Zd Zd Z G d de          ZdS )    N)maximum_filterminimum_filterconvolve   )integral_image   structure_tensor)octagonstar)_censure_dob_loop)FeatureDetector_prepare_grayscale_input_2D_mask_border_keypoints)check_nD)   r   r      )   r   )	      r   r   )   r   )   
   )r      r      )   r   )r       ))r   r   r   r   )r   r   r   r   )r   r   )r   r   )r   r   )r      r   r#   r   )r   r   r   r   r#      r   r                -   .   @   Z      ))r   r   r"   )r   r   r   )r   r   )r%   r   r$   )r   r%   )r   r   )r!   r   r   )r&   r!   c           
         t          j        | j        d         | j        d         ||z
  dz   ft           j                  }|dk    r|j        }||j        d         z  |||j        d         z  |j        d         z  f|_        t          |           }t          ||z
  dz             D ]F}||z   }dd|z  dz   dz  z  }	dd|dz  z  d|z  z   z  }
t          |||d d d d |f         |	|
           Gn|d	k    rot          ||z
  dz             D ]X}t          ||z   dz
           \  }}t          ||z   dz
           \  }}t          | t          ||||                    |d d d d |f<   Yn|d
k    rt          ||z
  dz             D ]r}t          t          ||z   dz
           d                  }t          t          ||z   dz
           d                  }t          | t          ||                    |d d d d |f<   s|S )Nr   r   dtypedob      ?r   r   r   r   r   )npzerosshapefloat64itemsizestridesr   ranger   OCTAGON_OUTER_SHAPEOCTAGON_INNER_SHAPEr   _octagon_kernel
STAR_SHAPESTAR_FILTER_SHAPE_star_kernel)image	min_scale	max_scalemoderesponse	item_sizeintegral_imgininner_weightouter_weightmonominims                   W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/censure.py_filter_imagerR   B   sd   x	QQY)>)BC2:  H u}}%	q))q))HN1,==
 &e,,y9,q011 	 	AAA
 !a%!)!11L"q!t)a!e"34L<!!!QQQ'!2L,   	$ 
		 y9,q011 	Q 	QA(Q):;FB(Q):;FB (BB0O0O P PHQQQ1W	Q
 
y9,q011 	D 	DA,Y]Q->?BCA,Y]Q->?BCA (Q0B0B C CHQQQ1WO    c                 Z   | d|z  z   dz  d|z  |dz   z  z
  }|d|z  z   dz  d|z  |dz   z  z
  }d||z
  z  }d|z  }| d|z  z   |d|z  z   z
  dz  }t          | |          }	t          j        | d|z  z   | d|z  z   f          }
t          ||          |
|| || f<   ||	z  ||z   |
z  z
  }|S )Nr   r   r3   )r   r4   r5   )rL   rM   rN   rO   outerinnerrK   rJ   c	outer_oct	inner_octbfilters               rQ   r=   r=   u   s    !b&[QR26!22E!b&[QR26!22E%%-(L;L
q2v+"q2v+	&1,ABI"q2v+rAF{344I#BOOIadAqbDjY&,*E)RRGNrS   c                     | | dz  z   |z
  |dz  z
  }t          |           }t          j        |          }t          |          ||| || f<   dt          j        ||z
            z  }dt          j        |          z  }||z  ||z   |z  z
  }|S )Nr   r3   )r   r4   
zeros_likesum)rP   rI   rW   
outer_star
inner_starrK   rJ   rZ   s           rQ   r@   r@      s    	AF
QaAaJz**J!!WWJq!tQrTz"&j!899:L
+++LZ'<,+F**TTGNrS   c                 h    t          ||d          \  }}}d| ||z   dz  |||z  |dz  z
  z  k    <   d S )Nrc)orderFr   r	   )feature_maskrA   sigmaline_thresholdArrArcAccs          rQ   _suppress_linesri      sL    $UE>>>MCcMRL#)!NcCi#q&6H$IIJJJrS   c                   *    e Zd ZdZ	 	 	 	 	 d
dZd Zd	S )CENSUREa  CENSURE keypoint detector.

    min_scale : int, optional
        Minimum scale to extract keypoints from.
    max_scale : int, optional
        Maximum scale to extract keypoints from. The keypoints will be
        extracted from all the scales except the first and the last i.e.
        from the scales in the range [min_scale + 1, max_scale - 1]. The filter
        sizes for different scales is such that the two adjacent scales
        comprise of an octave.
    mode : {'DoB', 'Octagon', 'STAR'}, optional
        Type of bi-level filter used to get the scales of the input image.
        Possible values are 'DoB', 'Octagon' and 'STAR'. The three modes
        represent the shape of the bi-level filters i.e. box(square), octagon
        and star respectively. For instance, a bi-level octagon filter consists
        of a smaller inner octagon and a larger outer octagon with the filter
        weights being uniformly negative in both the inner octagon while
        uniformly positive in the difference region. Use STAR and Octagon for
        better features and DoB for better performance.
    non_max_threshold : float, optional
        Threshold value used to suppress maximas and minimas with a weak
        magnitude response obtained after Non-Maximal Suppression.
    line_threshold : float, optional
        Threshold for rejecting interest points which have ratio of principal
        curvatures greater than this value.

    Attributes
    ----------
    keypoints : (N, 2) array
        Keypoint coordinates as ``(row, col)``.
    scales : (N,) array
        Corresponding scales.

    References
    ----------
    .. [1] Motilal Agrawal, Kurt Konolige and Morten Rufus Blas
           "CENSURE: Center Surround Extremas for Realtime Feature
           Detection and Matching",
           https://link.springer.com/chapter/10.1007/978-3-540-88693-8_8
           :DOI:`10.1007/978-3-540-88693-8_8`

    .. [2] Adam Schmidt, Marek Kraft, Michal Fularz and Zuzanna Domagala
           "Comparative Assessment of Point Feature Detectors and
           Descriptors in the Context of Robot Navigation"
           http://yadda.icm.edu.pl/yadda/element/bwmeta1.element.baztech-268aaf28-0faf-4872-a4df-7e2e61cb364c/c/Schmidt_comparative.pdf
           :DOI:`10.1.1.465.1117`

    Examples
    --------
    >>> from skimage.data import astronaut
    >>> from skimage.color import rgb2gray
    >>> from skimage.feature import CENSURE
    >>> img = rgb2gray(astronaut()[100:300, 100:300])
    >>> censure = CENSURE()
    >>> censure.detect(img)
    >>> censure.keypoints
    array([[  4, 148],
           [ 12,  73],
           [ 21, 176],
           [ 91,  22],
           [ 93,  56],
           [ 94,  22],
           [ 95,  54],
           [100,  51],
           [103,  51],
           [106,  67],
           [108,  15],
           [117,  20],
           [122,  60],
           [125,  37],
           [129,  37],
           [133,  76],
           [145,  44],
           [146,  94],
           [150, 114],
           [153,  33],
           [154, 156],
           [155, 151],
           [184,  63]])
    >>> censure.scales
    array([2, 6, 6, 2, 4, 3, 2, 3, 2, 6, 3, 2, 2, 3, 2, 2, 2, 3, 2, 2, 4, 2,
           2])

    r   r   DoB333333?r   c                     |                                 }|dvrt          d          |dk     s|dk     s	||z
  dk     rt          d          || _        || _        || _        || _        || _        d | _        d | _        d S )N)r2   r   r   z/`mode` must be one of 'DoB', 'Octagon', 'STAR'.r   r   z@The scales must be >= 1 and the number of scales should be >= 3.)	lower
ValueErrorrB   rC   rD   non_max_thresholdre   	keypointsscales)selfrB   rC   rD   rq   re   s         rQ   __init__zCENSURE.__init__   s     zz||111NOOOq==IMMY-BQ-F-FU   #"	!2,rS   c                 .   t          |d           | j        | j        z
  }t          j        t          |                    }t          || j        | j        | j                  }t          |d          |k    }t          |d          |k    }||z  }d||| j
        k     <   t          d|          D ]7}t          |dddd|f         |d| j        |z   dz
  dz  z   | j                   8t          j        |dd|f                   \  }}	}
t          j        ||	g          }|
| j        z   dz   }
| j        dk    r|| _        |
| _        dS t          j        |j        d	         t(          
          }| j        dk    rtt          | j        dz   | j                  D ]U}t*          |dz
           d	         dz
  dz  t*          |dz
           d         z   }|t-          |j        ||          |
|k    z  z  }Vn| j        dk    rt          | j        dz   | j                  D ]h}t.          t0          |dz
           d	                  t.          t0          |dz
           d	                  dz  z   }|t-          |j        ||          |
|k    z  z  }i||         | _        |
|         | _        dS )zDetect CENSURE keypoints along with the corresponding scale.

        Parameters
        ----------
        image : 2D ndarray
            Input image.

        r   )r   r   r   Fr   Ng      @.r2   r   r0   r   r   )r   rC   rB   r4   ascontiguousarrayr   rR   rD   r   r   rq   r:   ri   re   nonzerocolumn_stackrr   rs   r5   r6   boolr;   r   r>   r?   )rt   rA   
num_scalesfilter_responseminimasmaximasrc   rH   rowscolsrs   rr   cumulative_maskrW   s                 rQ   detectzCENSURE.detect  s   0 	^dn4
$%@%G%GHH (4>4>49
 
 !)<<O )<<O(AF_t'==>q*%% 
	 
	A
 QQQ1W%dnq(1,33#	     ZS!J,5F(GHHdFOT4L11	$.(1,9&DN DKF(9?1#5TBBB9	!!4>A-t~>>  (Q/2Q61<?RE@@   #9%+yRS#T#TaK$ 	 Y&  4>A-t~>>  0Q7:; !21q5!9!!<=BC   #9%+yRS#T#TaK$  #?3_-rS   N)r   r   rl   rm   r   )__name__
__module____qualname____doc__ru   r    rS   rQ   rk   rk      sZ        S Sn    4U. U. U. U. U.rS   rk   )numpyr4   scipy.ndimager   r   r   	transformr   cornerr
   
morphologyr   r   
censure_cyr   feature.utilr   r   r   _shared.utilsr   r;   r<   r>   r?   rR   r=   r@   ri   rk   r   rS   rQ   <module>r      s       B B B B B B B B B B & & & & & & $ $ $ $ $ $ & & & & & & & & ) ) ) ) ) )         
 % $ $ $ $ $        MLL
    0 0 0f
 
 
  S S S
E. E. E. E. E.o E. E. E. E. E.rS   