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