//This program is for learning DFT.
//Version: VS2015 + OpenCV3.1.0
//Author: Bandary Wang
//Date: 2016/8/10
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace cv;
int main()
{
Mat srcImage = imread("1.jpg", 0);
if (!srcImage.data) { printf("There is something wrong when reading the image! \n"); return false; }
imshow("srcImage", srcImage);
//broaden the srcImage
int m = getOptimalDFTSize(srcImage.rows);
int n = getOptimalDFTSize(srcImage.cols);
Mat padded;
copyMakeBorder(srcImage, padded, 0, m - srcImage.rows, 0, n - srcImage.cols, BORDER_CONSTANT, Scalar::all(0));
//prepare some memory room for DFT
Mat planes[] = { Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F) };
Mat complexI;
merge(planes, 2, complexI);
//DFT
dft(complexI, complexI);
//把复数转变为幅值
split(complexI, planes);
magnitude(planes[0], planes[1], planes[0]);
Mat magnitudeImage = planes[