You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

418 lines
12 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** @file sift.h
  2. ** @brief SIFT (@ref sift)
  3. ** @author Andrea Vedaldi
  4. **/
  5. /*
  6. Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
  7. All rights reserved.
  8. This file is part of the VLFeat library and is made available under
  9. the terms of the BSD license (see the COPYING file).
  10. */
  11. #ifndef VL_SIFT_H
  12. #define VL_SIFT_H
  13. #include <stdio.h>
  14. #include "generic.h"
  15. /** @brief SIFT filter pixel type */
  16. typedef float vl_sift_pix ;
  17. /** ------------------------------------------------------------------
  18. ** @brief SIFT filter keypoint
  19. **
  20. ** This structure represent a keypoint as extracted by the SIFT
  21. ** filter ::VlSiftFilt.
  22. **/
  23. typedef struct _VlSiftKeypoint
  24. {
  25. int o ; /**< o coordinate (octave). */
  26. int ix ; /**< Integer unnormalized x coordinate. */
  27. int iy ; /**< Integer unnormalized y coordinate. */
  28. int is ; /**< Integer s coordinate. */
  29. float x ; /**< x coordinate. */
  30. float y ; /**< y coordinate. */
  31. float s ; /**< s coordinate. */
  32. float sigma ; /**< scale. */
  33. } VlSiftKeypoint ;
  34. /** ------------------------------------------------------------------
  35. ** @brief SIFT filter
  36. **
  37. ** This filter implements the SIFT detector and descriptor.
  38. **/
  39. typedef struct _VlSiftFilt
  40. {
  41. double sigman ; /**< nominal image smoothing. */
  42. double sigma0 ; /**< smoothing of pyramid base. */
  43. double sigmak ; /**< k-smoothing */
  44. double dsigma0 ; /**< delta-smoothing. */
  45. int width ; /**< image width. */
  46. int height ; /**< image height. */
  47. int O ; /**< number of octaves. */
  48. int S ; /**< number of levels per octave. */
  49. int o_min ; /**< minimum octave index. */
  50. int s_min ; /**< minimum level index. */
  51. int s_max ; /**< maximum level index. */
  52. int o_cur ; /**< current octave. */
  53. vl_sift_pix *temp ; /**< temporary pixel buffer. */
  54. vl_sift_pix *octave ; /**< current GSS data. */
  55. vl_sift_pix *dog ; /**< current DoG data. */
  56. int octave_width ; /**< current octave width. */
  57. int octave_height ; /**< current octave height. */
  58. vl_sift_pix *gaussFilter ; /**< current Gaussian filter */
  59. double gaussFilterSigma ; /**< current Gaussian filter std */
  60. vl_size gaussFilterWidth ; /**< current Gaussian filter width */
  61. VlSiftKeypoint* keys ;/**< detected keypoints. */
  62. int nkeys ; /**< number of detected keypoints. */
  63. int keys_res ; /**< size of the keys buffer. */
  64. double peak_thresh ; /**< peak threshold. */
  65. double edge_thresh ; /**< edge threshold. */
  66. double norm_thresh ; /**< norm threshold. */
  67. double magnif ; /**< magnification factor. */
  68. double windowSize ; /**< size of Gaussian window (in spatial bins) */
  69. vl_sift_pix *grad ; /**< GSS gradient data. */
  70. int grad_o ; /**< GSS gradient data octave. */
  71. } VlSiftFilt ;
  72. /** @name Create and destroy
  73. ** @{
  74. **/
  75. VL_EXPORT
  76. VlSiftFilt* vl_sift_new (int width, int height,
  77. int noctaves, int nlevels,
  78. int o_min) ;
  79. VL_EXPORT
  80. void vl_sift_delete (VlSiftFilt *f) ;
  81. /** @} */
  82. /** @name Process data
  83. ** @{
  84. **/
  85. VL_EXPORT
  86. int vl_sift_process_first_octave (VlSiftFilt *f,
  87. vl_sift_pix const *im) ;
  88. VL_EXPORT
  89. int vl_sift_process_next_octave (VlSiftFilt *f) ;
  90. VL_EXPORT
  91. void vl_sift_detect (VlSiftFilt *f) ;
  92. VL_EXPORT
  93. int vl_sift_calc_keypoint_orientations (VlSiftFilt *f,
  94. double angles [4],
  95. VlSiftKeypoint const*k);
  96. VL_EXPORT
  97. void vl_sift_calc_keypoint_descriptor (VlSiftFilt *f,
  98. vl_sift_pix *descr,
  99. VlSiftKeypoint const* k,
  100. double angle) ;
  101. VL_EXPORT
  102. void vl_sift_calc_raw_descriptor (VlSiftFilt const *f,
  103. vl_sift_pix const* image,
  104. vl_sift_pix *descr,
  105. int widht, int height,
  106. double x, double y,
  107. double s, double angle0) ;
  108. VL_EXPORT
  109. void vl_sift_keypoint_init (VlSiftFilt const *f,
  110. VlSiftKeypoint *k,
  111. double x,
  112. double y,
  113. double sigma) ;
  114. /** @} */
  115. /** @name Retrieve data and parameters
  116. ** @{
  117. **/
  118. VL_INLINE int vl_sift_get_octave_index (VlSiftFilt const *f) ;
  119. VL_INLINE int vl_sift_get_noctaves (VlSiftFilt const *f) ;
  120. VL_INLINE int vl_sift_get_octave_first (VlSiftFilt const *f) ;
  121. VL_INLINE int vl_sift_get_octave_width (VlSiftFilt const *f) ;
  122. VL_INLINE int vl_sift_get_octave_height (VlSiftFilt const *f) ;
  123. VL_INLINE int vl_sift_get_nlevels (VlSiftFilt const *f) ;
  124. VL_INLINE int vl_sift_get_nkeypoints (VlSiftFilt const *f) ;
  125. VL_INLINE double vl_sift_get_peak_thresh (VlSiftFilt const *f) ;
  126. VL_INLINE double vl_sift_get_edge_thresh (VlSiftFilt const *f) ;
  127. VL_INLINE double vl_sift_get_norm_thresh (VlSiftFilt const *f) ;
  128. VL_INLINE double vl_sift_get_magnif (VlSiftFilt const *f) ;
  129. VL_INLINE double vl_sift_get_window_size (VlSiftFilt const *f) ;
  130. VL_INLINE vl_sift_pix *vl_sift_get_octave (VlSiftFilt const *f, int s) ;
  131. VL_INLINE VlSiftKeypoint const *vl_sift_get_keypoints (VlSiftFilt const *f) ;
  132. /** @} */
  133. /** @name Set parameters
  134. ** @{
  135. **/
  136. VL_INLINE void vl_sift_set_peak_thresh (VlSiftFilt *f, double t) ;
  137. VL_INLINE void vl_sift_set_edge_thresh (VlSiftFilt *f, double t) ;
  138. VL_INLINE void vl_sift_set_norm_thresh (VlSiftFilt *f, double t) ;
  139. VL_INLINE void vl_sift_set_magnif (VlSiftFilt *f, double m) ;
  140. VL_INLINE void vl_sift_set_window_size (VlSiftFilt *f, double m) ;
  141. /** @} */
  142. /* -------------------------------------------------------------------
  143. * Inline functions implementation
  144. * ---------------------------------------------------------------- */
  145. /** ------------------------------------------------------------------
  146. ** @brief Get current octave index.
  147. ** @param f SIFT filter.
  148. ** @return index of the current octave.
  149. **/
  150. VL_INLINE int
  151. vl_sift_get_octave_index (VlSiftFilt const *f)
  152. {
  153. return f-> o_cur ;
  154. }
  155. /** ------------------------------------------------------------------
  156. ** @brief Get number of octaves.
  157. ** @param f SIFT filter.
  158. ** @return number of octaves.
  159. **/
  160. VL_INLINE int
  161. vl_sift_get_noctaves (VlSiftFilt const *f)
  162. {
  163. return f-> O ;
  164. }
  165. /**-------------------------------------------------------------------
  166. ** @brief Get first octave.
  167. ** @param f SIFT filter.
  168. ** @return index of the first octave.
  169. **/
  170. VL_INLINE int
  171. vl_sift_get_octave_first (VlSiftFilt const *f)
  172. {
  173. return f-> o_min ;
  174. }
  175. /** ------------------------------------------------------------------
  176. ** @brief Get current octave width
  177. ** @param f SIFT filter.
  178. ** @return current octave width.
  179. **/
  180. VL_INLINE int
  181. vl_sift_get_octave_width (VlSiftFilt const *f)
  182. {
  183. return f-> octave_width ;
  184. }
  185. /** ------------------------------------------------------------------
  186. ** @brief Get current octave height
  187. ** @param f SIFT filter.
  188. ** @return current octave height.
  189. **/
  190. VL_INLINE int
  191. vl_sift_get_octave_height (VlSiftFilt const *f)
  192. {
  193. return f-> octave_height ;
  194. }
  195. /** ------------------------------------------------------------------
  196. ** @brief Get current octave data
  197. ** @param f SIFT filter.
  198. ** @param s level index.
  199. **
  200. ** The level index @a s ranges in the interval <tt>s_min = -1</tt>
  201. ** and <tt> s_max = S + 2</tt>, where @c S is the number of levels
  202. ** per octave.
  203. **
  204. ** @return pointer to the octave data for level @a s.
  205. **/
  206. VL_INLINE vl_sift_pix *
  207. vl_sift_get_octave (VlSiftFilt const *f, int s)
  208. {
  209. int w = vl_sift_get_octave_width (f) ;
  210. int h = vl_sift_get_octave_height (f) ;
  211. return f->octave + w * h * (s - f->s_min) ;
  212. }
  213. /** ------------------------------------------------------------------
  214. ** @brief Get number of levels per octave
  215. ** @param f SIFT filter.
  216. ** @return number of leves per octave.
  217. **/
  218. VL_INLINE int
  219. vl_sift_get_nlevels (VlSiftFilt const *f)
  220. {
  221. return f-> S ;
  222. }
  223. /** ------------------------------------------------------------------
  224. ** @brief Get number of keypoints.
  225. ** @param f SIFT filter.
  226. ** @return number of keypoints.
  227. **/
  228. VL_INLINE int
  229. vl_sift_get_nkeypoints (VlSiftFilt const *f)
  230. {
  231. return f-> nkeys ;
  232. }
  233. /** ------------------------------------------------------------------
  234. ** @brief Get keypoints.
  235. ** @param f SIFT filter.
  236. ** @return pointer to the keypoints list.
  237. **/
  238. VL_INLINE VlSiftKeypoint const *
  239. vl_sift_get_keypoints (VlSiftFilt const *f)
  240. {
  241. return f-> keys ;
  242. }
  243. /** ------------------------------------------------------------------
  244. ** @brief Get peaks treashold
  245. ** @param f SIFT filter.
  246. ** @return threshold ;
  247. **/
  248. VL_INLINE double
  249. vl_sift_get_peak_thresh (VlSiftFilt const *f)
  250. {
  251. return f -> peak_thresh ;
  252. }
  253. /** ------------------------------------------------------------------
  254. ** @brief Get edges threshold
  255. ** @param f SIFT filter.
  256. ** @return threshold.
  257. **/
  258. VL_INLINE double
  259. vl_sift_get_edge_thresh (VlSiftFilt const *f)
  260. {
  261. return f -> edge_thresh ;
  262. }
  263. /** ------------------------------------------------------------------
  264. ** @brief Get norm threshold
  265. ** @param f SIFT filter.
  266. ** @return threshold.
  267. **/
  268. VL_INLINE double
  269. vl_sift_get_norm_thresh (VlSiftFilt const *f)
  270. {
  271. return f -> norm_thresh ;
  272. }
  273. /** ------------------------------------------------------------------
  274. ** @brief Get the magnification factor
  275. ** @param f SIFT filter.
  276. ** @return magnification factor.
  277. **/
  278. VL_INLINE double
  279. vl_sift_get_magnif (VlSiftFilt const *f)
  280. {
  281. return f -> magnif ;
  282. }
  283. /** ------------------------------------------------------------------
  284. ** @brief Get the Gaussian window size.
  285. ** @param f SIFT filter.
  286. ** @return standard deviation of the Gaussian window (in spatial bin units).
  287. **/
  288. VL_INLINE double
  289. vl_sift_get_window_size (VlSiftFilt const *f)
  290. {
  291. return f -> windowSize ;
  292. }
  293. /** ------------------------------------------------------------------
  294. ** @brief Set peaks threshold
  295. ** @param f SIFT filter.
  296. ** @param t threshold.
  297. **/
  298. VL_INLINE void
  299. vl_sift_set_peak_thresh (VlSiftFilt *f, double t)
  300. {
  301. f -> peak_thresh = t ;
  302. }
  303. /** ------------------------------------------------------------------
  304. ** @brief Set edges threshold
  305. ** @param f SIFT filter.
  306. ** @param t threshold.
  307. **/
  308. VL_INLINE void
  309. vl_sift_set_edge_thresh (VlSiftFilt *f, double t)
  310. {
  311. f -> edge_thresh = t ;
  312. }
  313. /** ------------------------------------------------------------------
  314. ** @brief Set norm threshold
  315. ** @param f SIFT filter.
  316. ** @param t threshold.
  317. **/
  318. VL_INLINE void
  319. vl_sift_set_norm_thresh (VlSiftFilt *f, double t)
  320. {
  321. f -> norm_thresh = t ;
  322. }
  323. /** ------------------------------------------------------------------
  324. ** @brief Set the magnification factor
  325. ** @param f SIFT filter.
  326. ** @param m magnification factor.
  327. **/
  328. VL_INLINE void
  329. vl_sift_set_magnif (VlSiftFilt *f, double m)
  330. {
  331. f -> magnif = m ;
  332. }
  333. /** ------------------------------------------------------------------
  334. ** @brief Set the Gaussian window size
  335. ** @param f SIFT filter.
  336. ** @param x Gaussian window size (in units of spatial bin).
  337. **
  338. ** This is the parameter @f$ \hat \sigma_{\text{win}} @f$ of
  339. ** the standard SIFT descriptor @ref sift-tech-descriptor-std.
  340. **/
  341. VL_INLINE void
  342. vl_sift_set_window_size (VlSiftFilt *f, double x)
  343. {
  344. f -> windowSize = x ;
  345. }
  346. /* VL_SIFT_H */
  347. #endif