32 #include <Image/FFT2D.hh>
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Image/LogPolarMapping.hh>
37 #include <Image/HomographyMapping.hh>
38 #include <Base/Debug/TimeMeasure.hh>
39 #include <Geometry/RMatrix.hh>
53 for(
int i=0;i<height;i++){
54 for(
int j=1;j<width;j++){
55 dimgp[(j-1)+i*(width-1)] = simgp[j+i*width];
65 int qsize = width*height/2;
68 dst.
Init(width,height,1);
71 for(
int i=0;i<qsize;i++){
73 oimgp[qsize+i] = log(simgp[i]);
74 oimgp[i] = log(simgp[qsize+i]);
109 int size = width*height;
113 for(
int i=0;i<size;i++){
114 oimgp1[i] = (float) imgp1[i];
122 int size = width*height;
126 for(
int i=0;i<size;i++){
127 oimgp1[i] = (
unsigned char) imgp1[i];
132 int main(
int argc,
char *argv[])
135 TimeMeasure t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11;
140 cerr << argv[0] <<
" <image> <image2>\n";
145 Image<float> im1greyfloat, im2correctedfloat, im2greyfloat, mag1, mag1cut, mag1mirrored, mag2, mag2cut, mag2mirrored, cps, res;
148 unsigned int* coords = (
unsigned int*) calloc(2,
sizeof(
unsigned int));
149 unsigned int* coords2 = (
unsigned int*) calloc(2,
sizeof(
unsigned int));
153 HMatrix HTrans(MatrixIdentity);
154 HMatrix HTransInv(MatrixIdentity);
156 HMatrix HScale(MatrixIdentity);
158 if (ImageIO::Load(argv[1], im1)!=0){
159 BIASERR(
"error loading image "<<argv[1]);
162 if (ImageIO::Load(argv[2], im2)!=0){
163 BIASERR(
"error loading image "<<argv[2]);
170 if((width != (
int)im2.
GetWidth()) ||
172 BIASERR(
"images must have same size!");
184 fft.
Init(width,height);
187 ImageConvert::ToGrey(im1,im1grey);
189 ImageIO::Save(
"0_Grey1",im1grey);
190 ImageConvert::ToGrey(im2,im2grey);
192 ImageIO::Save(
"0_Grey2",im2grey);
199 castfloat(im1grey,im1greyfloat);
200 castfloat(im2grey,im2greyfloat);
207 ImageIO::Save(
"1_mag1",mag1);
210 ImageIO::Save(
"1_mag2",mag2);
219 mirror(mag1cut,mag1mirrored);
220 mirror(mag2cut,mag2mirrored);
223 ImageIO::Save(
"2_mag1mirrored",mag1mirrored);
224 ImageIO::Save(
"2_mag2mirrored",mag2mirrored);
229 mapperlp.
Map(mag1mirrored, im1lp, MapBilinear);
231 if (ImageIO::Save(
"ImgLogPolar.mip", im1lp)!=0){
232 BIASERR(
"error image");
235 mapperlp.
Map(mag2mirrored, im2lp, MapBilinear);
237 if (ImageIO::Save(
"ImgLogPolar2.mip", im2lp)!=0){
238 BIASERR(
"error image");
246 ImageIO::Save(
"3_CPS",cps);
253 ImageIO::Save(
"4_Resolution",res);
263 angle = (double)coords[1] / (
double) height * M_PI;
264 if (angle > (0.5*M_PI)) angle -= M_PI;
265 if(coords[0] > (
unsigned int)(width/2))
266 scale = pow((
double)(width/2),((
double)coords[0]-(
double)width)/(
double)width);
268 scale = pow((
double)(width/2),(
double)coords[0]/(
double) width);
270 HTrans[0][2] = (double)(width/2);
271 HTrans[1][2] = (double)(height/2);
272 HTransInv[0][2] = (double)-(width/2);
273 HTransInv[1][2] = (double)-(height/2);
274 HRot[0][0]= cos(angle);
275 HRot[0][1]= -sin(angle);
276 HRot[1][0]= sin(angle);
277 HRot[1][1]= cos(angle);
278 HScale[0][0] = scale;
279 HScale[1][1] = scale;
282 H = HTrans * HScale * HRot * HTransInv;
284 MapperHM.
Map(im2grey, imgcorrected, MapBilinear);
286 ImageIO::Save(
"5_Corrected",imgcorrected);
291 castfloat(imgcorrected,im2correctedfloat);
295 ImageIO::Save(
"6_Resolution2",res);
299 if(coords2[0] > (
unsigned int)(width/2))
300 HTrans[0][2] = width - (int)coords2[0];
302 HTrans[0][2] = -(int)coords2[0];
303 if(coords2[1] > (
unsigned int)(height/2))
304 HTrans[1][2] = height - (int)coords2[1];
306 HTrans[1][2] = -(int)coords2[1];
309 MapperHM.
Map(imgcorrected, imgcorrected2, MapBilinear);
311 ImageIO::Save(
"7_Corrected2",imgcorrected2);
318 cout <<
"Loading Image and converting to grey took "<<t1.
GetUserTime()<<
" ms, "<<endl;
319 cout <<
"Floating took "<<t2.
GetUserTime()<<
" ms, "<<endl;
320 cout <<
"Init FFT took "<<t10.
GetUserTime()<<
" ms, "<<endl;
321 cout <<
"FFT took "<<t3.
GetUserTime()<<
" ms, "<<endl;
322 cout <<
"Mirror took "<<t4.
GetUserTime()<<
" ms, "<<endl;
323 cout <<
"LogPolar took: "<<t5.
GetUserTime()<<
" ms, "<<endl;
324 cout <<
"CPS took "<<t6.
GetUserTime()<<
" ms, "<<endl;
325 cout <<
"IFT took "<<t7.
GetUserTime()<<
" ms, "<<endl;
326 cout <<
"Finding Max took "<<t8.
GetUserTime()<<
" ms, "<<endl;
327 cout <<
"Correcting rotation and scale took "<<t9.
GetUserTime()<<
" ms, "<<endl;
328 cout <<
"Finding and correcting translation took "<<t11.
GetUserTime()<<
" ms, "<<endl;
332 cout<<
"Max at: "<<coords[0]<<
"/"<<coords[1]<<
" value: "<<max<<endl<<endl;
333 cout<<
"Max2 at: "<<coords2[0]<<
"/"<<coords2[1]<<
" value: "<<max2<<endl<<endl;
334 cout<<
"Das entspricht (fuer ein 512x512 Bild):"<<endl;
335 if(coords[0] > (
unsigned int)(width/2))
336 cout<<
"Skalierungsfaktor: "<<pow(256.0,((
double)coords[0]-width)/512.0)<<endl;
338 cout<<
"Skalierungsfaktor: "<<pow(256.0,(
double)coords[0]/512.0)<<endl;
339 cout<<
"Rotation: "<<180.0*angle/M_PI<<
" Grad"<<endl;
341 cout<<
"Verschiebung: (";
342 if(coords2[0] > (
unsigned int)(width/2))
343 cout<<width - (int)coords2[0];
345 cout<<-(int)coords2[0];
347 if(coords2[1] > (
unsigned int)(height/2))
348 cout<<height - (int)coords2[1];
350 cout<<-(int)coords2[1];
Maps cartesian source coordinates to log-polar sink coordinates.
void Release()
reimplemented from ImageBase
StorageType GetMaxPixelValue(unsigned short int channel=0, unsigned int *coo=NULL) const
Get the maximal pixel value if coo!=NULL the coo[0]=x of max and coo[1]=y of max. ...
a 3x3 Matrix describing projective transformations between planes
Maps image src to image sink with homography H (software implementation)
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
void SetImageCenter(const int &x, const int &y)
set your image center before calling Map().
unsigned int GetWidth() const
virtual int TransformAbs(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Transform forward and get absolute value from complex result The result is not normalized! ...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
int Map(const Image< InputStorageType > &src, Image< OutputStorageType > &sink, InterpolationMethod=MapTrilinear, bool newSink=false, double SuperSampling=1.0)
backward mapping with various interpolations
void Init(unsigned int Width, unsigned int Height, unsigned int channels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
calls Init from ImageBase storageType is ignored, just dummy argument
const StorageType * GetImageData() const
overloaded GetImageData() from ImageBase
void Init(int width, int height)
initializes for forward transformation on complete image.
enum EColorModel GetColorModel() const
virtual int CrossPowerSpectrum(const Image< InputStorageType > &src1, const Image< InputStorageType > &src2, Image< OutputStorageType > &dst1)
Wrapper to the fftw3 library adapted for 2D image filtering.
void SetHomography(const HMatrix &H)
set your homography H (source = H * sink) before calling Map()
virtual int TransformReverse(const Image< OutputStorageType > &src, Image< InputStorageType > &dst)
Transform reverse, src must be of _SizeX,_OutSizeY,2.
double GetUserTime() const
return user time (=system usage time) in msec JW For Win32: user-time is the sum over all processes o...
class TimeMeasure contains functions for timing real time and cpu time.