
    1-PhP'                         d dl Z d dl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 ddlmZ 	 	 	 	 	 	 	 	 	 ddZdS )    N)arctan2exppisqrt   )draw)img_as_float)gaussian)check_nD)gray2rgb            l1Fc
                    t          | dd           t          |           } | j        }
|4|2t          |          dz
  t          |          k    rt	          d          |t          |          |d         |t          |          dz
  |fdt                    D             }|fdt                    D             }|d	vrt	          d
          t          j        | j        |
          }t          j        | j        |
          }t          j	        | dd          |ddddf<   t          j	        | dd          |ddddf<   t          |dz  |dz  z             }t          ||          }t          z  }fdt                    D             }t          j        f| j        z   |
          }t          |          D ]b\  }}t          |t          j        ||z
            z            ||ddddf<   t          j        ||ddddf         |          ||ddddf<   c|d         g|z   }t          j        dz   f|j        z   |
          }t          dz             D ]D}t                    D ]2}t%          ||ddddf         ||         d          |||ddddf<   3Efdt                    D             }z  dz   z  }t          j        || j        d         dz  z
  | j        d         dz  z
  f|
          }|ddd  f         |dddddf<   }t                    D ]}t                    D ]}t'          t)          ||         t+          j        ||                   z                      z   }|j        d         |z   }t'          t)          ||         t+          j        ||                   z                      z   }|j        d         |z   }||dz   dd||||f         |||z   ddddf<   |z  }̌|dddd|dd|f         }|                    dd                              dd          }|dk    r|dz  }|dk    r1|t          j        |d          ddddt          j        f         z  }n|dk    rA|t          t          j        |dz  d                    ddddt          j        f         z  }n|dk    rt          d|          D ]m}t          t          j        |dddd||z   f         dz  d                    }|dddd||z   fxx         |ddddt          j        f         z  cc<   n|	rRt5          |           }t          |j        d                   D ]#}t          |j        d                   D ]}g d} ||z  z   }!||z  z   }"t7          j        |!|"t'          |d                             \  }#}$}%t7          j        ||#|$f| |%           t          j        |||ddf                   }&t          |          D ]\  }'}||||'f         |&z  }(|d         |(z  t+          j        |          z  }|d         |(z  t+          j        |          z  }t7          j        |!|"t'          |!|z             t'          |"|z                       \  }#}$}%t7          j        ||#|$f| |%           t          |          D ]\  })}*tA          d|)z             z  }+d|+z
  d|+f} t          |          D ]\  },}-|!t'          t)          |*t+          j        |-          z                      z   }.|"t'          t)          |*t+          j        |-          z                      z   }/t7          j        |.|/t'          ||)dz                                \  }#}$}%t7          j        ||#|$f| |%           t          |          D ]\  }'}||||)z  z  z   |,z  z   |'z   f         }(|(|&z  }(||)dz            |(z  t+          j        |          z  }||)dz            |(z  t+          j        |          z  }t7          j        |.|/t'          |.|z             t'          |/|z                       \  }#}$}%t7          j        ||#|$f| |%           Ð%||fS |S )a  Extract DAISY feature descriptors densely for the given image.

    DAISY is a feature descriptor similar to SIFT formulated in a way that
    allows for fast dense extraction. Typically, this is practical for
    bag-of-features image representations.

    The implementation follows Tola et al. [1]_ but deviate on the following
    points:

      * Histogram bin contribution are smoothed with a circular Gaussian
        window over the tonal range (the angular range).
      * The sigma values of the spatial Gaussian smoothing in this code do not
        match the sigma values in the original code by Tola et al. [2]_. In
        their code, spatial smoothing is applied to both the input image and
        the center histogram. However, this smoothing is not documented in [1]_
        and, therefore, it is omitted.

    Parameters
    ----------
    image : (M, N) array
        Input image (grayscale).
    step : int, optional
        Distance between descriptor sampling points.
    radius : int, optional
        Radius (in pixels) of the outermost ring.
    rings : int, optional
        Number of rings.
    histograms : int, optional
        Number of histograms sampled per ring.
    orientations : int, optional
        Number of orientations (bins) per histogram.
    normalization : [ 'l1' | 'l2' | 'daisy' | 'off' ], optional
        How to normalize the descriptors

          * 'l1': L1-normalization of each descriptor.
          * 'l2': L2-normalization of each descriptor.
          * 'daisy': L2-normalization of individual histograms.
          * 'off': Disable normalization.

    sigmas : 1D array of float, optional
        Standard deviation of spatial Gaussian smoothing for the center
        histogram and for each ring of histograms. The array of sigmas should
        be sorted from the center and out. I.e. the first sigma value defines
        the spatial smoothing of the center histogram and the last sigma value
        defines the spatial smoothing of the outermost ring. Specifying sigmas
        overrides the following parameter.

            ``rings = len(sigmas) - 1``

    ring_radii : 1D array of int, optional
        Radius (in pixels) for each ring. Specifying ring_radii overrides the
        following two parameters.

            ``rings = len(ring_radii)``
            ``radius = ring_radii[-1]``

        If both sigmas and ring_radii are given, they must satisfy the
        following predicate since no radius is needed for the center
        histogram.

            ``len(ring_radii) == len(sigmas) + 1``

    visualize : bool, optional
        Generate a visualization of the DAISY descriptors

    Returns
    -------
    descs : array
        Grid of DAISY descriptors for the given image as an array
        dimensionality  (P, Q, R) where

            ``P = ceil((M - radius*2) / step)``
            ``Q = ceil((N - radius*2) / step)``
            ``R = (rings * histograms + 1) * orientations``

    descs_img : (M, N, 3) array (only if visualize==True)
        Visualization of the DAISY descriptors.

    References
    ----------
    .. [1] Tola et al. "Daisy: An efficient dense descriptor applied to wide-
           baseline stereo." Pattern Analysis and Machine Intelligence, IEEE
           Transactions on 32.5 (2010): 815-830.
    .. [2] http://cvlab.epfl.ch/software/daisy
    r   imgN   z"`len(sigmas)-1 != len(ring_radii)`c                 F    g | ]}|d z   z  t          dz            z  S )r   r   float.0iradiusringss     V/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/skimage/feature/_daisy.py
