
    1-Ph                         d dl ZddlmZ ddlmZmZ  G d d          Z G d d          Zd	dd
dddZ	d Z
d Zd ZdS )    N   )img_as_float)_supported_float_typecheck_nDc                       e Zd Zd Zd ZdS )FeatureDetectorc                 8    t          j        g           | _        d S N)nparray
keypoints_selfs    T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/util.py__init__zFeatureDetector.__init__   s    (2,,    c                     t                      )z}Detect keypoints in image.

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

        NotImplementedError)r   images     r   detectzFeatureDetector.detect   s     "###r   N)__name__
__module____qualname__r   r    r   r   r   r   
   s2        ' ' '	$ 	$ 	$ 	$ 	$r   r   c                       e Zd Zd Zd ZdS )DescriptorExtractorc                 8    t          j        g           | _        d S r
   )r   r   descriptors_r   s    r   r   zDescriptorExtractor.__init__   s    HRLLr   c                     t                      )zExtract feature descriptors in image for given keypoints.

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

        r   )r   r   	keypointss      r   extractzDescriptorExtractor.extract   s     "###r   N)r   r   r   r   r"   r   r   r   r   r      s2        ) ) )$ $ $ $ $r   r   kF
horizontal)keypoints_colormatches_coloronly_matches	alignmentc                   t          |           } t          |          }t          | j                  }
t          |j                  }| j        d         |j        d         k     r|j        d         |
d<   n,| j        d         |j        d         k    r| j        d         |d<   | j        d         |j        d         k     r|j        d         |
d<   n,| j        d         |j        d         k    r| j        d         |d<   |
| j        k    r>t          j        |
| j                  }| |d| j        d         d| j        d         f<   |} ||j        k    r>t          j        ||j                  }||d|j        d         d|j        d         f<   |}t          j        | j                  }|	dk    rt          j        | |gd          }d|d<   n9|	dk    rt          j        | |gd          }d|d<   nd|	 d	}t          |          |sl|	                    |dddf         |dddf         d
|           |	                    |dddf         |d         z   |dddf         |d         z   d
|           |
                    |d           |                    d| j        d         |d         z   | j        d         |d         z   df           |j        d         }ddlm} <t          j                            d          fdt!          |          D             }n^ |          rfdt!          |          D             }n7t#          d          rt%                    |k    r}nd}t          |          t'          |          D ]_\  }}|\  }}|                    ||df         ||df         |d         z   f||df         ||df         |d         z   fd||                    `dS )a  Plot matched features between two images.

    .. versionadded:: 0.23

    Parameters
    ----------
    image0 : (N, M [, 3]) array
        First image.
    image1 : (N, M [, 3]) array
        Second image.
    keypoints0 : (K1, 2) array
        First keypoint coordinates as ``(row, col)``.
    keypoints1 : (K2, 2) array
        Second keypoint coordinates as ``(row, col)``.
    matches : (Q, 2) array
        Indices of corresponding matches in first and second sets of
        descriptors, where `matches[:, 0]` (resp. `matches[:, 1]`) contains
        the indices in the first (resp. second) set of descriptors.
    ax : matplotlib.axes.Axes
        The Axes object where the images and their matched features are drawn.
    keypoints_color : matplotlib color, optional
        Color for keypoint locations.
    matches_color : matplotlib color or sequence thereof, optional
        Single color or sequence of colors for each line defined by `matches`,
        which connect keypoint matches. See [1]_ for an overview of supported
        color formats. By default, colors are picked randomly.
    only_matches : bool, optional
        Set to True to plot matches only and not the keypoint locations.
    alignment : {'horizontal', 'vertical'}, optional
        Whether to show the two images side by side (`'horizontal'`), or one above
        the other (`'vertical'`).

    References
    ----------
    .. [1] https://matplotlib.org/stable/users/explain/colors/colors.html#specifying-colors

    Notes
    -----
    To make a sequence of colors passed to `matches_color` work for any number of
    `matches`, you can wrap that sequence in :func:`itertools.cycle`.
    r      )dtypeNr$   )axisverticalzV`plot_matched_features` accepts either 'horizontal' or 'vertical' for alignment, but 'z~' was given. See https://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.plot_matched_features for details.none)
