# Revision history [back]

### 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. ### 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. cv::Mat phase;
cv::Mat magI;
cv::Mat I;
cv::Mat output;
cv::Mat ampIm;
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++)
{

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 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 = Re(DFT(I), planes = Im(DFT(I))

cv::cartToPolar   (planes,planes,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;
}