Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

FFT at 3D Mat

Hello, I want to computing FFT at 3D matin C++: I have n images that I want to calculate FFT at z axe for each pixel(x,y), and as a result the n images of amplitude and phase... but I have no idea how to make that please help me. image description

FFT at 3D Mat

Hello, I want to computing FFT at 3D matin C++: I have n images that I want to calculate FFT at z axe for each pixel(x,y), and as a result the n images of amplitude and phase... but I have no idea how to make that please help me. image description

cv::Mat phase;
 cv::Mat magI;
 cv::Mat I;
 cv::Mat padded;
 cv::Mat output;     
  cv::Mat ampIm; 
  I = imread(liste[0].toStdString().c_str(), CV_LOAD_IMAGE_GRAYSCALE);
 int rows=I.rows;
 int cols=I.cols;

 for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
     for(int k=0;k<liste.size();k++)
      {

        I = imread(liste[k].toStdString().c_str(), CV_LOAD_IMAGE_GRAYSCALE);
       Vec3b color = I.at<Vec3b>(Point(i,j));
        output.at<Vec3b>(Point(j+i*(rows-1),k))=color;


    }
    }
   }

   int m = cv::getOptimalDFTSize(output.rows );
  int n = getOptimalDFTSize( output.cols ); // on the border add zero values
  cv::copyMakeBorder(output, padded, 0, m - output.rows, 0, n - output.cols, BORDER_CONSTANT, Scalar::all(0));

cv::Mat planes[] = {Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F)};
cv::Mat complexI;
merge(planes, 2, complexI);         // Add to the expanded another plane with zeros

dft(complexI, complexI,cv::DFT_ROWS|cv::DFT_COMPLEX_OUTPUT);            // this way the result may fit in the        source matrix


split(complexI, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))



  cv::cartToPolar   (planes[0],planes[1],magI,phase,true);
     magI += Scalar::all(1);                    // switch to logarithmic scale
        log(magI, magI);

     for(int k=0;k<liste.size();k++){
    for(int i=0;i<rows;i++){
     for(int j=0;j<cols;j++){
     Vec3b colorF =magI.at<Vec3b>(Point(j+i*(rows-1),k));
    ampIm.at<Vec3b>(Point(i,j))=colorF;
}
}     
   //save ampIm;
}