facecolors
edgecolorsgray)cmap)is_color_like)seedc                 :    g | ]}                     d           S )   )random).0_rngs     r   
<listcomp>z)plot_matched_features.<locals>.<listcomp>   s#    BBBA#**Q--BBBr   c                     g | ]}S r   r   )r8   r9   r&   s     r   r;   z)plot_matched_features.<locals>.<listcomp>   s    BBBA-BBBr   __len__zb`matches_color` needs to be a single color or a sequence of length equal to the number of matches.-)color)r   listshaper   zerosr+   r   concatenate
ValueErrorscatterimshowr,   matplotlib.colorsr3   r7   default_rngrangehasattrlen	enumerateplot)image0image1
keypoints0
keypoints1matchesaxr%   r&   r'   r(   
new_shape0
new_shape1
new_image0
new_image1offsetr   mesgnumber_of_matchesr3   colorserror_messageimatchidx0idx1r:   s          `                 @r   plot_matched_featuresra   ,   s   l &!!F&!!Ffl##Jfl##J|Aa((Q
1	a6<?	*	*Q
1|Aa((Q
1	a6<?	*	*Q
1V\!!Xj===
;A
$V\!_$&7Q&778V\!!Xj===
;A
$V\!_$&7Q&778Xfl##FL  /a888q			j	 	 /a888q		(   	  



qqq!tqqq!t&	 	 	
 	
 	
 	

qqq!tvay(qqq!tvay(&	 	 	
 	
 	
 IIe&I!!!GGQQ&)+V\!_vay-H!LMMMa(//////i###++BBBB/@)A)ABBB	}	%	% 
(BBBB/@)A)ABBB			*	* (s=/A/AEV/V/VF 	 '''g&& 
 
5
d
a *T1W"5q	"ABa *T1W"5q	"AB)	 	 	
 	
 	
 	

 
r   c                     t          j        |           } t          | d           t          |           } t	          | j                  }|                     |d          S )Nr   Fcopy)r   squeezer   r   r   r+   astyper   float_dtypes     r   _prepare_grayscale_input_2Dri      sS    JuEUAE'44K<<%<000r   c                     t          j        |           } t          | t          dd                     t	          |           } t          | j                  }|                     |d          S )Nr      Frc   )r   re   r   rI   r   r   r+   rf   rg   s     r   _prepare_grayscale_input_nDrl      s[    JuEUE!QKK   E'44K<<%<000r   c                     | d         }| d         }|dz
  |dddf         k     |dddf         ||z
  dz   k     z  |dz
  |dddf         k     z  |dddf         ||z
  dz   k     z  }|S )a  Mask coordinates that are within certain distance from the image border.

    Parameters
    ----------
    image_shape : (2,) array_like
        Shape of the image as ``(rows, cols)``.
    keypoints : (N, 2) array
        Keypoint coordinates as ``(rows, cols)``.
    distance : int
        Image border distance.

    Returns
    -------
    mask : (N,) bool array
        Mask indicating if pixels are within the image (``True``) or in the
        border region of the image (``False``).

    r   r*   Nr   )image_shaper!   distancerowscolsmasks         r   _mask_border_keypointsrs      s    ( q>Dq>D Q,)AAAqD/	)QQQT?dXo12	4qLIaaadO+	- QQQT?dXo12	4 	 Kr   )numpyr   utilr   _shared.utilsr   r   r   r   ra   ri   rl   rs   r   r   r   <module>rw      s                    $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $4 K
 K
 K
 K
 K
\1 1 11 1 1    r   