
    9i                         S SK r S SKrS SKJr  SSKJr  SSKJr  SSK	J
r
  SSKJrJrJr  \" \R                  5      \" S	5      :  r " S
 S\5      rg)    N)Version   )gaussian)check_nD   )_brief_loop)DescriptorExtractor_mask_border_keypoints_prepare_grayscale_input_2D2c                   *    \ rS rSrSr SS jrS rSrg)BRIEF   a  BRIEF binary descriptor extractor.

BRIEF (Binary Robust Independent Elementary Features) is an efficient
feature point descriptor. It is highly discriminative even when using
relatively few bits and is computed using simple intensity difference
tests.

For each keypoint, intensity comparisons are carried out for a specifically
distributed number N of pixel-pairs resulting in a binary descriptor of
length N. For binary descriptors the Hamming distance can be used for
feature matching, which leads to lower computational cost in comparison to
the L2 norm.

Parameters
----------
descriptor_size : int, optional
    Size of BRIEF descriptor for each keypoint. Sizes 128, 256 and 512
    recommended by the authors. Default is 256.
patch_size : int, optional
    Length of the two dimensional square patch sampling region around
    the keypoints. Default is 49.
mode : {'normal', 'uniform'}, optional
    Probability distribution for sampling location of decision pixel-pairs
    around keypoints.
rng : {`numpy.random.Generator`, int}, optional
    Pseudo-random number generator (RNG).
    By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
    If `rng` is an int, it is used to seed the generator.

    The PRNG is used for the random sampling of the decision
    pixel-pairs. From a square window with length `patch_size`,
    pixel pairs are sampled using the `mode` parameter to build
    the descriptors using intensity comparison.

    For matching across images, the same `rng` should be used to construct
    descriptors. To facilitate this:

    (a) `rng` defaults to 1
    (b) Subsequent calls of the ``extract`` method will use the same rng/seed.
sigma : float, optional
    Standard deviation of the Gaussian low-pass filter applied to the image
    to alleviate noise sensitivity, which is strongly recommended to obtain
    discriminative and good descriptors.

Attributes
----------
descriptors : (Q, `descriptor_size`) array of dtype bool
    2D ndarray 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)``.
mask : (N,) array of dtype bool
    Mask indicating whether a keypoint has been filtered out
    (``False``) or is described in the `descriptors` array (``True``).

Examples
--------
>>> from skimage.feature import (corner_harris, corner_peaks, BRIEF,
...                              match_descriptors)
>>> import numpy as np
>>> square1 = np.zeros((8, 8), dtype=np.int32)
>>> square1[2:6, 2:6] = 1
>>> square1
array([[0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
>>> square2 = np.zeros((9, 9), dtype=np.int32)
>>> square2[2:7, 2:7] = 1
>>> square2
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
>>> keypoints1 = corner_peaks(corner_harris(square1), min_distance=1)
>>> keypoints2 = corner_peaks(corner_harris(square2), min_distance=1)
>>> extractor = BRIEF(patch_size=5)
>>> extractor.extract(square1, keypoints1)
>>> descriptors1 = extractor.descriptors
>>> extractor.extract(square2, keypoints2)
>>> descriptors2 = extractor.descriptors
>>> matches = match_descriptors(descriptors1, descriptors2)
>>> matches
array([[0, 0],
       [1, 1],
       [2, 2],
       [3, 3]])
>>> keypoints1[matches[:, 0]]
array([[2, 2],
       [2, 5],
       [5, 2],
       [5, 5]])
>>> keypoints2[matches[:, 1]]
array([[2, 2],
       [2, 6],
       [6, 2],
       [6, 6]])

c                 r   UR                  5       nUS;  a  [        S5      eXl        X l        X0l        X@l        [        U[        R                  R                  5      (       a_  UR                  nUR                  nUR                  S5      u  n[        R                  R                  [        U5      " U5      5      U l        OhUcA  [        R                  R                  [        R                  R!                  5       5      U l        O$[        R                  R                  U5      U l        S U l        S U l        g )N)normaluniformz%`mode` must be 'normal' or 'uniform'.r   )lower
ValueErrordescriptor_size
patch_sizemodesigma
isinstancenprandom	Generator_bit_generator	_seed_seqspawntyperngdefault_rngSeedSequencedescriptorsmask)	selfr   r   r   r   r!   bgsschild_sss	            U/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/skimage/feature/brief.py__init__BRIEF.__init__   s     zz|,,DEE.$	
c299..// ##BB((1+KXyy**48H+=>DH[yy,,RYY-C-C-EFDHyy,,S1DH	    c                    [        US5        [        R                  " U R                  5      n[	        U5      n[
        R                  " [        XR                  SS95      nU R                  nU R                  nU R                  S:X  a  US-  UR                  US-  5      -  n[
        R                  " U[
        R                  S9nUXeS-  :  XeS-
  * S-  :  -     nUSUS-   R                  US5      nXdS-  US	-   R                  US5      nOqU R                  S
:X  aa  UR!                  US-
  * S-  US-  S-   US-  S45      n[
        R                  " U[
        R                  S9n[
        R"                  " US5      u  px[
        R                  " W5      n[
        R                  " W5      n[%        UR&                  X%S-  5      U l        [
        R                  " X R(                  SS24   [
        R*                  S[,        (       a  SOSS9n[
        R.                  " UR&                  S   U4[0        SS9U l        [5        XR2                  R7                  [
        R8                  5      X'U5        g)zExtract BRIEF binary descriptors for given keypoints in image.

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

r   reflect)r   r   r   g      @   )dtypeN   r   r   CF)r1   ordercopyr   )r1   r4   )r   r5   deepcopyr!   r   r   ascontiguousarrayr   r   r   r   r   standard_normalarrayint32reshapeintegerssplitr
   shaper%   int64np2zerosboolr$   r   viewuint8)	r&   image	keypointsr!   	desc_sizer   samplespos1pos2s	            r*   extractBRIEF.extract   s    	 mmDHH%+E2 $$Xe::I%VW ((	__
99 !C'3+>+>y1}+MMGhhwbhh7G!O,!^;LPQ;Q1QRG ?Y]+33IqADq=9q=9AA)QODYY)#llq.!Q&qA(=	Aq?QG hhwbhh7G'1-JD##D)##D) +5;;	QR?S	HHiil#((%	
	 88__Q+4s
 	E++00:ITRr-   )r   r$   r%   r   r   r!   r   N)   1   r   r   r   )__name__
__module____qualname____firstlineno____doc__r+   rK   __static_attributes__ r-   r*   r   r      s    l^ OP8:Sr-   r   )r5   numpyr   packaging.versionr   _shared.filtersr   _shared.utilsr   brief_cyr   utilr	   r
   r   __version__r@   r   rU   r-   r*   <module>r]      sK      % & $ !  bnn-ES ESr-   