用java实现了归一化积相关的计算,主要源码如下:
static
public void guiyihua(Pic s_p,Pic t_p){
//s_p为源图像,t_p为实时图像
ints_height=s_p.getHeight();
ints_width=s_p.getWidth();
int t_height=t_p.getHeight();
intt_width=t_p.getWidth();
//两个图像的像素数组
int []s_pixels=s_p.getPixels();
int []t_pixels=t_p.getPixels();
//最佳匹配位置
int maxWidth=0;
int maxHeight=0;
intr=s_height-t_height;
int c=s_width-t_width;
int rc=r*c;
double tt=0.0;
double t=0.0;
double t_mn=0.0;
double s_mn=0.0;
double R=0.0;
double maxR=0.0;
int count=0;
for(int m=0;mdouble)t_pixels[m]*t_pixels[m];
t+=(double)t_pixels[m];
}
for(int j=0;j<=s_height-t_height;j++){
for(inti=0;i<=s_width-t_width;i++){
double ts=0.0;
double ss=0.0;
double s=0.0;
for(intm=0;mfor(intn=0;nsqrt((tt-t*t/rc)*(ss-s*s/rc));
if(R>maxR){
maxR=R;
maxWidth=i;
maxHeight=j;
}
}
}
System.out.println("最大归一化积相关系数为:"+maxR+"
匹配位置横坐标为:"+maxWidth+"
;匹配位置纵坐标为:"+maxHeight );
}
Pic类的定义:
class Pic{
int
height;//模拟图片高度
int
width;//模拟图像宽度
int
pixels[];//图像内的像素点用int数组来表示
public Pic(int h,int w,int[]
pix){
height=h;
width=w;
pixels=pix;
}
public
int getHeight() {
return
height;
}
public
void setHeight(int height) {
this.height = height;
}
public
int getWidth() {
return
width;
}
public
void setWidth(int width) {
this.width = width;
}
public
int[] getPixels() {
return
pixels;
}
public
void setPixels(int[] pixels) {
this.pixels = pixels;
}
}
Pic的实例化:
int t_pixels[]={//模拟实时图像
1,2,3,
4,5,6,
7,8,9
};
new Pic(3,3,t_pixels);
基准图像的图像实例化类似。