【发布时间】:2017-04-19 06:56:45
【问题描述】:
我正在尝试为我预先应用离散傅里叶变换的图像实现逆离散傅里叶变换。输出是两种图像。一个图像在正确的位置,另一个是相反的位置。你能帮我解决这个问题吗?
这是我写的代码。
double inverseFourierReal = 0.0;
double inverseFourierImg = 0.0;
double degreeValue,cosValue,sinValue;
// double inverse = inverseFourier;
for(int rowm = 0; rowm < rows; rowm++ )
for(int coln = 0; coln < cols; coln++ ) {
inverseFourierImg = 0.0;
inverseFourierReal = 0.0;
for(int rowk = 0; rowk < rows; rowk++ ) {
for(int coll = 0; coll < cols; coll++ ) {
degreeValue = 2. * PI * (float(rowk*rowm)/rows + float(coll*coln)/cols);
cosValue = cos(degreeValue);
sinValue = sin(degreeValue);
inverseFourierReal += cosValue * fourierImageReal[rowk][coll] - sinValue * fourierImageImg[rowk][coll];
//inverseFourierImg += (cosValue * fourierImageImg[rowk][coll] + sinValue * fourierImageReal[rowk][coll]);
//cout<<inverseFourierReal;
}
}
invr_FourierReal.at<double>(rowm,coln) = abs((inverseFourierReal) / (sqrt(rows*cols)));
// invr_FourierReal.at<double>(rowm,coln) = double(inverseFourierReal) / (sqrt(rows*cols));
//invr_FourierImg.at<double>(int(rowm),int(coln)) = double(inverseFourierImg) / (sqrt(rows*cols));
}
你可以在这里看到输出图像:
编辑:
我已经更改了代码,您可以看到新的输出。它是颠倒的。
我使用 Lena 图像作为输入
P.S 对不起我的英语不好。
【问题讨论】:
-
当我们看不到您正在使用的代码部分时,我们如何提供帮助?最有可能与此类似的问题:Implementing 2D inverse fourier transform using 1D transforms
-
@Spektre 感谢您的回复。我添加了一段用于逆变换的代码
-
添加的答案至少我是这么看的。
-
我已经纠正了我的错误。你能看看新的输出吗
标签: c++ image opencv image-processing dft