Reputation: 57
I am trying implement inverse discrete Fourier transfrom for the image which i applied discrete Fourier transform beforehand. The output is kind of two images. One image is in correct position the other is reversed position. Could you help me to solve this issue?
Here is the code i have written.
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));
}
You can see the output image here:
Edit:
I have changed the code and you can see new output. it is upside down.
I used Lena image for the input
P.S sorry for my poor English.
Upvotes: 1
Views: 1446
Reputation: 51835
Weird mirrored blend
What is fourierFilterImg
? are you doing some kind of convolution instead of IDFT? Also hope invr_FourierReal
is not the same memory place as fourierImageReal
. My bet is that it is just a copy/paste typo so I would change this line:
inverseFourierReal += (cosValue * fourierImageReal[rowk][coll] - sinValue * fourierFilterImg[rowk][coll]);
To:
inverseFourierReal += cosValue * fourierImageReal[rowk][coll] - sinValue * fourierImageImg[rowk][coll];
Also I hope your input image is correctly DFT transformed and in complex domain.
[Edit1] inversion of X,Y
That can be just not the same counting of row,col
direction for DFT and IDFT somewhere. Images usually have Y
axis going down and X
axis going right. If it is just upside down then just invert the one that is wrong.
If the problem is in IDFT then just change:
invr_FourierReal.at<double>(rowm,coln)
to:
invr_FourierReal.at<double>(rows-rowm-1,cols-coln-1)
But my bet is that it is just inverted during loading or rendering and DFT/IDFT has nothing to do with this.
Upvotes: 0