
    1-Ph\3                     N   d dl ZddlmZmZmZmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ dd	lmZ  ej        d
          Zg dZ edd          D ]@Z ee ee                    e ee                   dz             D ]Zdedez   dez   f<   A G d dee          ZdS )    N   )FeatureDetectorDescriptorExtractor_mask_border_keypoints_prepare_grayscale_input_2D   )corner_fastcorner_orientationscorner_peakscorner_harris)pyramid_gaussian)check_nD)NP_COPY_IF_NEEDED)	_orb_loop)   r   )   r   r   r      r   r      r         
   	            i   r   c                   J    e Zd ZdZ	 	 	 	 	 	 ddZd	 Zd
 Zd Zd Zd Z	d Z
dS )ORBa  Oriented FAST and rotated BRIEF feature detector and binary descriptor
    extractor.

    Parameters
    ----------
    n_keypoints : int, optional
        Number of keypoints to be returned. The function will return the best
        `n_keypoints` according to the Harris corner response if more than
        `n_keypoints` are detected. If not, then all the detected keypoints
        are returned.
    fast_n : int, optional
        The `n` parameter in `skimage.feature.corner_fast`. Minimum number of
        consecutive pixels out of 16 pixels on the circle that should all be
        either brighter or darker w.r.t test-pixel. A point c on the circle is
        darker w.r.t test pixel p if ``Ic < Ip - threshold`` and brighter if
        ``Ic > Ip + threshold``. Also stands for the n in ``FAST-n`` corner
        detector.
    fast_threshold : float, optional
        The ``threshold`` parameter in ``feature.corner_fast``. Threshold used
        to decide whether the pixels on the circle are brighter, darker or
        similar w.r.t. the test pixel. Decrease the threshold when more
        corners are desired and vice-versa.
    harris_k : float, optional
        The `k` parameter in `skimage.feature.corner_harris`. Sensitivity
        factor to separate corners from edges, typically in range ``[0, 0.2]``.
        Small values of `k` result in detection of sharp corners.
    downscale : float, optional
        Downscale factor for the image pyramid. Default value 1.2 is chosen so
        that there are more dense scales which enable robust scale invariance
        for a subsequent feature description.
    n_scales : int, optional
        Maximum number of scales from the bottom of the image pyramid to
        extract the features from.

    Attributes
    ----------
    keypoints : (N, 2) array
        Keypoint coordinates as ``(row, col)``.
    scales : (N,) array
        Corresponding scales.
    orientations : (N,) array
        Corresponding orientations in radians.
    responses : (N,) array
        Corresponding Harris corner responses.
    descriptors : (Q, `descriptor_size`) array of dtype bool
        2D array of binary descriptors of size `descriptor_size` for Q
        keypoints after filtering out border keypoints with value at an
        index ``(i, j)`` either being ``True`` or ``False`` representing
        the outcome of the intensity comparison for i-th keypoint on j-th
        decision pixel-pair. It is ``Q == np.sum(mask)``.

    References
    ----------
    .. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski
          "ORB: An efficient alternative to SIFT and SURF"
          http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf

    Examples
    --------
    >>> from skimage.feature import ORB, match_descriptors
    >>> img1 = np.zeros((100, 100))
    >>> img2 = np.zeros_like(img1)
    >>> rng = np.random.default_rng(19481137)  # do not copy this value
    >>> square = rng.random((20, 20))
    >>> img1[40:60, 40:60] = square
    >>> img2[53:73, 53:73] = square
    >>> detector_extractor1 = ORB(n_keypoints=5)
    >>> detector_extractor2 = ORB(n_keypoints=5)
    >>> detector_extractor1.detect_and_extract(img1)
    >>> detector_extractor2.detect_and_extract(img2)
    >>> matches = match_descriptors(detector_extractor1.descriptors,
    ...                             detector_extractor2.descriptors)
    >>> matches
    array([[0, 0],
           [1, 1],
           [2, 2],
           [3, 4],
           [4, 3]])
    >>> detector_extractor1.keypoints[matches[:, 0]]
    array([[59. , 59. ],
           [40. , 40. ],
           [57. , 40. ],
           [46. , 58. ],
           [58.8, 58.8]])
    >>> detector_extractor2.keypoints[matches[:, 1]]
    array([[72., 72.],
           [53., 53.],
           [70., 53.],
           [59., 71.],
           [72., 72.]])

    333333?r     r   {Gz?{Gz?c                     || _         || _        || _        || _        || _        || _        d | _        d | _        d | _        d | _	        d | _
        d S )N)	downscalen_scalesn_keypointsfast_nfast_thresholdharris_k	keypointsscales	responsesorientationsdescriptors)selfr$   r%   r&   r'   r(   r)   s          S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/orb.py__init__zORB.__init__w   s[     # &,      c                 z    t          |          }t          t          || j        dz
  | j        d                     S )Nr   )channel_axis)r   listr   r%   r$   )r/   images     r0   _build_pyramidzORB._build_pyramid   sE    +E22t}q($.t  
 
 	
r2   c                    |j         }t          || j        | j                  }t	          |d          }t          |          dk    rAt          j        d|          t          j        d|          t          j        d|          fS t          |j	        |d          }||         }t          ||t                    }t          |d	| j        
          }||d d df         |d d df         f         }|||fS )Nr   )min_distancer   )r   r   dtype)r   r   distancek)methodr>   )r;   r	   r'   r(   r   lennpzerosr   shaper
   
