[英]CImg - Get inverse FFT of an image
我正在嘗試實現頻譜方法來計算圖像的顯着性圖,但是我似乎無法使逆FFT正常工作。
int main(int argc, char * argv[]) {
const char * input_file = "img/pic.png";
CImg<unsigned char> * input = new CImg<unsigned char>(input_file);
resize_fft(*input); //Resize the image for the FFT
CImg<unsigned char> gray = any2gray(*input); //to single-channel grayscale image
free(input);
CImgList<unsigned char> fft = gray.get_FFT();
CImg<unsigned char>::FFT(fft[0], fft[1], true);
fft[0].save("img/fft.png");
return 1;
}
最后,fft.png只是一個黑色圖像文件。 我找不到任何人使用CImg計算逆fft的示例...有人有任何線索嗎?
非常感謝 ! 知更鳥
對於寬范圍的圖像可能出現的一個常見問題是,圖像的FFT無法用有限范圍的unsigned char
來表示(或散布了太多信息以至於無法實際使用)。 您可以通過對中間float
圖像執行FFT計算來避免這種情況:
// convert from unsigned char to float to support larger range of values
CImg<float> fft_in = gray;
// Forward transform
CImgList<float> fft = fft_in .get_FFT();
// Inverse transform
CImg<float>::FFT(fft[0], fft[1], true);
// Normalize back to unsigned char range (0,255) and save
fft[0].normalize(0,255).save("img/fft.png");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.