-1

I am trying to apply fourier transform to an image, by following the code from link http://www.docs.opencv.org/2.4/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html , after this I am trying to remove the noise components which are visible in fourier spectrum as horizontal and vertical lines, like in this image shown in link below: (http://www.imagemagick.org/Usage/fourier/twigs_spectrum.png) - Spectrum image

Now after zeroing out the noise pixel locations in the spectrum, I just want to see how the original image is changed now. I have applied inverse DFT to it, and reconstructed the image also but the image is null image. Here is my code:

Mat magI_copy;
magI.copyTo(magI_copy);
//magI.convertTo(magI_copy, CV_8U);
//imshow("image", magI_copy); waitKey();
for (int i = 0; i < 86; i++){
    for (int j = 127; j < 130;j++){
        magI_copy.at<float>(i, j) = 0;
    }
}
for (int i = 171; i < magI_copy.rows; i++){
    for (int j = 127; j < 130; j++){
        magI_copy.at<float>(i, j) = 0;
    }
}
for (int i = 126; i < 131; i++){
    for (int j = 0; j < 87; j++){
        magI_copy.at<float>(i, j) = 0;
    }
}
for (int i = 126; i < 131; i++){
    for (int j = 170; j < magI_copy.cols; j++){
        magI_copy.at<float>(i, j) = 0;
    }
}
///////////Inverse Transform

cv::Mat inverseTransform;
cv::dft(magI_copy, inverseTransform, cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT);
normalize(inverseTransform, inverseTransform, 0, 1, CV_MINMAX);
Mat finalimage;
inverseTransform.convertTo(finalimage, CV_8U); 
Bala
  • 19
  • 4
  • @Miki my question is after applying IDFT, how can I reconstruct the image – Bala Jan 31 '17 at 15:25
  • Since you're normalizing the data between 0 and 1, I suppose you need to scale them to 0,255: `inverseTransform.convertTo(finalimage, CV_8U, 255); ` Note that in the linked answer there's no normalization, though. – Miki Jan 31 '17 at 15:30

1 Answers1

-1

Inverse DFT is what you need here. Here is the answer for your question.

Community
  • 1
  • 1
Leontyev Georgiy
  • 1,295
  • 11
  • 24