OFAST_MASKr   r)   )	r/   octave_imager;   fast_responser*   maskr-   harris_responser,   s	            r0   _detect_octavezORB._detect_octave   s    "#L$+t?RSS Q???	y>>Qu---U+++U+++  &l&8)bQQQdO	*<JOO'SDMRRR#IaaadOYqqq!t_$DE	,	11r2   c                    t          |d           |                     |          }g }g }g }g }t          t          |                    D ]}t	          j        ||                   }t	          j        |          j        dk     r n|                     |          \  }	}
}|	                    |	| j
        |z  z             |	                    |
           |	                    t	          j        |	j        d         | j
        |z  |j                             |	                    |           t	          j        |          }	t	          j        |          }
t	          j        |          }t	          j        |          }|	j        d         | j        k     r|	| _        || _        |
| _        || _        dS |                                ddd         d| j                 }|	|         | _        ||         | _        |
|         | _        ||         | _        dS )zDetect oriented FAST keypoints along with the corresponding scale.

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

        r   r   r:   N)r   r7   ranger@   rA   ascontiguousarraysqueezendimrI   appendr$   fullrC   r;   vstackhstackr&   r*   r+   r-   r,   argsort)r/   r6   pyramidkeypoints_listorientations_listscales_listresponses_listoctaverE   r*   r-   r,   r+   best_indicess                 r0   detectz
