Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to draw magnitude of spectrum. here is the code.</p> <pre><code>void ForwardFFT(Mat &amp;Src, Mat *FImg) { int M = getOptimalDFTSize( Src.rows ); int N = getOptimalDFTSize( Src.cols ); Mat padded; copyMakeBorder(Src, padded, 0, M - Src.rows, 0, N - Src.cols, BORDER_CONSTANT, Scalar::all(0)); // Создаем комплексное представление изображения // planes[0] содержит само изображение, planes[1] его мнимую часть (заполнено нулями) Mat planes[] = {Mat_&lt;float&gt;(padded), Mat::zeros(padded.size(), CV_32F)}; Mat complexImg; merge(planes, 2, complexImg); dft(complexImg, complexImg); // После преобразования результат так-же состоит из действительной и мнимой части split(complexImg, planes); // обрежем спектр, если у него нечетное количество строк или столбцов planes[0] = planes[0](Rect(0, 0, planes[0].cols &amp; -2, planes[0].rows &amp; -2)); planes[1] = planes[1](Rect(0, 0, planes[1].cols &amp; -2, planes[1].rows &amp; -2)); Recomb(planes[0],planes[0]); Recomb(planes[1],planes[1]); // Нормализуем спектр planes[0]/=float(M*N); planes[1]/=float(M*N); FImg[0]=planes[0].clone(); FImg[1]=planes[1].clone(); } void ForwardFFT_Mag_Phase(Mat &amp;src, Mat &amp;Mag,Mat &amp;Phase) { Mat planes[2]; ForwardFFT(src,planes); Mag.zeros(planes[0].rows,planes[0].cols,CV_32F); Phase.zeros(planes[0].rows,planes[0].cols,CV_32F); cv::cartToPolar(planes[0],planes[1],Mag,Phase); } Mat LogMag; LogMag.zeros(Mag.rows,Mag.cols,CV_32F); LogMag=(Mag+1); cv::log(LogMag,LogMag); //--------------------------------------------------- imshow("Логарифм амплитуды", LogMag); imshow("Фаза", Phase); imshow("Результат фильтрации", img); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload