/* file: siftdescriptor
** author: Andrea Vedaldi
** description: Compute SIFT descriptors
**/
/* AUTORIGHTS
Copyright (c) 2006 The Regents of the University of California.
All Rights Reserved.
Created by Andrea Vedaldi
UCLA Vision Lab - Department of Computer Science
Permission to use, copy, modify, and distribute this software and its
documentation for educational, research and non-profit purposes,
without fee, and without a written agreement is hereby granted,
provided that the above copyright notice, this paragraph and the
following three paragraphs appear in all copies.
This software program and documentation are copyrighted by The Regents
of the University of California. The software program and
documentation are supplied "as is", without any accompanying services
from The Regents. The Regents does not warrant that the operation of
the program will be uninterrupted or error-free. The end-user
understands that the program was developed for research purposes and
is advised not to rely exclusively on the program for any reason.
This software embodies a method for which the following patent has
been issued: "Method and apparatus for identifying scale invariant
features in an image and use of same for locating an object in an
image," David G. Lowe, US Patent 6,711,293 (March 23,
2004). Provisional application filed March 8, 1999. Asignee: The
University of British Columbia.
IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND
ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF
CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE
MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
*/
/*
REMARKS. The use of strcasecmp makes the function POSIX but not ANSI
compliant. When compling with Altivec, GCC Altivec extensions are
supported.
*/
#define LOWE_COMPATIBLE
#include"mexutils.c"
#include<stdlib.h>
#include<math.h>
#ifdef WINDOWS
#include<string.h>
#ifndef __cplusplus
#define sqrtf(x) ((float)sqrt((double)(x)))
#define powf(x,y) ((float)pow((double)(x),(double)(y)))
#define fabsf(x) ((float)fabs((double)(x)))
#define sinf(x) ((float)sin((double)(x)))
#define cosf(x) ((float)cos((double)(x)))
#define expf(x) ((float)exp((double)(x)))
#define atan2f(x,y) ((float)atan2((double)(x),(double)(y)))
#endif
#else
#include<strings.h>
#endif
/* Altivec and Accelerate support.
* Very crude at this time.
*/
#if defined( MACOSX ) && defined( __ALTIVEC__ )
#include<Accelerate/Accelerate.h>
typedef union
{
float x[4] ;
vFloat vec ;
} float4 ;
#endif
#define greater(a,b) a > b
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
enum {SCALESPACE, NOSCALESPACE} ;
enum {PROP_MAGNIF=0,
PROP_NBP,
PROP_NBO,
PROP_UNKNOWN} ;
char const * properties [4] =
{ "Magnif",
"NumSpatialBins",
"NumOrientBins",
0L
} ;
/** Fast fmodf for 2*PI
**/
/*inline*/
float fast_mod(float th)
{
while(th < 0) th += 2*M_PI ;
while(th > 2*M_PI) th -= 2*M_PI ;
return th ;
}
/** Fast floor. Equivalent to (int) floor(x)
**/
/*inline*/
int fast_floor(float x)
{
return (int)( x - ((x>=0)?0:1) ) ;
}
/** Normalizes in norm L_2 a descriptor.
**/
void
normalize_histogram(float* L_begin, float* L_end)
{
float* L_iter ;
float norm=0.0 ;
for(L_iter = L_begin; L_iter != L_end ; ++L_iter)
norm += (*L_iter) * (*L_iter) ;
norm = sqrtf(norm) ;
/* mexPrintf("%f\n",norm) ;*/
for(L_iter = L_begin; L_iter != L_end ; ++L_iter)
*L_iter /= norm ;
}
/** @brief MATLAB Driver.
**/
void
mexFunction(int nout, mxArray *out[],
int nin, const mxArray *in[])
{
int M,N,S=0,smin=0,K,num_levels=0 ;
const int* dimensions ;
const double* P_pt ;
const double* G_pt ;
float* descr_pt ;
float* buffer_pt ;
float sigma0 ;
float magnif = 3.0f ; /* Spatial bin extension factor. */
int NBP = 4 ; /* Number of bins for one spatial direction (even). */
int NBO = 8 ; /* Number of bins for the ortientation. */
int mode = NOSCALESPACE ;
int buffer_size=0;
enum {IN_G=0,IN_P,IN_SIGMA0,IN_S,IN_SMIN} ;
enum {OUT_L=0} ;
/* ------------------------------------------------------------------
** Check the arguments
** --------------------------------------------------------------- */
if (nin < 3) {
mexErrMsgTxt("At least three arguments are required") ;
} else if (nout > 1) {
mexErrMsgTxt("Too many output arguments.");
}
if( !uIsRealScalar(in[IN_SIGMA0]) ) {
mexErrMsgTxt("SIGMA0 should be a real scalar") ;
}
if(!mxIsDouble(in[IN_G]) ||
mxGetNumberOfDimensions(in[IN_G]) > 3) {
mexErrMsgTxt("G should be a real matrix or 3-D array") ;
}
sigma0 = (float) *mxGetPr(in[IN_SIGMA0]) ;
dimensions = mxGetDimensions(in[IN_G]) ;
M = dimensions[0] ;
N = dimensions[1] ;
G_pt = mxGetPr(in[IN_G]) ;
P_pt = mxGetPr(in[IN_P]) ;
K = mxGetN(in[IN_P]) ;
if( !uIsRealMatrix(in[IN_P],-1,-1)) {
mexErrMsgTxt("P should be a real matrix") ;
}
if ( mxGetM(in[IN_P]) == 4) {
/* Standard (scale space) mode */
mode = SCALESPACE ;
num_levels = dimensions[2] ;
if(nin < 5) {
mexErrMsgTxt("Five arguments are required in standard mode") ;
}
if( !uIsRealScalar(in[IN_S]) ) {
mexErrMsgTxt("S should be a real scalar") ;
}
if( !uIsRealScalar(in[IN_SMIN]) ) {
mexErrMsgTxt("SMIN should be a real scalar") ;
}
if( !uIsRealMatrix(in[IN_P],4,-1)) {
mexErrMsgTxt("When the e mode P should be a 4xK matrix.") ;
}
S = (int)(*mxGetPr(in[IN_S])) ;
smin = (int)(*mxGetPr(in[IN_SMIN])) ;
} else if ( mxGetM(in[IN_P]) == 3 ) {
mode = NOSCALESPACE ;
num_levels = 1 ;
S = 1 ;
smin = 0 ;
} else {
mexErrMsgTxt("P should be either a 3xK or a 4xK matrix.") ;
}
/* Parse the property-value pairs */
{
char str [80] ;
int arg = (mode == SCALESPACE) ? IN_SMIN + 1 : IN_SIGMA0 + 1 ;
while(arg < nin) {
int k ;
if( !uIsString(in[arg],-1) ) {
mexErrMsgTxt("The first argument in a property-value pair"
" should be a string") ;
}
mxGetString(in[arg], str, 80) ;
#ifdef WINDOWS
for(k = 0 ; properties[k] && strcmpi(str, properties[k]) ; ++k) ;
#else
for(k = 0 ; properties[k] && strcasecmp(str, properties[k]) ; ++k) ;
#endif
switch (k) {
case PROP_NBP:
if( !uIsRealScalar(in[arg+1]) ) {
mexErrMsgTxt("'NumSpatialBins' should be real scalar") ;
}
NBP = (int) *mxGetPr(in[arg+1]) ;
if( NBP <= 0 || (NBP & 0x1) ) {
mexErrMsgTxt("'NumSpatialBins' must be positive and even") ;
}
break ;
case PROP_NBO:
if( !uIsRealScalar(in[arg+1]) ) {
mexErrMsgTxt("'NumOrientBins' should be a real scalar") ;
}
NBO = (int) *mxGetPr(in[arg+1]) ;
if( NBO <= 0 ) {
mexErrMsgTxt("'NumOrientlBins' must be positive") ;
}
break ;
case PROP_MAGNIF:
if( !uIsRealScalar(in[arg+1]) ) {
mexErrMsgTxt("'Magnif' should be a real scalar") ;
}
magnif = (float) *mxGetPr(in[arg+1]) ;
if( magnif <= 0 ) {
mexErrMsgTxt("'Magnif' must be positive") ;
}
break ;
case PROP_UNKNOWN:
mexErrMsgTxt("Property unknown.") ;
break ;
}
arg += 2 ;
}
}
/* ------------------------------------------------------
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
SIFT算法 MATLAB实现.rar (56个子文件)
SIFT算法 MATLAB实现
siftread.m 3KB
siftormx.c 8KB
sift_demo4.m 1KB
diffss.m 3KB
tightsubplot.m 5KB
siftdescriptor.m 4KB
gaussianss.m 8KB
siftmatch.c 10KB
siftdescriptor.c 16KB
imreadbw.m 2KB
imsmooth.c 4KB
LICENSE 2KB
sift_demo3.m 2KB
bundle.m 0B
sift_demo2.m 4KB
plotsiftframe.m 5KB
sift_demo5.m 387B
siftlocalmax.c 9KB
sift_overview.m 1KB
plotmatches.m 10KB
TIMESTAMP 219B
README 2KB
plotsiftdescriptor.m 5KB
doc
sift.tex 21KB
bibliography.bib 246B
visionlab.sty 6KB
figures
sift-descriptor.aux 8B
sift-descriptor.log 13KB
warmread.sty 47KB
sift-descriptor.wrm 13B
sift-descriptor.pdf 433KB
sift-descriptor-AI.bb 550B
sift-descriptor.tex 3KB
sift-descriptor-AI.pdf 465KB
sift-descriptor-SAVED.tex 3KB
siftrefinemx.m 3KB
siftrefinemx.c 9KB
data
circle.sift 1KB
landscape-b.jpg 298KB
img5.jpg 457KB
circle.pgm 10KB
box.pgm 71KB
nest.png 11KB
landscape-a.jpg 269KB
box.sift 228KB
img3.jpg 454KB
nest2.bmp 17KB
Makefile 2KB
sift_gendoc.css 3KB
sift.m 10KB
plotss.m 3KB
siftlocalmax.m 2KB
sift_compile.m 2KB
sift_demo.m 3KB
mexutils.c 2KB
siftmatch.m 3KB
共 56 条
- 1
wbhiverson
- 粉丝: 10
- 资源: 12
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
前往页