Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Here is how I did it (and it worked properly):

First I created 2 images (fft1 and fft2) according to getOptimalDFTSize(). Than I filled them with values from original images (image1 and image2). Than I made following calculations:

dft(fft1,fft1,0,image1.rows);
dft(fft2,fft2,0,image2.rows);
mulSpectrums(fft1,fft2,fft1,0,true);
idft(fft1,fft1);
double maxVal;
Point maxLoc;
minMaxLoc(fft1,NULL,&maxVal,NULL,&maxLoc);
resX = (maxLoc.x<width/2) ? (maxLoc.x) : (maxLoc.x-width);
resY = (maxLoc.y<height/2) ? (maxLoc.y) : (maxLoc.y-height);

Here is how I did it (and it worked properly):

First I created 1) Create 2 images (fft1 and fft2) according to getOptimalDFTSize(). Than I filled getOptimalDFTSize().

int width = getOptimalDFTSize(max(image1.cols,image2.cols));
int height = getOptimalDFTSize(max(image1.rows,image2.rows));
Mat fft1(Size(width,height),CV_32F,Scalar(0));
Mat fft2(Size(width,height),CV_32F,Scalar(0));

2) Filled them with values from original images (image1 and image2). Than I made image2).

3)Do the following calculations:

dft(fft1,fft1,0,image1.rows);
dft(fft2,fft2,0,image2.rows);
mulSpectrums(fft1,fft2,fft1,0,true);
idft(fft1,fft1);
double maxVal;
Point maxLoc;
minMaxLoc(fft1,NULL,&maxVal,NULL,&maxLoc);
resX = (maxLoc.x<width/2) ? (maxLoc.x) : (maxLoc.x-width);
resY = (maxLoc.y<height/2) ? (maxLoc.y) : (maxLoc.y-height);

Here is how I did it (and it worked properly):

1) Create 2 images (fft1 and fft2) according to getOptimalDFTSize().

int width = getOptimalDFTSize(max(image1.cols,image2.cols));
int height = getOptimalDFTSize(max(image1.rows,image2.rows));
Mat fft1(Size(width,height),CV_32F,Scalar(0));
Mat fft2(Size(width,height),CV_32F,Scalar(0));

2) Filled them with values from original images (image1 and image2).

3)Do 3) Do the following calculations:

dft(fft1,fft1,0,image1.rows);
dft(fft2,fft2,0,image2.rows);
mulSpectrums(fft1,fft2,fft1,0,true);
idft(fft1,fft1);
double maxVal;
Point maxLoc;
minMaxLoc(fft1,NULL,&maxVal,NULL,&maxLoc);
resX = (maxLoc.x<width/2) ? (maxLoc.x) : (maxLoc.x-width);
resY = (maxLoc.y<height/2) ? (maxLoc.y) : (maxLoc.y-height);

Here is how I did it (and it worked properly):

1) Create 2 images (fft1 and fft2) according to getOptimalDFTSize().

int width = getOptimalDFTSize(max(image1.cols,image2.cols));
int height = getOptimalDFTSize(max(image1.rows,image2.rows));
Mat fft1(Size(width,height),CV_32F,Scalar(0));
Mat fft2(Size(width,height),CV_32F,Scalar(0));

2) Filled them with values from original images (image1 and image2).

3) Do the following calculations:

dft(fft1,fft1,0,image1.rows);
dft(fft2,fft2,0,image2.rows);
mulSpectrums(fft1,fft2,fft1,0,true);
idft(fft1,fft1);
double maxVal;
Point maxLoc;
minMaxLoc(fft1,NULL,&maxVal,NULL,&maxLoc);
resX = (maxLoc.x<width/2) ? (maxLoc.x) : (maxLoc.x-width);
resY = (maxLoc.y<height/2) ? (maxLoc.y) : (maxLoc.y-height);

Also your question is not about 'image stitching' but about a step done before that - 'image registration'. Title of your question is somewhat misleading.

Here is how I did it (and it worked properly):

1) Create 2 images (fft1 and fft2) according to getOptimalDFTSize().

int width = getOptimalDFTSize(max(image1.cols,image2.cols));
int height = getOptimalDFTSize(max(image1.rows,image2.rows));
Mat fft1(Size(width,height),CV_32F,Scalar(0));
Mat fft2(Size(width,height),CV_32F,Scalar(0));

2) Filled them with values from original images (image1 and image2).

3) Do the following calculations:

dft(fft1,fft1,0,image1.rows);
dft(fft2,fft2,0,image2.rows);
mulSpectrums(fft1,fft2,fft1,0,true);
idft(fft1,fft1);
double maxVal;
Point maxLoc;
minMaxLoc(fft1,NULL,&maxVal,NULL,&maxLoc);
resX = (maxLoc.x<width/2) ? (maxLoc.x) : (maxLoc.x-width);
resY = (maxLoc.y<height/2) ? (maxLoc.y) : (maxLoc.y-height);

Also your question is not about 'image stitching' but about a step done before that - 'image registration'. Title of your question is somewhat misleading.

Edit:

mrgloom, it is already almost full code. The only part I didn't posted yet is how I copied the data between the images. This is how I did it:

for(j=0; j<image1.rows; j++)
for(i=0; i<image1.cols; i++)
fft1.at<float>(j,i) = image1.at<unsigned char>(j,i);

for(j=0; j<image2.rows; j++)
for(i=0; i<image2.cols; i++)
fft2.at<float>(j,i) = image2.at<unsigned char>(j,i);

I didn't knew back than about functions like convertTo.