sift.c File Reference
Detailed Description
For internal use only.
Definition in file sift.c.
#include "sift.h"
#include "imop.h"
#include "mathop.h"
Go to the source code of this file.
Functions | |
VL_INLINE double | fast_expn (double x) |
Fast ![]() | |
VL_INLINE void | fast_expn_init () |
Initialize tables for fast_expn. | |
static void | copy_and_upsample_rows (vl_sift_pix *dst, vl_sift_pix const *src, int width, int height) |
Copy image, upsample rows and take transpose. | |
static void | copy_and_downsample (vl_sift_pix *dst, vl_sift_pix const *src, int width, int height, int d) |
Copy and downsample an image. | |
VL_EXPORT VlSiftFilt * | vl_sift_new (int width, int height, int noctaves, int nlevels, int o_min) |
Create a new SIFT filter. | |
VL_EXPORT void | vl_sift_delete (VlSiftFilt *f) |
Delete SIFT filter. | |
VL_EXPORT int | vl_sift_process_first_octave (VlSiftFilt *f, vl_sift_pix const *im) |
Start processing a new image. | |
VL_EXPORT int | vl_sift_process_next_octave (VlSiftFilt *f) |
Process next octave. | |
VL_EXPORT void | vl_sift_detect (VlSiftFilt *f) |
Detect keypoints. | |
static void | update_gradient (VlSiftFilt *f) |
Update gradients to current GSS octave. | |
VL_EXPORT int | vl_sift_calc_keypoint_orientations (VlSiftFilt *f, double angles[4], VlSiftKeypoint const *k) |
Calculate the keypoint orientation(s). | |
VL_INLINE vl_sift_pix | normalize_histogram (vl_sift_pix *begin, vl_sift_pix *end) |
Normalizes in norm L_2 a descriptor. | |
VL_EXPORT void | vl_sift_calc_raw_descriptor (VlSiftFilt const *f, vl_sift_pix const *grad, vl_sift_pix *descr, int width, int height, double x, double y, double sigma, double angle0) |
Run the SIFT descriptor on raw data. | |
VL_EXPORT void | vl_sift_calc_keypoint_descriptor (VlSiftFilt *f, vl_sift_pix *descr, VlSiftKeypoint const *k, double angle0) |
Compute the descriptor of a keypoint. | |
VL_EXPORT void | vl_sift_keypoint_init (VlSiftFilt const *f, VlSiftKeypoint *k, double x, double y, double sigma) |
Initialize a keypoint from its position and scale. | |
Variables | |
double | expn_tab [EXPN_SZ+1] |
Function Documentation
static void copy_and_downsample | ( | vl_sift_pix * | dst, | |
vl_sift_pix const * | src, | |||
int | width, | |||
int | height, | |||
int | d | |||
) | [static] |
For internal use only.
- Parameters:
-
dst output imgae buffer. src input image buffer. width input image width. height input image height. d octaves (non negative).
1/2^d
of its original size. The parameters width and height are the size of the input image. The destination image dst is assumed to be floor(width/2^d)
pixels wide and floor(height/2^d)
pixels high.
Definition at line 795 of file sift.c.
Referenced by vl_sift_process_first_octave(), and vl_sift_process_next_octave().
static void copy_and_upsample_rows | ( | vl_sift_pix * | dst, | |
vl_sift_pix const * | src, | |||
int | width, | |||
int | height | |||
) | [static] |
For internal use only.
- Parameters:
-
dst output image buffer. src input image buffer. width input image width. height input image height.
Upsampling is performed by linear interpolation.
Definition at line 756 of file sift.c.
Referenced by vl_sift_process_first_octave().
VL_INLINE double fast_expn | ( | double | x | ) |
For internal use only.
- Parameters:
-
x argument.
- Returns:
- approximation of
.
Definition at line 708 of file sift.c.
References expn_tab, and vl_floor_d().
Referenced by vl_sift_calc_keypoint_descriptor(), vl_sift_calc_keypoint_orientations(), and vl_sift_calc_raw_descriptor().
VL_INLINE void fast_expn_init | ( | ) |
For internal use only.
Definition at line 730 of file sift.c.
References expn_tab.
Referenced by vl_sift_new().
VL_INLINE vl_sift_pix normalize_histogram | ( | vl_sift_pix * | begin, | |
vl_sift_pix * | end | |||
) |
For internal use only.
- Parameters:
-
begin begin of histogram. end end of histogram.
Definition at line 1662 of file sift.c.
References VL_EPSILON_F, and vl_fast_sqrt_f().
Referenced by vl_sift_calc_keypoint_descriptor(), and vl_sift_calc_raw_descriptor().
static void update_gradient | ( | VlSiftFilt * | f | ) | [static] |
For internal use only.
- Parameters:
-
f SIFT filter.
- Remarks:
- The minimum octave size is 2x2xS.
Definition at line 1405 of file sift.c.
References _VlSiftFilt::grad, _VlSiftFilt::grad_o, _VlSiftFilt::o_cur, _VlSiftFilt::s_max, _VlSiftFilt::s_min, vl_sift_get_octave(), vl_sift_get_octave_height(), and vl_sift_get_octave_width().
Referenced by vl_sift_calc_keypoint_descriptor(), and vl_sift_calc_keypoint_orientations().
VL_EXPORT void vl_sift_calc_keypoint_descriptor | ( | VlSiftFilt * | f, | |
vl_sift_pix * | descr, | |||
VlSiftKeypoint const * | k, | |||
double | angle0 | |||
) |
- Parameters:
-
f SIFT filter. descr SIFT descriptor (output) k keypoint. angle0 keypoint direction.
The function assumes that the keypoint is on the current octave. If not, it does not do anything.
Definition at line 1881 of file sift.c.
References fast_expn(), _VlSiftFilt::grad, normalize_histogram(), _VlSiftKeypoint::o, _VlSiftFilt::o_cur, _VlSiftFilt::s_max, _VlSiftFilt::s_min, update_gradient(), vl_abs_f(), vl_floor_f(), VL_MAX, VL_MIN, vl_mod_2pi_f(), VL_PI, and _VlSiftFilt::windowSize.
VL_EXPORT int vl_sift_calc_keypoint_orientations | ( | VlSiftFilt * | f, | |
double | angles[4], | |||
VlSiftKeypoint const * | k | |||
) |
- Parameters:
-
f SIFT filter. angles orientations (output). k keypoint.
- Remarks:
- The function requires the keypoint octave k->o to be equal to the filter current octave vl_sift_get_octave. If this is not the case, the function returns zero orientations.
The function requires the keypoint scale level
k->s
to be in the ranges_min+1
ands_max-2
(where usuallys_min=0
ands_max=S+2
). If this is not the case, the function returns zero orientations.
- Returns:
- number of orientations found.
Definition at line 1517 of file sift.c.
References fast_expn(), _VlSiftKeypoint::o, _VlSiftFilt::o_cur, _VlSiftFilt::s_max, _VlSiftFilt::s_min, update_gradient(), vl_floor_d(), VL_MAX, VL_MIN, and VL_PI.
VL_EXPORT void vl_sift_calc_raw_descriptor | ( | VlSiftFilt const * | f, | |
vl_sift_pix const * | grad, | |||
vl_sift_pix * | descr, | |||
int | width, | |||
int | height, | |||
double | x, | |||
double | y, | |||
double | sigma, | |||
double | angle0 | |||
) |
- Parameters:
-
f SIFT filter. grad image gradients. descr SIFT descriptor (output). width image width. height image height. x keypoint x coordinate. y keypoint y coordinate. sigma keypoint scale. angle0 keypoint orientation.

