资源简介
MATLAB完成图像匹配的代码: 都是通过归一化的傅里叶描述子,来完成图像匹配,旋转不变性,有一定的尺度,
代码片段和文件信息
/*
轮廓数据提取示例程序
Written by Mao Y.Bin
School of Automation NJUST
2010.12.13
*/
# include “viLib.h“ // 包含头文件
# pragma comment( lib “viLib.lib“ ) // 包含viLib.lib库
//////////////////////////////////////////////////////////////////////
# include
# include
#include
#include
#include
#include
using namespace std;
const double pi = acos(-1.0);
//////////////////////////////////////////////////////////////////////
/*
轮廓数据读取函数
轮廓数据以文本文件保存。
文件格式:
第1行:总数据点数
第2-n行:第一个点坐标,先x后y,中间以空格隔开
注意:轮廓数据文件中保存的轮廓点数,起始点和终止点是重合的,也就是起始
点保存了两次,起始一次,结束一次。
*/
/*
获得轮廓数据文件中轮廓的总点数
输入参数:
char * filename: 文件名
输出参数:
无
返回值:
轮廓总点数,若返回值 <= 0则表示读取错误
*/
int GetContourInfo( char * filename )
{
FILE * fp;
int N;
fp = fopen( filename “rt“ );
if ( fp == NULL ) return( 0 );
fscanf( fp “%d“ &N );
fclose( fp );
return( N );
}
/*
读入数据,返回值为读入的总轮廓点数
输入参数:
char * filename: 文件名
int * Contours: 轮廓点(大小为2N,N为轮廓点数)
其中,偶数位置存x坐标,奇数位置存y坐标
输出参数:
无
返回值:
轮廓总点数,若返回值 <= 0则表示读取错误
*/
int ReadContourData( char * filename int * Contours )
{
FILE * fp;
int N k x y;
fp = fopen( filename “rt“ );
if ( fp == NULL ) return( 0 );
fscanf( fp “%d“ &N );
for ( k = 0; k < N; k++ )
{
fscanf( fp “%d %d“ &x &y );
Contours[k*2] = x;
Contours[k*2+1] = y;
}
fclose( fp );
return( N );
}
void DFT(int Nint *dataR int *dataIdouble *ansRdouble *ansIdouble DFT=0)
{
int k n;
for(k=0; k<=N-1; k++)
{
if(DFT==1) dataI[k] = -dataI[k];
ansR[k] = ansI[k] = 0;
for(n=0; n<=N-1; n++)
{
double tempRtempI;
double cos_tap=cos(2*pi*k*n/N);
double sin_tap=sin(2*pi*k*n/N);
if(DFT==1)
{
tempR = (dataR[n]*cos_tap+dataI[n]*sin_tap)/N;
ansR[k] += tempR;
tempI = (dataR[n]*sin_tap-dataI[n]*cos_tap)/N;
ansI[k] += tempI;
}
else
{
tempR = dataR[n]*cos_tap+dataI[n]*sin_tap;
ansR[k] += tempR;
tempI = -(dataR[n]*sin_tap-dataI[n]*cos_tap);
ansI[k] += tempI;
}
}//end for2
}//end for1
}//end DFT
void fourierdes(char* filenamedouble* dkint NN)//归一化傅里叶变换
{
int * Contour2;
NN = GetContourInfo( filename ); // 获得轮廓点数
int* xx = new int [NN];
int* yy = new int [NN];
double* out1 = new double [NN];
double* out2 = new double [NN];
if ( NN > 0 )
{
Contour2 = new int [NN*2];
ReadContourData( filename Contour2 ); // 读入轮廓点数据
for(int i=0;i {
xx[i]=Contour2[i*2];
yy[i]=Contour2[i*2+1];
}
//dft并计算dk
DFT(NNxx yyout1out20);
//归一化傅里叶系数
double f1=sqrt((out1[1]*out1[1])+(out2[1]*out2[1]));
for(int i=1;i {
dk[i-1]=sqrt(double(out1[i]*out1[i])+double(out2[i]*out2[i]));
dk[i-1]=(double)dk[i-1]/(double)f1;
}
delete [] Contour2;
delete [] x
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
.CA.... 448826 2011-01-04 20:37 110101338郭思郁作业1\110101338郭思郁作业1.pdf
.CA.... 7714 2011-01-04 20:19 110101338郭思郁作业1\homework1\ContourRead.cpp
.CA.... 3470 2010-12-14 21:40 110101338郭思郁作业1\homework1\ContourRead.dsp
.CA.... 547 2010-12-14 21:44 110101338郭思郁作业1\homework1\ContourRead.dsw
.CA.... 14748672 2011-01-04 20:20 110101338郭思郁作业1\homework1\ContourRead.ncb
.CA.... 48640 2010-12-14 21:44 110101338郭思郁作业1\homework1\ContourRead.opt
.CA.... 1249 2010-12-14 21:44 110101338郭思郁作业1\homework1\ContourRead.plg
.CA.... 887 2011-01-02 10:13 110101338郭思郁作业1\homework1\ContourRead.sln
.CA..H. 19968 2011-01-04 20:20 110101338郭思郁作业1\homework1\ContourRead.suo
.CA.... 4901 2010-12-30 22:56 110101338郭思郁作业1\homework1\ContourRead.vcproj
.CA.... 1490 2011-01-04 20:20 110101338郭思郁作业1\homework1\ContourRead.vcproj.YUYU.Administrator.user
.CA.... 9374 2010-12-31 15:15 110101338郭思郁作业1\homework1\Debug\bat0.txt
.CA.... 13114 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\BuildLog.htm
.CA.... 561664 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\ContourRead.exe
.CA.... 406 2011-01-02 11:27 110101338郭思郁作业1\homework1\Debug\ContourRead.exe.em
.CA.... 472 2011-01-02 11:27 110101338郭思郁作业1\homework1\Debug\ContourRead.exe.em
.CA.... 381 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\ContourRead.exe.intermediate.manifest
.CA.... 1194372 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\ContourRead.ilk
.CA.... 67671 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\ContourRead.obj
.CA.... 3468288 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\ContourRead.pdb
.CA.... 8045 2010-12-14 18:51 110101338郭思郁作业1\homework1\Debug\flatfish0.txt
.CA.... 2420736 2009-12-22 15:55 110101338郭思郁作业1\homework1\Debug\FreeImage.dll
.CA.... 5513 2010-12-14 18:51 110101338郭思郁作业1\homework1\Debug\hammer0.txt
.CA.... 6539 2010-12-14 18:51 110101338郭思郁作业1\homework1\Debug\key0.txt
.CA.... 69 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\mt.dep
.CA.... 486400 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\vc90.idb
.CA.... 233472 2011-01-04 20:19 110101338郭思郁作业1\homework1\Debug\vc90.pdb
.CA.... 102400 2010-09-02 11:10 110101338郭思郁作业1\homework1\Debug\viLib.dll
.CA.... 27213 2010-07-06 17:55 110101338郭思郁作业1\homework1\viLib.h
.CA.... 12098 2010-09-02 11:10 110101338郭思郁作业1\homework1\viLib.lib
............此处省略6个文件信息
评论
共有 条评论