#include <Image/FFT2D.hh>
#include <Base/Image/Image.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Image/LogPolarMapping.hh>
#include <Image/HomographyMapping.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Geometry/RMatrix.hh>
using namespace std;
using namespace BIAS;
for(int i=0;i<height;i++){
for(int j=1;j<width;j++){
dimgp[(j-1)+i*(width-1)] = simgp[j+i*width];
}
}
return 0;
}
int qsize = width*height/2;
dst.
Init(width,height,1);
for(int i=0;i<qsize;i++){
oimgp[qsize+i] = log(simgp[i]);
oimgp[i] = log(simgp[qsize+i]);
}
return 0;
}
int size = width*height;
for(int i=0;i<size;i++){
oimgp1[i] = (float) imgp1[i];
}
return 0;
}
int size = width*height;
for(int i=0;i<size;i++){
oimgp1[i] = (unsigned char) imgp1[i];
}
return 0;
}
int main(int argc, char *argv[])
{
TimeMeasure t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11;
if (argc != 3){
cerr << argv[0] << " <image> <image2>\n";
return -1;
}
Image<float> im1greyfloat, im2correctedfloat, im2greyfloat, mag1, mag1cut, mag1mirrored, mag2, mag2cut, mag2mirrored, cps, res;
float max, max2;
double angle,scale;
unsigned int* coords = (unsigned int*) calloc(2,sizeof(unsigned int));
unsigned int* coords2 = (unsigned int*) calloc(2,sizeof(unsigned int));
if (ImageIO::Load(argv[1], im1)!=0){
BIASERR("error loading image "<<argv[1]);
return -2;
}
if (ImageIO::Load(argv[2], im2)!=0){
BIASERR("error loading image "<<argv[2]);
return -2;
}
BIASERR("images must have same size!");
return -2;
}
ImageConvert::ToGrey(im1,im1grey);
ImageIO::Save("0_Grey1",im1grey);
ImageConvert::ToGrey(im2,im2grey);
ImageIO::Save("0_Grey2",im2grey);
castfloat(im1grey,im1greyfloat);
castfloat(im2grey,im2greyfloat);
ImageIO::Save("1_mag1",mag1);
ImageIO::Save("1_mag2",mag2);
cut(mag1,mag1cut);
cut(mag2,mag2cut);
}
mirror(mag1cut,mag1mirrored);
mirror(mag2cut,mag2mirrored);
ImageIO::Save("2_mag1mirrored",mag1mirrored);
ImageIO::Save("2_mag2mirrored",mag2mirrored);
mapperlp.
Map(mag1mirrored, im1lp, MapBilinear);
if (ImageIO::Save("ImgLogPolar.mip", im1lp)!=0){
BIASERR("error image");
}
mapperlp.
Map(mag2mirrored, im2lp, MapBilinear);
if (ImageIO::Save("ImgLogPolar2.mip", im2lp)!=0){
BIASERR("error image");
}
ImageIO::Save("3_CPS",cps);
ImageIO::Save("4_Resolution",res);
angle = (double)coords[1] / (double) height * M_PI;
if (angle > (0.5*M_PI)) angle -= M_PI;
if(coords[0] > (unsigned int)(width/2))
scale = pow((double)(width/2),((double)coords[0]-(double)width)/(double)width);
else
scale = pow((double)(width/2),(double)coords[0]/(double) width);
HTrans[0][2] = (double)(width/2);
HTrans[1][2] = (double)(height/2);
HTransInv[0][2] = (double)-(width/2);
HTransInv[1][2] = (double)-(height/2);
HRot[0][0]= cos(angle);
HRot[0][1]= -sin(angle);
HRot[1][0]= sin(angle);
HRot[1][1]= cos(angle);
HScale[0][0] = scale;
HScale[1][1] = scale;
HScale[1][2] = 1.0;
H = HTrans * HScale * HRot * HTransInv;
MapperHM.
Map(im2grey, imgcorrected, MapBilinear);
ImageIO::Save("5_Corrected",imgcorrected);
castfloat(imgcorrected,im2correctedfloat);
ImageIO::Save("6_Resolution2",res);
if(coords2[0] > (unsigned int)(width/2))
HTrans[0][2] = width - (int)coords2[0];
else
HTrans[0][2] = -(int)coords2[0];
if(coords2[1] > (unsigned int)(height/2))
HTrans[1][2] = height - (int)coords2[1];
else
HTrans[1][2] = -(int)coords2[1];
MapperHM.
Map(imgcorrected, imgcorrected2, MapBilinear);
ImageIO::Save("7_Corrected2",imgcorrected2);
cout<<endl<<endl;
cout <<
"Loading Image and converting to grey took "<<t1.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Floating took "<<t2.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Init FFT took "<<t10.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Mirror took "<<t4.
GetUserTime()<<
" ms, "<<endl;
cout <<
"LogPolar took: "<<t5.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Finding Max took "<<t8.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Correcting rotation and scale took "<<t9.
GetUserTime()<<
" ms, "<<endl;
cout <<
"Finding and correcting translation took "<<t11.
GetUserTime()<<
" ms, "<<endl;
cout<<endl;
cout<<"Max at: "<<coords[0]<<"/"<<coords[1]<<" value: "<<max<<endl<<endl;
cout<<"Max2 at: "<<coords2[0]<<"/"<<coords2[1]<<" value: "<<max2<<endl<<endl;
cout<<"Das entspricht (fuer ein 512x512 Bild):"<<endl;
if(coords[0] > (unsigned int)(width/2))
cout<<"Skalierungsfaktor: "<<pow(256.0,((double)coords[0]-width)/512.0)<<endl;
else
cout<<"Skalierungsfaktor: "<<pow(256.0,(double)coords[0]/512.0)<<endl;
cout<<"Rotation: "<<180.0*angle/M_PI<<" Grad"<<endl;
cout<<"Verschiebung: (";
if(coords2[0] > (unsigned int)(width/2))
cout<<width - (int)coords2[0];
else
cout<<-(int)coords2[0];
cout<<",";
if(coords2[1] > (unsigned int)(height/2))
cout<<height - (int)coords2[1];
else
cout<<-(int)coords2[1];
cout<<")"<<endl;
return 0;
}