ETRI IVCL 1.0.0
Acceleration SW Platform for Ondevice
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Macros | Functions | Variables
SIFT.cpp File Reference
#include <iostream>
#include <algorithm>
#include "SIFT.hpp"
#include "__SIFT.hpp"
#include "MathU.h"

Macros

#define R_PORT   0.2126f
 
#define G_PORT   0.7152f
 
#define B_PORT   0.0722f
 
#define MY_GAUSS   true
 
#define MY_RESIZE   true
 

Functions

void start_time (system_clock::time_point &startTime)
 
void end_time (system_clock::time_point &startTime, system_clock::time_point &endTime, const char *step_name)
 
void extractSiftFeatures (const Mat &img, vector< KeyPoint > &keypoints, Mat &descriptor, int intervals, double sigma, double contrast_thres, int curvature_thres, bool img_dbl, int descr_width, int descr_hist_bins)
 
void convertGrayAndNormalize (const Mat &input, Mat &output)
 
void __feats2KeyPoints (const vector< Feature > &feats, vector< KeyPoint > &keypoints)
 
void __featsVec2Mat (const vector< Feature > &feats, Mat &mat)
 
void filterCreation (double **GKernel, int kSize, double sigma)
 
void filterCreation1D (float *GKernel, int kSize, double sigma)
 
void gaussianBlur (const Mat &src, Mat &output, int kSize, double **kernel)
 
void resizeHalf (const Mat &input, Mat &output, Size outSize)
 
Mat __createInitImg (const Mat &img, bool img_dbl, double sigma)
 
void __buildGaussPyramid (const Mat &base, vector< Mat > &gaussian_pyramid, int octaves, int intervals, double sigma)
 
void __buildDogPyramid (const vector< Mat > &gaussian_pyramid, vector< Mat > &dog_pyramid, int octaves, int intervals)
 
void __scaleSpaceExtrema (const vector< Mat > &dog_pyramid, vector< Feature > &feats, int octaves, int intervals, double contrast_thres, int curvature_thres)
 
bool __isExtremum (const vector< Mat > &dog_pyramid, int idx, int r, int c)
 
bool __interpExtremum (const vector< Mat > &dog_pyramid, Feature &feat, int idx, int r, int c, int intervals, double contrast_thres)
 
void __interpStep (const vector< Mat > &dog_pyramid, int idx, int r, int c, double &xi, double &xr, double &xc)
 
void _derivative ()
 
Mat __derivative (const vector< Mat > &dog_pyramid, int idx, int r, int c)
 
Mat __hessian (const vector< Mat > &dog_pyramid, int idx, int r, int c)
 
double __interpContrast (const vector< Mat > &dog_pyramid, int idx, int r, int c, double xi, double xr, double xc)
 
bool __isTooEdgeLike (const Mat &dog, int r, int c, int curvature_thres)
 
void __calcFeatureScales (vector< Feature > &feats, double sigma, int intervals)
 
void __adjustForImgDbl (vector< Feature > &feats)
 
void __calcFeatureOris (vector< Feature > &feats, const vector< Mat > &gaussian_pyramid, int layer_per_octave)
 
void __oriHist (const Mat &gaussian, vector< double > &hist, int r, int c, int rad, double sigma)
 
bool __calcGradMagOri (const Mat &gaussian, int r, int c, double &mag, double &ori)
 
void __smoothOriHist (vector< double > &hist)
 
void __addGoodOriFeatures (queue< Feature > &feat_queue, const vector< double > &hist, double mag_thres, const Feature &feat)
 
void __computeDescriptors (vector< Feature > &feats, const vector< Mat > &gaussian_pyramid, int layer_per_octave, int d, int n)
 
void __descriptorHist (const Mat &gaussian, vector< double > &hist, int r, int c, double ori, double scl, int d, int n)
 
void __interpHistEntry (vector< double > &hist, double rbin, double cbin, double obin, double mag, int d, int n)
 
void __hist2Descriptor (const vector< double > &hist, Feature &feat, int d, int n)
 
void __normalizeDescriptor (vector< double > &descriptor)
 

Variables

double ** gKernel
 
int kSize = 9
 
volatile int p_cnt = 0
 

Macro Definition Documentation

◆ B_PORT

#define B_PORT   0.0722f

◆ G_PORT

#define G_PORT   0.7152f

◆ MY_GAUSS

#define MY_GAUSS   true

◆ MY_RESIZE

#define MY_RESIZE   true

◆ R_PORT

#define R_PORT   0.2126f

Function Documentation

◆ __addGoodOriFeatures()

void __addGoodOriFeatures ( queue< Feature > &  feat_queue,
const vector< double > &  hist,
double  mag_thres,
const Feature feat 
)

[add features with orientation greater than mag_thres]

Parameters
feat_queue[queue for features]
hist[orientation histogram]
mag_thres[magnitude threshold]
feat[template feat]

◆ __adjustForImgDbl()

void __adjustForImgDbl ( vector< Feature > &  feats)

[Halves feature coordinates and scale]

Parameters
feats[feature vector]

◆ __buildDogPyramid()

void __buildDogPyramid ( const vector< Mat > &  gaussian_pyramid,
vector< Mat > &  dog_pyramid,
int  octaves,
int  intervals 
)

[Build Difference of Gaussian Pyramid]

Parameters
gaussian_pyramid[gaussian pyramid]
dog_pyramid[returned dog pyramid, size : octaves x (intervals + 2)]
octaves[number of octaves]
intervals[number of intervals per octave]

◆ __buildGaussPyramid()

void __buildGaussPyramid ( const Mat &  base,
vector< Mat > &  gaussian_pyramid,
int  octaves,
int  intervals,
double  sigma 
)

[Build Gaussian pyramid]

Parameters
base[base image for the pyramid]
gaussian_pyramid[returned gaussian pyramid, size : octaves x (intervals + 3)]
octaves[number of octaves]
intervals[number of intervals per octave]
sigma[sigma for gaussian smoothing]

◆ __calcFeatureOris()

void __calcFeatureOris ( vector< Feature > &  feats,
const vector< Mat > &  gaussian_pyramid,
int  layer_per_octave 
)

[Computes a canonical orientation for each image feature]

Parameters
feats[feature vector]
gaussian_pyramid[gaussian pyramid]
layer_per_octave[number of layers per octave]

◆ __calcFeatureScales()

void __calcFeatureScales ( vector< Feature > &  feats,
double  sigma,
int  intervals 
)

[Calculates characteristic scale]

Parameters
feats[feature vector]
sigma[sigma for Gaussian smoothing]
intervals[intervals per octave]

◆ __calcGradMagOri()

bool __calcGradMagOri ( const Mat &  gaussian,
int  r,
int  c,
double &  mag,
double &  ori 
)

[Calculates the gradient magnitude and orientation]

Parameters
gaussian[Gaussian image]
r[row]
c[col]
mag[returned gradient magnitude]
ori[returned gradient orientation]
Returns
[valid pixel]

◆ __computeDescriptors()

void __computeDescriptors ( vector< Feature > &  feats,
const vector< Mat > &  gaussian_pyramid,
int  layer_per_octave,
int  d,
int  n 
)

[Computes feature descriptors]

Parameters
feats[feature vector]
gaussian_pyramid[Gaussian pyramid]
layer_per_octave[number of layers per octave in Gaussian pyramid]
d[width of 2d hist]
n[number of bins for descriptor]

◆ __createInitImg()

Mat __createInitImg ( const Mat &  img,
bool  img_dbl,
double  sigma 
)

[Create the initial image for builing gaussian pyramid, optionally double the image size before smoothing]

Parameters
img[input image]
img_dbl[double size before smoothing?]
sigma[sigma for gaussian smoothing]
Returns
[image returned]

◆ __derivative()

Mat __derivative ( const vector< Mat > &  dog_pyramid,
int  idx,
int  r,
int  c 
)

[partial derivatives in x, y, interval]

Parameters
dog_pyramid[Dog pyramid]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
Returns
[partial derivatives]

◆ __descriptorHist()

void __descriptorHist ( const Mat &  gaussian,
vector< double > &  hist,
int  r,
int  c,
double  ori,
double  scl,
int  d,
int  n 
)

