Ask Your Question

Revision history [back]

I don't know this function in opencv but you can try :

Mat x = imread("f:/lib/opencv/samples/data/lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat y = x(Rect(256,256,50,50));
imshow("Image ",x);
imshow("Sub Image ",y);
waitKey();

x = x - mean(x);
y = y - mean(y);
Mat xp,yp,xy;                            //expand input image to optimal size
int m = getOptimalDFTSize( max(x.rows,y.rows) );
int n = getOptimalDFTSize( max(x.cols,y.cols) ); // on the border add zero values
copyMakeBorder(x, xp, 0, m - x.rows, 0, n - x.cols, BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(y, yp, 0, m - y.rows, 0, n - y.cols, BORDER_CONSTANT, Scalar::all(0));
Mat xpf,ypf;
xp.convertTo(xpf,CV_32F);
yp.convertTo(ypf,CV_32F);
Mat XP,YP,XY;
dft(xpf,XP,DFT_COMPLEX_OUTPUT);
dft(ypf,YP,DFT_COMPLEX_OUTPUT);
mulSpectrums(XP,YP,XY,0,true);
idft(XY,xy,DFT_REAL_OUTPUT);
double s,t;
minMaxLoc(xy,&s,&t);
xy = xy / max(s,abs(t))*255;
Mat cxy;
xy.convertTo(cxy,CV_8S);
imshow("cxy",cxy );
waitKey();

I don't know this function in opencv but you can try :

Mat x = imread("f:/lib/opencv/samples/data/lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat y = x(Rect(256,256,50,50));
imshow("Image ",x);
imshow("Sub Image ",y);
waitKey();

x = x - mean(x);
y = y - mean(y);
Mat xp,yp,xy;                            //expand input image to optimal size
int m = getOptimalDFTSize( max(x.rows,y.rows) );
int n = getOptimalDFTSize( max(x.cols,y.cols) ); // on the border add zero values
copyMakeBorder(x, xp, 0, m - x.rows, 0, n - x.cols, BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(y, yp, 0, m - y.rows, 0, n - y.cols, BORDER_CONSTANT, Scalar::all(0));
Mat xpf,ypf;
xp.convertTo(xpf,CV_32F);
yp.convertTo(ypf,CV_32F);
xpf = xpf - mean(xpf);
ypf = ypf - mean(ypf);
Mat XP,YP,XY;
dft(xpf,XP,DFT_COMPLEX_OUTPUT);
dft(ypf,YP,DFT_COMPLEX_OUTPUT);
mulSpectrums(XP,YP,XY,0,true);
idft(XY,xy,DFT_REAL_OUTPUT);
double s,t;
minMaxLoc(xy,&s,&t);
xy = xy / max(s,abs(t))*255;
Mat cxy;
xy.convertTo(cxy,CV_8S);
imshow("cxy",cxy );
waitKey();

I don't know this Finally it is function in opencv but you can try :filter2d

Mat x = imread("f:/lib/opencv/samples/data/lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
Mat y = x(Rect(256,256,50,50));
imshow("Image ",x);
imshow("Sub Image ",y);
Mat xp,yp,xy;                            //expand input image to optimal size
int m = getOptimalDFTSize( max(x.rows,y.rows) );
int n = getOptimalDFTSize( max(x.cols,y.cols) ); // on the border add zero values
copyMakeBorder(x, xp, 0, m - x.rows, 0, n - x.cols, BORDER_CONSTANT, Scalar::all(0));
copyMakeBorder(y, yp, 0, m - y.rows, 0, n - y.cols, BORDER_CONSTANT, Scalar::all(0));
Mat xpf,ypf;
xp.convertTo(xpf,CV_32F);
yp.convertTo(ypf,CV_32F);
xpf = xpf - mean(xpf);
ypf = ypf - mean(ypf);
Mat XP,YP,XY;
dft(xpf,XP,DFT_COMPLEX_OUTPUT);
dft(ypf,YP,DFT_COMPLEX_OUTPUT);
mulSpectrums(XP,YP,XY,0,true);
idft(XY,xy,DFT_REAL_OUTPUT);
double s,t;
minMaxLoc(xy,&s,&t);
xy = xy / max(s,abs(t))*255;
Mat cxy;
xy.convertTo(cxy,CV_8S);
imshow("cxy",cxy );
waitKey();