# Fast fourier higest three magnitudes

i am trying to build a classifier using the fast Fourier as a feature for my image so the steps must be as following: 1-get the FFT coefficients

2-get the three highest magnitudes.

3-pass the highest magnitudes to a neural network classifier or k-nearest neighbor algorithm ,

the idea is that i don't know whether to use the coefficients or magnitudes , but any how here is the code i followed

Mat padded;                            //expand input image to optimal size
int m = getOptimalDFTSize(vertical.rows);
int n = getOptimalDFTSize(vertical.cols); // on the border add zero values
copyMakeBorder(vertical , padded, 0, m - vertical.rows, 0, n - vertical.cols, BORDER_CONSTANT, Scalar::all(0));

Mat complexI;
merge(planes, 2, complexI);         // Add to the expanded another plane with zeros

dft(complexI, complexI);            // this way the result may fit in the source matrix
split(complexI, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
Mat magI = planes[0];


where Vertical is the required processed image

ComplexI i guess is the FFT coefficients

MagI is the Magnitude

generally when using Matlab i would do :

F=fft2(src);
magnitude= abs(F);
sorted_mag = sort(magnitude , 'descend')
threehighest = sorted_mag(1:3);


then get these threehighest , put them into a vector and apply nearest neighbor.

but hey that's matlab , so how do i implement this idea and code it in opencv c++ ??

please explain the concept behind the magnitude and how the dft is splited into planes ...

edit retag close merge delete