ORB.detect   s    	%%e,,CLL)) 	- 	-F/@@Lz,'',q00151D1D\1R1R.I|Y!!)dnf.D"DEEE$$\222OA&NF*&,     !!),,,,In--	y!233;''In--	?1 000&DN DK ,D&DNNN %,,..ttt45Gt7G5GHL&|4DN .DK ,\ :D&|4DNNNr2   c                     t          |j        |d          }t          j        ||         t          j        dt
                    }t          j        ||         dd          }t          |||          }||fS )N   r<   C)r;   ordercopyF)r`   ra   )r   rC   rA   arrayintpr   r   )r/   rE   r*   r-   rG   r.   s         r0   _extract_octavezORB._extract_octave   sx    %l&8)bQQQHdO27#<M
 
 
	 xT 2#EJJJiFFD  r2   c                    t          |d           |                     |          }g }g }t          j        |          t          j        | j                  z                      t          j                  }t          t          |                    D ]}	||	k    }
t          j	        |
          dk    r{t          j
        ||	                   }||
         }|| j        |	z  z  }||
         }|                     |||          \  }}|                    |           |                    |           t          j        |                              t                    | _        t          j        |          | _        dS )a  Extract rBRIEF binary descriptors for given keypoints in image.

        Note that the keypoints must be extracted using the same `downscale`
        and `n_scales` parameters. Additionally, if you want to extract both
        keypoints and descriptors you should use the faster
        `detect_and_extract`.

        Parameters
        ----------
        image : 2D array
            Input image.
        keypoints : (N, 2) array
            Keypoint coordinates as ``(row, col)``.
        scales : (N,) array
            Corresponding scales.
        orientations : (N,) array
            Corresponding orientations in radians.

        r   r   N)r   r7   rA   logr$   astyperc   rL   r@   sumrM   rd   rP   rR   viewboolr.   rS   mask_)r/   r6   r*   r+   r-   rU   descriptors_list	mask_listoctavesrZ   octave_maskrE   octave_keypointsoctave_orientationsr.   rG   s                   r0   extractzORB.extract   s^   ( 	%%e,,	 6&>>BF4>$:$::BB27KKCLL)) 	' 	'F!V+Kvk""Q&&!3GFODD#,[#9  DNF$:: &2;&?#$($8$8 "24G% %!T !''444  &&&9%566;;DAAYy))


r2   c                 X   t          |d           |                     |          }g }g }g }g }g }t          t          |                    D ]}t	          j        ||                   }	t	          j        |	          j        dk     r n]|                     |	          \  }
}}t          |
          dk    rY|	                    |
           |	                    |           |	                    t	          j
        dt                               |                     |	|
|          \  }}|
|         | j        |z  z  }|	                    |           |	                    ||                    |	                    ||                    |	                    | j        |z  t	          j        |j        d         t          j                  z             |	                    |           t          |          dk    rt#          d          t	          j        |          }
t	          j        |          }t	          j        |          }t	          j        |          }t	          j        |                              t                    }|
j        d         | j        k     r%|
| _        || _        || _        || _        || _        dS |                                ddd         d| j                 }|
|         | _        ||         | _        ||         | _        ||         | _        ||         | _        dS )zDetect oriented FAST keypoints and extract rBRIEF descriptors.

        Note that this is faster than first calling `detect` and then
        `extract`.

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

        r   r   )r      r:   znORB found no features. Try passing in an image containing greater intensity contrasts between adjacent pixels.NrK   )r   r7   rL   r@   rA   rM   rN   rO   rI   rP   rB   rj   rd   r$   onesrC   rc   RuntimeErrorrR   rS   ri   r&   r*   r+   r-   r,   r.   rT   )r/   r6   rU   rV   rY   rX   rW   rl   rZ   rE   r*   r-   r,   r.   rG   scaled_keypointsr+   r[   s                     r0   detect_and_extractzORB.detect_and_extract"  s    	%%e,,CLL)) 	1 	1F/@@Lz,'',q00151D1D\1R1R.I|Y9~~""%%i000%%i000 ''(F(F(FGGG $ 4 4i! !K  )1GG!!"2333!!)D/222$$\$%7888&'*0327CCCD   ##K0000{q  G  
 In--	In--	;''y!233i 01166t<<?1 000&DN DK ,D&DN*D %,,..ttt45Gt7G5GHL&|4DN .DK ,\ :D&|4DN*<8Dr2   N)r   r   r    r   r!   r"   )__name__
__module____qualname____doc__r1   r7   rI   r\   rd   rr   rx    r2   r0   r   r      s        [ [~        ,
 
 
2 2 2.65 65 65p	! 	! 	!1* 1* 1*fL9 L9 L9 L9 L9r2   r   )numpyrA   feature.utilr   r   r   r   cornerr	   r
   r   r   	transformr   _shared.utilsr   _shared.compatr   orb_cyr   rB   rD   
OFAST_UMAXrL   iabsjr   r}   r2   r0   <module>r      s                  R Q Q Q Q Q Q Q Q Q Q Q ( ( ( ( ( ( $ $ $ $ $ $ . . . . . .       RXh
III
	sB ' 'AUJss1vv&&
33q66(:Q(>?? ' '%&
2626>""'U9 U9 U9 U9 U9/. U9 U9 U9 U9 U9r2   