Fourier.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // C++ Implementation: Fourier
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: Michael Koch <Koch.Michael@uni-jena.de>, (C) 2009
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. /**
  12. * @file Fourier.cpp
  13. * @brief Fourier
  14. * @author Michael Koch
  15. * @date Fr Jul 24 2009
  16. */
  17. // #define DEBUG
  18. #undef DEBUG
  19. //normal includes
  20. #include "Fourier.h"
  21. //IF ICE is available TODO REPLACE BY FFTW DIRECTLY
  22. #ifdef NICE_USELIB_ICE
  23. #include "core/iceconversion/image_convertice.h"
  24. #include <image_nonvis.h>
  25. using namespace NICE;
  26. void Fourier::FourierTransform(NICE::FloatImage &space_real, NICE::FloatImage &space_imag, NICE::FloatImage &freq_real, NICE::FloatImage &freq_imag)
  27. {
  28. #ifdef NICE_USELIB_ICE
  29. if (space_real.width() != space_imag.width() || space_real.height() != space_imag.height())
  30. {
  31. fthrow(ImageException, "Fourier_FourierTransform: Image Dimension do not agree.");
  32. }
  33. else
  34. {
  35. freq_real.resize(space_real.width(), space_real.height());
  36. freq_imag.resize(space_real.width(), space_real.height());
  37. freq_real.set(0);
  38. freq_imag.set(0);
  39. //create ICE Images
  40. ice::ImageD space_realD, space_imagD, freq_realD, freq_imagD;
  41. space_realD = NICE::createIceImageD(space_real);
  42. space_imagD = NICE::createIceImageD(space_imag);
  43. freq_realD=NICE::createIceImageD(freq_real);
  44. freq_imagD=NICE::createIceImageD(freq_imag);
  45. //Fourier Transform and store results
  46. ice::FourierImgD(space_realD, space_imagD, 15, freq_realD, freq_imagD);
  47. NICE::copyFloatImage(freq_realD, freq_real);
  48. NICE::copyFloatImage(freq_imagD, freq_imag);
  49. FreeImgD(space_realD);FreeImgD(space_imagD);FreeImgD(freq_realD);FreeImgD(freq_imagD);
  50. }
  51. #else
  52. fthrow(ImageException, "ICE essential, TODO: Change to FFTW directly");
  53. #endif
  54. }
  55. void Fourier::FourierTransformInverse(NICE::FloatImage &freq_real, NICE::FloatImage &freq_imag, NICE::FloatImage &space_real, NICE::FloatImage &space_imag)
  56. {
  57. #ifdef NICE_USELIB_ICE
  58. if (freq_real.width() != freq_imag.width() || freq_real.height() != freq_imag.height())
  59. {
  60. fprintf(stderr, "Fourier_FourierTransformInverse: Image Dimension must agree!\n");
  61. fthrow(ImageException, "Fourier_FourierTransformInverse: Image Dimension do not agree.");
  62. }
  63. else
  64. {
  65. space_real.resize(freq_real.width(), freq_real.height());
  66. space_imag.resize(freq_real.width(), freq_real.height());
  67. space_real.set(0);
  68. space_imag.set(0);
  69. //create ICE Images
  70. ice::ImageD space_realD, space_imagD, freq_realD, freq_imagD;
  71. space_realD = NICE::createIceImageD(space_real);
  72. space_imagD = NICE::createIceImageD(space_imag);
  73. freq_realD = NICE::createIceImageD(freq_real);
  74. freq_imagD = NICE::createIceImageD(freq_imag);
  75. //Fourier Transform Inverse and store results
  76. ice::FourierImgD(freq_realD, freq_imagD,16,space_realD, space_imagD );
  77. NICE::copyFloatImage(space_realD, space_real);
  78. NICE::copyFloatImage(space_imagD, space_imag);
  79. FreeImgD(space_realD);FreeImgD(space_imagD);FreeImgD(freq_realD);FreeImgD(freq_imagD);
  80. }
  81. #else
  82. fthrow(ImageException, "ICE essential, TODO: Change to FFTW directly");
  83. #endif
  84. }
  85. void Fourier::CrossCorrelation(const NICE::FloatImage &img1, const NICE::FloatImage &img2, NICE::FloatImage &cc)
  86. {
  87. #ifdef NICE_USELIB_ICE
  88. if (img1.width() != img2.width() || img1.height() != img2.height())
  89. {
  90. fprintf(stderr, "Fourier_CrossCorrelation: Image Dimension must agree!\n");
  91. fthrow(ImageException, "Fourier_CrossCorrelation: Image Dimension do not agree.");
  92. }
  93. else
  94. {
  95. //create ICE Images
  96. ice::ImageD img1D, img2D,ccD;
  97. img1D=NICE::createIceImageD(img1);
  98. img2D=NICE::createIceImageD(img2);
  99. ccD=ice::NewImgD(img1.width(),img1.height());
  100. CrossCorrelationImgD(img1D,img2D,ccD);
  101. NICE::copyFloatImage(ccD,cc);
  102. FreeImgD(img1D);FreeImgD(img2D);FreeImgD(ccD);
  103. }
  104. #else
  105. fthrow(ImageException, "ICE essential, TODO: Change to FFTW directly");
  106. #endif
  107. }
  108. #endif