Fast fourier higest three magnitudes

asked 2017-05-31 10:16:24 -0500

raymond gravatar image

updated 2017-05-31 10:17:33 -0500

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 planes[] = { Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F) };
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 :

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 flag offensive close merge delete