[Computes the 2D array of orientation histograms]

Parameters
gaussian[gaussian image]
hist[returned dxdxn hist vector]
r[row]
c[col]
ori[orientation]
scl[scl scale relative to image]
d[width of 2d hist]
n[number of bins for descriptor]

◆ __feats2KeyPoints()

void __feats2KeyPoints ( const vector< Feature > &  feats,
vector< KeyPoint > &  keypoints 
)

[convert features to keypoints]

Parameters
feats[features in vector]
keypoints[returned keypoint vector]

◆ __featsVec2Mat()

void __featsVec2Mat ( const vector< Feature > &  feats,
Mat &  mat 
)

[convert features from vector to Mat]

Parameters
feats[features in vector]
mat[returned Mat]

◆ __hessian()

Mat __hessian ( const vector< Mat > &  dog_pyramid,
int  idx,
int  r,
int  c 
)

[3D Hessian matrix in x, y, interval]

Parameters
dog_pyramid[Dog pyramid]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
Returns
[3D Hessian matrix]

◆ __hist2Descriptor()

void __hist2Descriptor ( const vector< double > &  hist,
Feature feat,
int  d,
int  n 
)

[converts 2d hist into 1d descriptor]

Parameters
hist[2d histogram]
feat[feature point]
d[width of 2d hist]
n[number of bins for descriptor]

◆ __interpContrast()

double __interpContrast ( const vector< Mat > &  dog_pyramid,
int  idx,
int  r,
int  c,
double  xi,
double  xr,
double  xc 
)

[Calculates interpolated pixel contrast]

Parameters
dog_pyramid[Dog pyramid]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
xi[interpolated subpixel increment to interval]
xr[interpolated subpixel increment to row]
xc[interpolated subpixel increment to col]
Returns
[interpolated contrast]

◆ __interpExtremum()

bool __interpExtremum ( const vector< Mat > &  dog_pyramid,
Feature feat,
int  idx,
int  r,
int  c,
int  intervals,
double  contrast_thres 
)

