⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 siftdescriptor.c

📁 sift的matlab代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* file:        siftdescriptor** author:      Andrea Vedaldi** description: Compute SIFT descriptors**//* AUTORIGHTSCopyright (c) 2006 The Regents of the University of California.All Rights Reserved.Created by Andrea VedaldiUCLA Vision Lab - Department of Computer SciencePermission to use, copy, modify, and distribute this software and itsdocumentation 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 thefollowing three paragraphs appear in all copies.This software program and documentation are copyrighted by The Regentsof the University of California. The software program anddocumentation are supplied "as is", without any accompanying servicesfrom The Regents. The Regents does not warrant that the operation ofthe program will be uninterrupted or error-free. The end-userunderstands that the program was developed for research purposes andis advised not to rely exclusively on the program for any reason.This software embodies a method for which the following patent hasbeen issued: "Method and apparatus for identifying scale invariantfeatures in an image and use of same for locating an object in animage," David G. Lowe, US Patent 6,711,293 (March 23,2004). Provisional application filed March 8, 1999. Asignee: TheUniversity of British Columbia.IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTYFOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE ANDITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEENADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OFCALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOTLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FORA PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDEMAINTENANCE, 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. **/voidnormalize_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 + FLT_EPSILON ) ;}/** @brief MATLAB Driver. **/voidmexFunction(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]) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -