Absolute Value of the DFT with OpenCV in C++

I am trying to compute the DFT in C++ with OpenCV. I want the absolute value of the DFT. To compute it I do:

vector<float> areas, X_mag; 
cv::Mat X;

...

cv::dft(areas, X, cv::DFT_COMPLEX_OUTPUT);

areas is a 50×1 vector, and I want to store the absolute value of the DFT of areas in X_mag

The problem, is that I think there is no way to compute directly the absolute value, and I didn’t find any function that computes directly the absolute.

I tried to use absdiff: cv::absdiff(X, cv::Scalar::all(0), X_mag);, but it only works if I use a std::vector instead of the cv::Mat.

If I don’t use the DFT_COMPLEX_OUTPUT, I get only the real part, so is not what I need.

I was thinking on computing manually the absolute value (sqrt(Re(X)^2 + Im(X)^2), but I think it would be too slow, and I don’t think that cv::Mat was thought to be iterated this way.

How could I get my 50×1 DFT’s absolute value vector?

Answer

As @Christoph Rackwitz said, we can use split and magnitude.

vector<float> areas, X_abs;
Mat X;
Mat X_mag[2];

...

cv::dft(areas, X, cv::DFT_COMPLEX_OUTPUT);
cv::split(X, X_mag);
cv::magnitude(X_mag[0], X_mag[1], X_abs);

And we will have the absolute value vector in X_abs.