<listcomp>zdaisy.<locals>.<listcomp>   s3    LLL!&AE"U1u9%5%55LLL    c                 @    g | ]}|d z   z  t                    z  S )r   r   r   s     r   r   zdaisy.<locals>.<listcomp>   s-    LLL!fA&u5LLLr    )r   l2daisyoffzInvalid normalization method.)dtype)naxisr   c                 @    g | ]}d |z  t           z  z  t           z
  S r   r   )r   oorientationss     r   r   zdaisy.<locals>.<listcomp>   s+    VVVQ!a%"*|3b8VVVr    reflect)sigmamodec                 0    g | ]}d t           z  |z  z  S r)   r*   )r   j
histogramss     r   r   zdaisy.<locals>.<listcomp>   s&    @@@QVaZ*$@@@r    r$   g|=r   )r'   r"   r#   )r   r   r   )alpha)!r   r	   r%   len
ValueErrorrangenpzerosshapediffr   r   r   empty	enumerater   cosmultiplyr
   introundmathsinswapaxessumnewaxisr   r   circle_perimeter_aa	set_colormaxline_aar   )0imagestepr   r   r2   r,   normalizationsigmas
ring_radii	visualizefloat_dtypedxdygrad_maggrad_oriorientation_kappaorientation_angleshistr   r+   hist_smoothr1   theta	desc_dimsdescsidxy_miny_maxx_minx_maxnorms	descs_imgcolordesc_ydesc_xrowscolsvalmax_bino_numbin_sizer_numrcolor_offsett_numthist_yhist_xs0     ````                                          r   r#   r#      sG
   D UAuE+K 	"KK!Os:..=>>>JBFa~LLLLLuU||LLLLLLLLuU||LLL
8888999 
%+[	1	1	1B	%+[	1	1	1B!!,,,Bqqq#2#vJ!!,,,BssAAAvJ BEBEM""Hr2H$r)VVVV%BUBUVVV8\Oek1EEED,-- = =1-x!|0D0DDEEQ111WDAAAqqqM8<<Q111W Qi[6!F(EAI<$*4KHHHK519  |$$ 	 	A&.Q111WVAYY' ' 'K1aaa
##	 A@@@eJ.?.?@@@E#a'<7IH	EKNQZ/Q!f*1LM  E "-Q66'>66'>-Q!RE-<-AAA

C5\\ 	  	 z"" 	  	 ASz!}txa7I7I'I!J!JKKKEKNU*ESz!}txa7I7I'I!J!JKKKEKNU*E4?Aqqq%+uU{25E#l**AAAqqq01 <CC	  !!!VVtVVVtV#$ENN1a  ))!Q//E D  RVE***111aaa+;<<EEd""T"&22233AAAqqq"*4DEEEEg%%1i66 M MRVE!!!QQQA4D0D*D$E$JQRSSSTTaaaAL 000111U111aaa;K5LL1111 4UOO	u{1~&& /	V /	VA5;q>** .V .V!		TF*TF*"&":FCq	NN# #dC y4,SIIII&q!QQQw00 )*< = = N NHE1$Q5[1G;HX-;BX-;B&*lFRK(8(8#frk:J:J' 'OD$ N9tTlEMMMMM )* 5 5 V VHE1#(U#3#3e#;L-q,?E$-e$4$4 V Vq!'#eAO.D.D*E*E!E!'#eAO.D.D*E*E!E*.*B"FCuqy0A,B,B+ +dC y4,SQQQQ(12D(E(E V VHE1', ! ! ,"'*"4|"C!D"',"6!7 #(!(!)(H %/H!'	!2X!=!KB!'	!2X!=!KB.2l &FRK0@0@#frkBRBR/ /OD$ !N9tTlEQTUUUUU!VVV'.V^ ir    )	r   r   r   r   r   r   NNF)rA   numpyr7   r   r   r   r    r   
util.dtyper	   _shared.filtersr
   _shared.utilsr   rc   r   r#    r    r   <module>ry      s         ( ( ( ( ( ( ( ( ( ( ( (       % % % % % % & & & & & & $ $ $ $ $ $      
 

l l l l l lr    