📄 main.cpp
字号:
/* * This program is used to registrate two images */
#include "main.h"
void main()// int argc;// char **argv;{ char* inputfilename,*referfilename,*targetfilename; /* filename */ FILE *infPtr,*refPtr,*tfPtr; /* file ptr */ long img_width,img_height,i; /* file size */ unsigned char *image_in,*image_re,*image_out;
int h_start,h_end; //wavelet transform coefficient
double *h_coe;
//wavelet decomposition levels
unsigned char *inLL_level1,*inLH_level1,*inHL_level1,*inHH_level1;
unsigned char *reLL_level1,*reLH_level1,*reHL_level1,*reHH_level1;
unsigned char *inLL_level2,*inLH_level2,*inHL_level2,*inHH_level2;
unsigned char *reLL_level2,*reLH_level2,*reHL_level2,*reHH_level2;
unsigned char *inLL_level3,*inLH_level3,*inHL_level3,*inHH_level3;
unsigned char *reLL_level3,*reLH_level3,*reHL_level3,*reHH_level3;
double angleL,angleR,angleD,xL,xR,yL,yR,xyD,xCen,yCen,angleCen;
double *xC,*yC,*angleC;
DECLARE_TIME(t0);
DECLARE_TIME(t1);
memset(timer_ticks,0,VPTIMER_COUNT);//========================================================================// ALL needed parameters are here// 1. input file name// 2. output file name// 3. transform tx ty, change scope// 4. rotate angle, change scope// 5. image size is determined by reading input file
i = 4;
switch(i){
case 1: inputfilename="lake-airport1024-1.bmp";//10,10,-3
referfilename="lake-airport1024.bmp";
break;
case 2:
inputfilename="rs512-1.bmp";//20,5,7
referfilename="rs512.bmp";
break;
case 3:
inputfilename="lenna512-1.bmp";//23,37,13
referfilename="lenna512.bmp";
break;
case 4:
inputfilename="brain1.bmp";//8,6,-25
referfilename="brain.bmp";
break;
case 5:
inputfilename="co1.bmp";//20,5,7
referfilename="co.bmp";
break;
case 6:
inputfilename="lake3072-1.bmp";//-55,14,21,result -54,10,21
referfilename="lake3072.bmp";
break;
case 7:
inputfilename="lenaNoise1.bmp";//-13,9,-17,result -13,9,-17
referfilename="lenna512.bmp";
break;
case 8:
inputfilename="lenaDenoise1.bmp";//-13,9,-17,result -13,9,-17
referfilename="lenna512.bmp";
break;
case 9:
inputfilename="lake-airportNoise1.bmp";//20,20,-8,result 20,20,-8
referfilename="lake-airport1024.bmp";
break;
case 10:
inputfilename="seaport1024-1.bmp";//-170,170,-30
referfilename="seaport1024.bmp";
break;
case 11:
inputfilename="Noise1.bmp";//20,20,-8,result 22,22,-8
referfilename="Noise.bmp";
break;
case 12:
inputfilename="bridge512-1.bmp";
referfilename="bridge512-2.bmp";
break;
}
targetfilename="best.bmp";
h_start = 0; h_end = 3;
h_coe = (double *)malloc(sizeof(double)*(h_end-h_start+1));
h_coe[0] = 0.482962913145;
h_coe[1] = 0.836516303738;
h_coe[2] = 0.224143868042;
h_coe[3] = -0.129409522551;
//========================================================================= infPtr = imgOpen(inputfilename,&img_width,&img_height,0);
refPtr = imgOpen(referfilename,&img_width,&img_height,0); tfPtr = imgOpen(targetfilename,&img_width,&img_height,1);
long dataLength;
dataLength = img_width*img_height; image_in = (unsigned char *)malloc(dataLength);
image_re = (unsigned char *)malloc(dataLength); image_out = (unsigned char *)malloc(dataLength);
dataLength = (img_width/2)*(img_height/2);
inLL_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inLH_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHL_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHH_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLL_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLH_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHL_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHH_level1 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
dataLength = (img_width/4)*(img_height/4);
inLL_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inLH_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHL_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHH_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLL_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLH_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHL_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHH_level2 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
dataLength = (img_width/8)*(img_height/8);
inLL_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inLH_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHL_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
inHH_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLL_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reLH_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHL_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
reHH_level3 = (unsigned char *)malloc(sizeof(unsigned char)*dataLength);
memset(image_out,0,img_width*img_height);
//=========================================================================// read source image data imgRead(infPtr,0,0,img_width,img_height,image_in);
imgRead(refPtr,0,0,img_width,img_height,image_re);
//=========================================================================
// wavelet transform function
long width,height;
printf("===========================================================\n\n");
printf(" 待配准的图像为:%s 和 %s\n\n",inputfilename,referfilename);
printf("*-----------------------------------------------------------------------*\n");
printf(" step 1: to do wavelet decompositon for input and reference image\n");
printf("*-----------------------------------------------------------------------*\n\n");
printf(" decomposition levels are %d\n\n",LEVELS);
GET_TIME(t0);
width = img_width; height = img_height;
cc_wavelet_transform(image_in,inLL_level1,inLH_level1,
inHL_level1,inHH_level1,
width,height,h_coe,h_start,h_end);
cc_wavelet_transform(image_re,reLL_level1,reLH_level1,
reHL_level1,reHH_level1,
width,height,h_coe,h_start,h_end);
#if 0
char* targetfile; /* filename */
FILE *Ptr;
long w,h;
w = width/2; h=width/2;
targetfile="tmp.bmp";
Ptr = imgOpen(targetfile,&w,&h,1);
imgWrite(Ptr,0,0,w,h,inLL_level1);
printf("\ntmp is created!\n\n");
fclose(Ptr);
#endif
width = img_width/2; height = img_height/2;
cc_wavelet_transform(inLL_level1,inLL_level2,inLH_level2,
inHL_level2,inHH_level2,
width,height,h_coe,h_start,h_end);
cc_wavelet_transform(reLL_level1,reLL_level2,reLH_level2,
reHL_level2,reHH_level2,
width,height,h_coe,h_start,h_end);
#if 1
char* targetfile; /* filename */
FILE *Ptr;
long w,h;
w = width/2; h=width/2;
targetfile="tmp.bmp";
Ptr = imgOpen(targetfile,&w,&h,1);
imgWrite(Ptr,0,0,w,h,reLL_level2);
printf("\ntmp is created!\n\n");
fclose(Ptr);
#endif
width = img_width/4; height = img_height/4;
cc_wavelet_transform(inLL_level2,inLL_level3,inLH_level3,
inHL_level3,inHH_level3,
width,height,h_coe,h_start,h_end);
cc_wavelet_transform(reLL_level2,reLL_level3,reLH_level3,
reHL_level3,reHH_level3,
width,height,h_coe,h_start,h_end);
GET_TIME(t1);
STORE_TIME(WAVELET_TRANS,t0,t1);
angleL=-16; angleR=16; angleD=8;
xL=-16; xR=16; yL=-16; yR=16; xyD=8;
xCen=0; yCen=0; angleCen=0;
xC=&xCen; yC=&yCen; angleC=&angleCen;
width /= 2; height /= 2;
//=========================================================================// registration function
printf("*------------------------------------------------------------------*\n");
printf(" step 2: to do registration from high level to low level\n");
printf("*------------------------------------------------------------------*\n\n");
//GET_TIME(t0);
for(i=LEVELS;i>=0;i--){
switch(i){
case 0:
printf(" level %d\n",i);
GET_TIME(t0);
cc_registration(image_in,image_re,img_width,img_height,
angleL,angleR,angleD,xL,xR,yL,yR,xyD,
angleC,xC,yC);
GET_TIME(t1);
STORE_TIME(REGISTRATION,t0,t1);
printf(" best_x is %f, best_y is %f, best_angle is %f\n\n",
*xC,*yC,*angleC);
break;
case 1:
printf(" level %d\n",i);
cc_registration(inLL_level1,reLL_level1,width,height,
angleL,angleR,angleD,xL,xR,yL,yR,xyD,
angleC,xC,yC);
printf(" best_x is %f, best_y is %f, best_angle is %f\n\n",
*xC,*yC,*angleC);
break;
case 2:
printf(" level %d\n",i);
cc_registration(inLL_level2,reLL_level2,width,height,
angleL,angleR,angleD,xL,xR,yL,yR,xyD,
angleC,xC,yC);
printf(" best_x is %f, best_y is %f, best_angle is %f\n\n",
*xC,*yC,*angleC);
break;
case 3:
printf(" level %d\n",i);
cc_registration(inLL_level3,reLL_level3,width,height,
angleL,angleR,angleD,xL,xR,yL,yR,xyD,
angleC,xC,yC);
printf(" best_x is %f, best_y is %f, best_angle is %f\n\n",
*xC,*yC,*angleC);
break;
default: printf("error! please add code for higher level\n");
}
angleL = -angleD; angleR = angleD;
xL = -xyD; xR = xyD;
yL = -xyD; yR = xyD;
angleD /=2; xyD /= 2;
width *=2 ; height *= 2;
*xC *= 2; *yC *= 2;
}
//GET_TIME(t1);
//STORE_TIME(REGISTRATION,t0,t1);
printf(" registation is over!\n\n");
printf("*------------------------------------------------------------------*\n\n");
*xC /= 2; *yC /= 2;
printf(" best_x is %f, best_y is %f, best_angle is %f\n",
*xC,*yC,*angleC);
printf(" 小波变换时间为 %d 微秒\n",timer_ticks[WAVELET_TRANS]);
printf(" 配准时间为 %d 微秒\n\n",timer_ticks[REGISTRATION]);
printf("===========================================================\n\n");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -