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.

353 lines
11 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /** @file dsift.h
  2. ** @brief Dense SIFT (@ref dsift)
  3. ** @author Andrea Vedaldi
  4. ** @author Brian Fulkerson
  5. **/
  6. /*
  7. Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson.
  8. All rights reserved.
  9. This file is part of the VLFeat library and is made available under
  10. the terms of the BSD license (see the COPYING file).
  11. */
  12. #ifndef VL_DSIFT_H
  13. #define VL_DSIFT_H
  14. #include "generic.h"
  15. /** @brief Dense SIFT keypoint */
  16. typedef struct VlDsiftKeypoint_{
  17. float x ; /**< x coordinate */
  18. float y ; /**< y coordinate */
  19. float s ; /**< scale */
  20. float norm ; /**< SIFT descriptor norm */
  21. } VlDsiftKeypoint ;
  22. /** @brief Dense SIFT descriptor geometry */
  23. typedef struct VlDsiftDescriptorGeometry_
  24. {
  25. int numBinT ; /**< number of orientation bins */
  26. int numBinX ; /**< number of bins along X */
  27. int numBinY ; /**< number of bins along Y */
  28. int binSizeX ; /**< size of bins along X */
  29. int binSizeY ; /**< size of bins along Y */
  30. } VlDsiftDescriptorGeometry ;
  31. /** @brief Dense SIFT filter */
  32. typedef struct VlDsiftFilter_
  33. {
  34. int imWidth ; /**< @internal @brief image width */
  35. int imHeight ; /**< @internal @brief image height */
  36. int stepX ; /**< frame sampling step X */
  37. int stepY ; /**< frame sampling step Y */
  38. int boundMinX ; /**< frame bounding box min X */
  39. int boundMinY ; /**< frame bounding box min Y */
  40. int boundMaxX ; /**< frame bounding box max X */
  41. int boundMaxY ; /**< frame bounding box max Y */
  42. /** descriptor parameters */
  43. VlDsiftDescriptorGeometry geom ;
  44. int useFlatWindow ; /**< flag: whether to approximate the Gaussian window with a flat one */
  45. double windowSize ; /**< size of the Gaussian window */
  46. int numFrames ; /**< number of sampled frames */
  47. int descrSize ; /**< size of a descriptor */
  48. VlDsiftKeypoint *frames ; /**< frame buffer */
  49. float *descrs ; /**< descriptor buffer */
  50. int numBinAlloc ; /**< buffer allocated: descriptor size */
  51. int numFrameAlloc ; /**< buffer allocated: number of frames */
  52. int numGradAlloc ; /**< buffer allocated: number of orientations */
  53. float **grads ; /**< gradient buffer */
  54. float *convTmp1 ; /**< temporary buffer */
  55. float *convTmp2 ; /**< temporary buffer */
  56. } VlDsiftFilter ;
  57. VL_EXPORT VlDsiftFilter *vl_dsift_new (int width, int height) ;
  58. VL_EXPORT VlDsiftFilter *vl_dsift_new_basic (int width, int height, int step, int binSize) ;
  59. VL_EXPORT void vl_dsift_delete (VlDsiftFilter *self) ;
  60. VL_EXPORT void vl_dsift_process (VlDsiftFilter *self, float const* im) ;
  61. VL_INLINE void vl_dsift_transpose_descriptor (float* dst,
  62. float const* src,
  63. int numBinT,
  64. int numBinX,
  65. int numBinY) ;
  66. /** @name Setting parameters
  67. ** @{
  68. **/
  69. VL_INLINE void vl_dsift_set_steps (VlDsiftFilter *self,
  70. int stepX,
  71. int stepY) ;
  72. VL_INLINE void vl_dsift_set_bounds (VlDsiftFilter *self,
  73. int minX,
  74. int minY,
  75. int maxX,
  76. int maxY) ;
  77. VL_INLINE void vl_dsift_set_geometry (VlDsiftFilter *self,
  78. VlDsiftDescriptorGeometry const* geom) ;
  79. VL_INLINE void vl_dsift_set_flat_window (VlDsiftFilter *self, vl_bool useFlatWindow) ;
  80. VL_INLINE void vl_dsift_set_window_size (VlDsiftFilter *self, double windowSize) ;
  81. /** @} */
  82. /** @name Retrieving data and parameters
  83. ** @{
  84. **/
  85. VL_INLINE float const *vl_dsift_get_descriptors (VlDsiftFilter const *self) ;
  86. VL_INLINE int vl_dsift_get_descriptor_size (VlDsiftFilter const *self) ;
  87. VL_INLINE int vl_dsift_get_keypoint_num (VlDsiftFilter const *self) ;
  88. VL_INLINE VlDsiftKeypoint const *vl_dsift_get_keypoints (VlDsiftFilter const *self) ;
  89. VL_INLINE void vl_dsift_get_bounds (VlDsiftFilter const *self,
  90. int* minX,
  91. int* minY,
  92. int* maxX,
  93. int* maxY) ;
  94. VL_INLINE void vl_dsift_get_steps (VlDsiftFilter const* self,
  95. int* stepX,
  96. int* stepY) ;
  97. VL_INLINE VlDsiftDescriptorGeometry const* vl_dsift_get_geometry (VlDsiftFilter const *self) ;
  98. VL_INLINE vl_bool vl_dsift_get_flat_window (VlDsiftFilter const *self) ;
  99. VL_INLINE double vl_dsift_get_window_size (VlDsiftFilter const *self) ;
  100. /** @} */
  101. VL_EXPORT
  102. void _vl_dsift_update_buffers (VlDsiftFilter *self) ;
  103. /** ------------------------------------------------------------------
  104. ** @brief Get descriptor size.
  105. ** @param self DSIFT filter object.
  106. ** @return size of a descriptor.
  107. **/
  108. int
  109. vl_dsift_get_descriptor_size (VlDsiftFilter const *self)
  110. {
  111. return self->descrSize ;
  112. }
  113. /** ------------------------------------------------------------------
  114. ** @brief Get descriptors.
  115. ** @param self DSIFT filter object.
  116. ** @return descriptors.
  117. **/
  118. float const *
  119. vl_dsift_get_descriptors (VlDsiftFilter const *self)
  120. {
  121. return self->descrs ;
  122. }
  123. /** ------------------------------------------------------------------
  124. ** @brief Get keypoints
  125. ** @param self DSIFT filter object.
  126. **/
  127. VlDsiftKeypoint const *
  128. vl_dsift_get_keypoints (VlDsiftFilter const *self)
  129. {
  130. return self->frames ;
  131. }
  132. /** ------------------------------------------------------------------
  133. ** @brief Get number of keypoints
  134. ** @param self DSIFT filter object.
  135. **/
  136. int
  137. vl_dsift_get_keypoint_num (VlDsiftFilter const *self)
  138. {
  139. return self->numFrames ;
  140. }
  141. /** ------------------------------------------------------------------
  142. ** @brief Get SIFT descriptor geometry
  143. ** @param self DSIFT filter object.
  144. ** @return DSIFT descriptor geometry.
  145. **/
  146. VlDsiftDescriptorGeometry const* vl_dsift_get_geometry (VlDsiftFilter const *self)
  147. {
  148. return &self->geom ;
  149. }
  150. /** ------------------------------------------------------------------
  151. ** @brief Get bounds
  152. ** @param self DSIFT filter object.
  153. ** @param minX bounding box minimum X coordinate.
  154. ** @param minY bounding box minimum Y coordinate.
  155. ** @param maxX bounding box maximum X coordinate.
  156. ** @param maxY bounding box maximum Y coordinate.
  157. **/
  158. void
  159. vl_dsift_get_bounds (VlDsiftFilter const* self,
  160. int *minX, int *minY, int *maxX, int *maxY)
  161. {
  162. *minX = self->boundMinX ;
  163. *minY = self->boundMinY ;
  164. *maxX = self->boundMaxX ;
  165. *maxY = self->boundMaxY ;
  166. }
  167. /** ------------------------------------------------------------------
  168. ** @brief Get flat window flag
  169. ** @param self DSIFT filter object.
  170. ** @return @c TRUE if the DSIFT filter uses a flat window.
  171. **/
  172. int
  173. vl_dsift_get_flat_window (VlDsiftFilter const* self)
  174. {
  175. return self->useFlatWindow ;
  176. }
  177. /** ------------------------------------------------------------------
  178. ** @brief Get steps
  179. ** @param self DSIFT filter object.
  180. ** @param stepX sampling step along X.
  181. ** @param stepY sampling step along Y.
  182. **/
  183. void
  184. vl_dsift_get_steps (VlDsiftFilter const* self,
  185. int* stepX,
  186. int* stepY)
  187. {
  188. *stepX = self->stepX ;
  189. *stepY = self->stepY ;
  190. }
  191. /** ------------------------------------------------------------------
  192. ** @brief Set steps
  193. ** @param self DSIFT filter object.
  194. ** @param stepX sampling step along X.
  195. ** @param stepY sampling step along Y.
  196. **/
  197. void
  198. vl_dsift_set_steps (VlDsiftFilter* self,
  199. int stepX,
  200. int stepY)
  201. {
  202. self->stepX = stepX ;
  203. self->stepY = stepY ;
  204. _vl_dsift_update_buffers(self) ;
  205. }
  206. /** ------------------------------------------------------------------
  207. ** @brief Set bounds
  208. ** @param self DSIFT filter object.
  209. ** @param minX bounding box minimum X coordinate.
  210. ** @param minY bounding box minimum Y coordinate.
  211. ** @param maxX bounding box maximum X coordinate.
  212. ** @param maxY bounding box maximum Y coordinate.
  213. **/
  214. void
  215. vl_dsift_set_bounds (VlDsiftFilter* self,
  216. int minX, int minY, int maxX, int maxY)
  217. {
  218. self->boundMinX = minX ;
  219. self->boundMinY = minY ;
  220. self->boundMaxX = maxX ;
  221. self->boundMaxY = maxY ;
  222. _vl_dsift_update_buffers(self) ;
  223. }
  224. /** ------------------------------------------------------------------
  225. ** @brief Set SIFT descriptor geometry
  226. ** @param self DSIFT filter object.
  227. ** @param geom descriptor geometry parameters.
  228. **/
  229. void
  230. vl_dsift_set_geometry (VlDsiftFilter *self,
  231. VlDsiftDescriptorGeometry const *geom)
  232. {
  233. self->geom = *geom ;
  234. _vl_dsift_update_buffers(self) ;
  235. }
  236. /** ------------------------------------------------------------------
  237. ** @brief Set flat window flag
  238. ** @param self DSIFT filter object.
  239. ** @param useFlatWindow @c true if the DSIFT filter should use a flat window.
  240. **/
  241. void
  242. vl_dsift_set_flat_window (VlDsiftFilter* self,
  243. vl_bool useFlatWindow)
  244. {
  245. self->useFlatWindow = useFlatWindow ;
  246. }
  247. /** ------------------------------------------------------------------
  248. ** @brief Transpose descriptor
  249. **
  250. ** @param dst destination buffer.
  251. ** @param src source buffer.
  252. ** @param numBinT
  253. ** @param numBinX
  254. ** @param numBinY
  255. **
  256. ** The function writes to @a dst the transpose of the SIFT descriptor
  257. ** @a src. Let <code>I</code> be an image. The transpose operator
  258. ** satisfies the equation <code>transpose(dsift(I,x,y)) =
  259. ** dsift(transpose(I),y,x)</code>
  260. **/
  261. VL_INLINE void
  262. vl_dsift_transpose_descriptor (float* dst,
  263. float const* src,
  264. int numBinT,
  265. int numBinX,
  266. int numBinY)
  267. {
  268. int t, x, y ;
  269. for (y = 0 ; y < numBinY ; ++y) {
  270. for (x = 0 ; x < numBinX ; ++x) {
  271. int offset = numBinT * (x + y * numBinX) ;
  272. int offsetT = numBinT * (y + x * numBinY) ;
  273. for (t = 0 ; t < numBinT ; ++t) {
  274. int tT = numBinT / 4 - t ;
  275. dst [offsetT + (tT + numBinT) % numBinT] = src [offset + t] ;
  276. }
  277. }
  278. }
  279. }
  280. /** ------------------------------------------------------------------
  281. ** @brief Set SIFT descriptor Gaussian window size
  282. ** @param self DSIFT filter object.
  283. ** @param windowSize window size.
  284. **/
  285. void
  286. vl_dsift_set_window_size(VlDsiftFilter * self, double windowSize)
  287. {
  288. assert(windowSize >= 0.0) ;
  289. self->windowSize = windowSize ;
  290. }
  291. /** ------------------------------------------------------------------
  292. ** @brief Get SIFT descriptor Gaussian window size
  293. ** @param self DSIFT filter object.
  294. ** @return window size.
  295. **/
  296. VL_INLINE double
  297. vl_dsift_get_window_size(VlDsiftFilter const * self)
  298. {
  299. return self->windowSize ;
  300. }
  301. /* VL_DSIFT_H */
  302. #endif