Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

It took me several more hours but I have eventually solved the problem. There are two options

1) real-to-complex (CV_32FC1 -> CV_32FC2) forward and complex-to-real (CV_32FC2 -> CV_32FC1) inverse
As a result of the forward transform a narrower spectrum matrix is obtained (newWidth = oldWidth/2+1 as explained in documentation). It is not CSS compact matrix as in case of non-gpu dft. It is a complex matrix that uses the fact that frequency spectrum is symmetric. Hence any filter can also be applied here with the speed up from performing nearly half less multiplication than in the second case. In this case the following flags should be set: forward -> 0 inverse -> DFT_INVERSE | DFT_REAL_OUTPUT | DFT_SCALE This worked great for me. Remember to declare earlier properly the GpuMat used to their types (CV_32FC1 or CV_32FC2)

2) complex-to-complex (CV_32FC2 -> CV_32FC2) forward and complex-to-complex(CV_32FC2 -> CV_32FC2) inverse Full size spectrum (CV_32FC2) is produced in the forward DFT. In this case the flags are forward -> 0 inverse -> DFT_INVERSE The result of inverse transform is a complex matrix (CV_32FC2), hence you need to split it and extract the desired result from the zero channel. Later the data needs to be scaled explicitly:

double n,x;
minMaxIdx(imageAfterInverseDFT, &n, &x);
imageAfterInverseDFT.convertTo(imageAfterInverseDFT, CV_8U, 255.0/x);

As simple as that! I have no idea why I didn't come across this earlier. I decided to post it any way as someone out there might have the same problem or need some guidance.