U
    ƒ±ËhÞ  ã                   @   sf   d dl ZddlmZ ddlmZmZ G dd„ dƒZG dd„ dƒZddd„Z	dd„ Z
dd„ Zdd„ ZdS )é    Né   )Úimg_as_float)Ú_supported_float_typeÚcheck_nDc                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚFeatureDetectorc                 C   s   t  g ¡| _d S ©N)ÚnpÚarrayZ
keypoints_©Úself© r   ú8/tmp/pip-unpacked-wheel-gtraehzf/skimage/feature/util.pyÚ__init__	   s    zFeatureDetector.__init__c                 C   s
   t ƒ ‚dS )z}Detect keypoints in image.

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

        N©ÚNotImplementedError)r   Úimager   r   r   Údetect   s    	zFeatureDetector.detectN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚDescriptorExtractorc                 C   s   t  g ¡| _d S r   )r   r	   Zdescriptors_r
   r   r   r   r      s    zDescriptorExtractor.__init__c                 C   s
   t ƒ ‚dS )zïExtract feature descriptors in image for given keypoints.

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

        Nr   )r   r   Ú	keypointsr   r   r   Úextract   s    zDescriptorExtractor.extractN)r   r   r   r   r   r   r   r   r   r      s   r   ÚkFÚ
horizontalc
                 C   sà  t |ƒ}t |ƒ}t|jƒ}
t|jƒ}|jd |jd k rH|jd |
d< n"|jd |jd krj|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}||d|jd …d|jd …f< |}||jkr.tj||jd}||d|jd …d|jd …f< |}t |j¡}|	dkr`tj||gdd}d|d< n:|	dkr†tj||gdd}d|d< nd|	› d	}t|ƒ‚|s| j	|dd…df |dd…df d
|d | j	|dd…df |d  |dd…df |d  d
|d | j
|dd |  d|jd |d  |jd |d  df¡ tj ¡ }t|jd ƒD ]‚}||df }||df }|dkrŠ| d¡}n|}| j||df ||df |d  f||df ||df |d  fd|d qXdS )a¼  Plot matched features.

    Parameters
    ----------
    ax : matplotlib.axes.Axes
        Matches and image are drawn in this ax.
    image1 : (N, M [, 3]) array
        First grayscale or color image.
    image2 : (N, M [, 3]) array
        Second grayscale or color image.
    keypoints1 : (K1, 2) array
        First keypoint coordinates as ``(row, col)``.
    keypoints2 : (K2, 2) array
        Second keypoint coordinates as ``(row, col)``.
    matches : (Q, 2) array
        Indices of corresponding matches in first and second set of
        descriptors, where ``matches[:, 0]`` denote the indices in the first
        and ``matches[:, 1]`` the indices in the second set of descriptors.
    keypoints_color : matplotlib color, optional
        Color for keypoint locations.
    matches_color : matplotlib color, optional
        Color for lines which connect keypoint matches. By default the
        color is chosen randomly.
    only_matches : bool, optional
        Whether to only plot matches and not plot the keypoint locations.
    alignment : {'horizontal', 'vertical'}, optional
        Whether to show images side by side, ``'horizontal'``, or one above
        the other, ``'vertical'``.

    r   é   )ÚdtypeNr   )ÚaxisZverticalzKplot_matches accepts either 'horizontal' or 'vertical' for alignment, but 'zu' was given. See https://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.plot_matches for details.Únone)Z
facecolorsZ
edgecolorsZgray)Zcmapé   ú-)Úcolor)r   ÚlistÚshaper   Úzerosr   r	   ZconcatenateÚ
ValueErrorZscatterZimshowr   ÚrandomZdefault_rngÚrangeZplot)ZaxZimage1Zimage2Z
keypoints1Z
keypoints2ÚmatchesZkeypoints_colorZmatches_colorZonly_matchesÚ	alignmentZ
new_shape1Z
new_shape2Z
new_image1Z
new_image2Úoffsetr   ZmesgÚrngÚiZidx1Zidx2r!   r   r   r   Úplot_matches+   sh    !


  



  ÿ0 ÿ.

" þr-   c                 C   s4   t  | ¡} t| dƒ t| ƒ} t| jƒ}| j|ddS )Nr   F©Úcopy)r   Úsqueezer   r   r   r   Úastype©r   Zfloat_dtyper   r   r   Ú_prepare_grayscale_input_2D   s
    


r3   c                 C   s:   t  | ¡} t| tddƒƒ t| ƒ} t| jƒ}| j|ddS )Nr   é   Fr.   )r   r0   r   r'   r   r   r   r1   r2   r   r   r   Ú_prepare_grayscale_input_nD•   s
    

r5   c                 C   s|   | d }| d }|d |dd…df k |dd…df || d k @ |d |dd…df k @ |dd…df || d k @ }|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   )Zimage_shaper   ZdistanceZrowsÚcolsÚmaskr   r   r   Ú_mask_border_keypoints   s    ÿþýr8   )r   NFr   )Znumpyr   Úutilr   Z_shared.utilsr   r   r   r   r-   r3   r5   r8   r   r   r   r   Ú<module>   s         þ
b