In order to be equivalent to a standard SIFT descriptor the image gradient must be computed at a smoothing level equal to the scale of the keypoint. In practice, the actual SIFT algorithm makes the following additional approximation, which influence the result:
- Scale is discretized in
S
levels. - The image is downsampled once for each octave (if you do this, the parameters x, y and sigma must be scaled too).
Definition at line 1712 of file sift.c.
References fast_expn(), normalize_histogram(), vl_abs_f(), VL_EPSILON_D, vl_floor_f(), VL_MAX, VL_MIN, vl_mod_2pi_f(), VL_PI, and _VlSiftFilt::windowSize.
VL_EXPORT void vl_sift_delete | ( | VlSiftFilt * | f | ) |
- Parameters:
-
f SIFT filter to delete.
Definition at line 905 of file sift.c.
References vl_free().
VL_EXPORT void vl_sift_detect | ( | VlSiftFilt * | f | ) |
The function detect keypoints in the current octave filling the internal keypoint buffer. Keypoints can be retrieved by vl_sift_get_keypoints().
- Parameters:
-
f SIFT filter.
Index GSS
For internal use only.
Index matrix A
Definition at line 1111 of file sift.c.
References _VlSiftFilt::keys, _VlSiftFilt::keys_res, _VlSiftFilt::nkeys, _VlSiftFilt::o_cur, _VlSiftFilt::S, _VlSiftFilt::sigma0, vl_abs_d(), vl_malloc(), vl_realloc(), and vl_sift_get_octave().
VL_EXPORT void vl_sift_keypoint_init | ( | VlSiftFilt const * | f, | |
VlSiftKeypoint * | k, | |||
double | x, | |||
double | y, | |||
double | sigma | |||
) |
- Parameters:
-
f SIFT filter. k SIFT keypoint (output). x x coordinate of the center. y y coordinate of the center. sigma scale.
Definition at line 2068 of file sift.c.
References _VlSiftFilt::O, _VlSiftFilt::o_min, _VlSiftFilt::S, _VlSiftFilt::s_max, _VlSiftFilt::s_min, _VlSiftKeypoint::sigma, _VlSiftFilt::sigma0, vl_floor_d(), VL_MAX, and VL_MIN.
VL_EXPORT VlSiftFilt* vl_sift_new | ( | int | width, | |
int | height, | |||
int | noctaves, | |||
int | nlevels, | |||
int | o_min | |||
) |
- Parameters:
-
width image width. height image height. noctaves number of octaves. nlevels number of levels per octave. o_min first octave index.
Setting O to a negative value sets the number of octaves to the maximum possible value depending on the size of the image.
- Returns:
- the new SIFT filter.
- See also:
- vl_sift_delete().
Definition at line 832 of file sift.c.
References fast_expn_init(), _VlSiftFilt::s_max, _VlSiftFilt::s_min, _VlSiftFilt::sigma0, _VlSiftFilt::sigmak, vl_malloc(), VL_MAX, VL_MIN, and VL_SHIFT_LEFT.
VL_EXPORT int vl_sift_process_first_octave | ( | VlSiftFilt * | f, | |
vl_sift_pix const * | im | |||
) |
- Parameters:
-
f SIFT filter. im image data.
- Returns:
- error code. The function returns VL_ERR_EOF if there are no more octaves to process.
- See also:
- vl_sift_process_next_octave().
Definition at line 935 of file sift.c.
References copy_and_downsample(), copy_and_upsample_rows(), _VlSiftFilt::height, _VlSiftFilt::nkeys, _VlSiftFilt::O, _VlSiftFilt::o_cur, VL_ERR_EOF, VL_ERR_OK, vl_imsmooth_f(), VL_SHIFT_LEFT, vl_sift_get_octave(), and _VlSiftFilt::width.
VL_EXPORT int vl_sift_process_next_octave | ( | VlSiftFilt * | f | ) |
- Parameters:
-
f SIFT filter.
- Returns:
- error code. The function returns the error VL_ERR_EOF when there are no more octaves to process.
- See also:
- vl_sift_process_first_octave().
Definition at line 1041 of file sift.c.
References copy_and_downsample(), _VlSiftFilt::height, _VlSiftFilt::o_cur, VL_ERR_EOF, VL_ERR_OK, vl_imsmooth_f(), VL_MIN, VL_SHIFT_LEFT, vl_sift_get_octave(), vl_sift_get_octave_height(), vl_sift_get_octave_width(), and _VlSiftFilt::width.
Variable Documentation
double expn_tab[EXPN_SZ+1] |
fast_expn table
For internal use only.
Definition at line 689 of file sift.c.
Referenced by fast_expn(), and fast_expn_init().