[Interpolates a scale-space extremum's location]

Parameters
dog_pyramid[Dog pyramid]
feat[returned feature]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
intervals[number of intervals per octave]
contrast_thres[low threshold on feature contrast]
Returns
[is a feature?]

◆ __interpHistEntry()

void __interpHistEntry ( vector< double > &  hist,
double  rbin,
double  cbin,
double  obin,
double  mag,
int  d,
int  n 
)

[Interpolates an entry into the array of orientation histograms]

Parameters
hist[2d histogram]
rbin[row]
cbin[col]
obin[orientation]
mag[size]
d[width of 2d hist]
n[number of bins for descriptor]

◆ __interpStep()

void __interpStep ( const vector< Mat > &  dog_pyramid,
int  idx,
int  r,
int  c,
double &  xi,
double &  xr,
double &  xc 
)

[one step of extremum interpolation]

Parameters
dog_pyramid[Dog pyramid]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
xi[interpolated subpixel increment to interval]
xr[interpolated subpixel increment to row]
xc[interpolated subpixel increment to col]

◆ __isExtremum()

bool __isExtremum ( const vector< Mat > &  dog_pyramid,
int  idx,
int  r,
int  c 
)

[Determines whether a pixel is a scale-space extremum]

Parameters
dog_pyramid[Dog pyramid]
idx[index of intervals]
r[pixel's image row]
c[pixel's image col]
Returns
[extremum?]

◆ __isTooEdgeLike()

bool __isTooEdgeLike ( const Mat &  dog,
int  r,
int  c,
int  curvature_thres 
)

[Is a feature too edge like?]

Parameters
dog[Dog layer]
r[row]
c[col]
curvature_thres[high threshold on ratio of principal curvatures]
Returns
[edge?]

◆ __normalizeDescriptor()

void __normalizeDescriptor ( vector< double > &  descriptor)

[normalize descriptor to length 1]

Parameters
descriptor[descriptor vector]

◆ __oriHist()

void __oriHist ( const Mat &  gaussian,
vector< double > &  hist,
int  r,
int  c,
int  rad,
double  sigma 
)

[Compute gradient orientation histogram]

Parameters
gaussian[gaussian image]
hist[returned hist]
r[row]
c[col]
n[number of bins]
rad[radius of selected region]
sigma[sigma for gaussian smoothing]

◆ __scaleSpaceExtrema()

void __scaleSpaceExtrema ( const vector< Mat > &  dog_pyramid,
vector< Feature > &  feats,
int  octaves,
int  intervals,
double  contrast_thres,
int  curvature_thres 
)

[Detects features at extrema in DoG scale space]

Parameters
dog_pyramid[Dog pyramid]
feats[Detected features with scales, origentations and descriptors to be determined]
octaves[number of octaves]
intervals[number of intervals per octave]
contrast_thres[low threshold on feature contrast]
curvature_thres[high threshold on feature ratio of principal curvatures]

◆ __smoothOriHist()

void __smoothOriHist ( vector< double > &  hist)

[Gaussian smooths an orientation histogram.]

Parameters
hist[orientation histogram]

◆ _derivative()

void _derivative ( )

◆ convertGrayAndNormalize()

void convertGrayAndNormalize ( const Mat &  input,
Mat &  output 
)

Change 3Channel RGB image to normalized gray image.

Parameters
input3Channel RGB input image
outputnormalized grayscale output image with pixel values in 0.0f~1.0f

◆ end_time()

void end_time ( system_clock::time_point &  startTime,
system_clock::time_point &  endTime,
const char *  step_name 
)

◆ extractSiftFeatures()

void extractSiftFeatures ( const Mat &  img,
vector< KeyPoint > &  keypoints,
Mat &  descriptor,
int  intervals = SIFT_INTERVALS,
double  sigma = SIFT_SIGMA,
double  contrast_thres = SIFT_CONTRAST_THRES,
int  curvature_thres = SIFT_CURVATURE_THRES,
bool  img_dbl = SIFT_IMG_DBL,
int  descr_width = SIFT_DESCR_WIDTH,
int  descr_hist_bins = SIFT_DESCR_HIST_BINS 
)

[Detect & extract sift features for an image]

Parameters
img[source image for extract sift features : grayscale image with pixel values in 0.0f~1.0f]
keypoints[vector for store sift feature point]
descriptor[Mat for store sift descriptor, each row for a keypoint]
intervals[the number of sampled intervals per octave]
sigma[sigma for initial gaussian smoothing]
contrast_thres[threshold on keypoint contrast]
curvature_thres[threshold on keypoint ratio of principle curvatures]
img_dbl[double image size before pyramid construction?]
descr_width[width of descriptor histogram array]
descr_hist_bins[number of bins per histogram in descriptor array]

◆ filterCreation()

void filterCreation ( double **  GKernel,
int  kSize,
double  sigma 
)

Create 2D gaussian filter

Parameters
GKerneloutput 2D gaussian filter
kSizegaussian kernel size
sigmagaussian sigma

◆ filterCreation1D()

void filterCreation1D ( float *  GKernel,
int  kSize,
double  sigma 
)

Create 1D gaussian filter

Parameters
GKerneloutput 1D gaussian filter
kSizegaussian kernel size
sigmagaussian sigma

◆ gaussianBlur()

void gaussianBlur ( const Mat &  src,
Mat &  output,
int  kSize,
double **  kernel 
)

Blurs an image using a Gaussian filter using padding
Assume that dst already copy the data of src

Parameters
srcinput image; Normalized grayscale input image
outputoutput image of the same size and type as src.
kSizewidth of the input image
kernelGaussian 2D kernel

◆ resizeHalf()

void resizeHalf ( const Mat &  input,
Mat &  output,
Size  outSize 
)

Resize image using Nearest neighbor sampling. Reduce width and height in half. (Native)

Parameters
inputnormalized grayscale input image
outputresized output image
outSizeoutput image size

◆ start_time()

void start_time ( system_clock::time_point &  startTime)

Variable Documentation

◆ gKernel

double** gKernel

◆ kSize

int kSize = 9

◆ p_cnt

volatile int p_cnt = 0