r331: *** empty log message ***
authorKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 2 Jan 2001 07:18:07 +0000 (07:18 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Tue, 2 Jan 2001 07:18:07 +0000 (07:18 +0000)
libctsim/imagefile.cpp

index 0cbd67826ae194750b64cb8df9a70f3dbbdaeeac..0b7eb8192f94690020e16dc0135c5f1e1c3b949c 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: imagefile.cpp,v 1.29 2001/01/02 05:34:57 kevin Exp $
+**  $Id: imagefile.cpp,v 1.30 2001/01/02 07:18:07 kevin Exp $
 **
 **  This program is free software; you can redistribute it and/or modify
 **  it under the terms of the GNU General Public License (version 2) as
@@ -88,7 +88,7 @@ ImageFile::filterResponse (const char* const domainName, double bw, const char*
 {\r
   ImageFileArray v = getArray();\r
   SignalFilter filter (filterName, domainName, bw, filt_param);\r
-\r
+  \r
 #if 1\r
   int iXCenter, iYCenter;\r
   if (isEven (m_nx))\r
@@ -99,24 +99,24 @@ ImageFile::filterResponse (const char* const domainName, double bw, const char*
     iYCenter = m_ny / 2;\r
   else\r
     iYCenter = (m_ny - 1) / 2;\r
-\r
-  for (int ix = 0; ix < m_nx; ix++)\r
-    for (int iy = 0; iy < m_ny; iy++) {\r
+  \r
+  for (unsigned int ix = 0; ix < m_nx; ix++)\r
+    for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       long lD2 = ((ix - iXCenter) * (ix - iXCenter)) + ((iy - iYCenter) * (iy - iYCenter));\r
       double r = ::sqrt (static_cast<double>(lD2)) * dInputScale;\r
       v[ix][iy] = filter.response (r) * dOutputScale;\r
     }\r
 #else
-  int hx = (m_nx - 1) / 2;
-  int hy = (m_ny - 1) / 2;
-  
-  for (int i = -hx; i <= hx; i++) {
-    for (int j = -hy; j <= hy; j++) {
-      double r = ::sqrt (i * i + j * j);
-      
-      v[i+hx][j+hy] = filter.response (r);
-    }
-  }\r
+    int hx = (m_nx - 1) / 2;
+    int hy = (m_ny - 1) / 2;
+    
+    for (int i = -hx; i <= hx; i++) {
+      for (int j = -hy; j <= hy; j++) {
+        double r = ::sqrt (i * i + j * j);
+        
+        v[i+hx][j+hy] = filter.response (r);
+      }
+    }\r
 #endif
 }
 
@@ -387,7 +387,7 @@ ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const
   \r
   if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArrayConst vRHS = rRHS.getArray();\r
@@ -407,7 +407,7 @@ ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const
       }\r
     }\r
   }\r
-    \r
+  \r
   return true;\r
 }\r
 
@@ -421,7 +421,7 @@ ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const
   \r
   if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArrayConst vRHS = rRHS.getArray();\r
@@ -455,7 +455,7 @@ ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const
   \r
   if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArrayConst vRHS = rRHS.getArray();\r
@@ -466,12 +466,14 @@ ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const
   for (unsigned int ix = 0; ix < m_nx; ix++) {\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
+        double dImag = 0;\r
         if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
-        std::complex<double> cRHS (vRHS[ix][iy], 0);\r
+          dImag = vLHSImag[ix][iy];\r
+        std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
+        dImag = 0;\r
         if (rRHS.isComplex())\r
-          cRHS.imag (vRHSImag[ix][iy]);\r
+          dImag = vRHSImag[ix][iy];\r
+        std::complex<double> cRHS (vRHS[ix][iy], dImag);\r
         std::complex<double> cResult = cLHS * cRHS;\r
         vResult[ix][iy] = cResult.real();\r
         vResultImag[ix][iy] = cResult.imag();\r
@@ -494,7 +496,7 @@ ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const
   \r
   if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArrayConst vRHS = rRHS.getArray();\r
@@ -505,12 +507,14 @@ ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const
   for (unsigned int ix = 0; ix < m_nx; ix++) {\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
+        double dImag = 0;\r
         if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
-        std::complex<double> cRHS (vRHS[ix][iy], 0);\r
+          dImag = vLHSImag[ix][iy];\r
+        std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
+        dImag = 0;\r
         if (rRHS.isComplex())\r
-          cRHS.imag (vRHSImag[ix][iy]);\r
+          dImag = vRHSImag[ix][iy];\r
+        std::complex<double> cRHS (vRHS[ix][iy], dImag);\r
         std::complex<double> cResult = cLHS / cRHS;\r
         vResult[ix][iy] = cResult.real();\r
         vResultImag[ix][iy] = cResult.imag();\r
@@ -523,7 +527,6 @@ ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const
     }\r
   }\r
   \r
-  \r
   return true;\r
 }\r
 \r
@@ -538,7 +541,7 @@ ImageFile::invertPixelValues (ImageFile& result) const
   \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArray vResult = result.getArray();\r
   \r
@@ -559,7 +562,7 @@ ImageFile::sqrt (ImageFile& result) const
     sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
     return false;\r
   }\r
-\r
+  \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
   \r
@@ -573,27 +576,28 @@ ImageFile::sqrt (ImageFile& result) const
           bComplexOutput = true;\r
           break;\r
         }\r
-\r
-  ImageFileArrayConst vLHSImag = getImaginaryArray();\r
-  ImageFileArray vResult = result.getArray();\r
-  ImageFileArray vResultImag = result.getImaginaryArray();\r
-  \r
-  for (unsigned int ix = 0; ix < m_nx; ix++) {\r
-    for (unsigned int iy = 0; iy < m_ny; iy++) {\r
-      if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
-        if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
-        std::complex<double> cResult = std::sqrt(cLHS);\r
-        vResult[ix][iy] = cResult.real();\r
-        vResultImag[ix][iy] = cResult.imag();\r
-      } else\r
-        vResult[ix][iy] = ::sqrt (vLHS[ix][iy]);\r
-    }\r
-  }\r
-  \r
-  \r
-  return true;\r
+        \r
+        ImageFileArrayConst vLHSImag = getImaginaryArray();\r
+        ImageFileArray vResult = result.getArray();\r
+        ImageFileArray vResultImag = result.getImaginaryArray();\r
+        \r
+        for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+          for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+            if (result.isComplex()) {\r
+              double dImag = 0;\r
+              if (isComplex())\r
+                dImag = vLHSImag[ix][iy];\r
+              std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
+              std::complex<double> cResult = std::sqrt(cLHS);\r
+              vResult[ix][iy] = cResult.real();\r
+              vResultImag[ix][iy] = cResult.imag();\r
+            } else\r
+              vResult[ix][iy] = ::sqrt (vLHS[ix][iy]);\r
+          }\r
+        }\r
+        \r
+        \r
+        return true;\r
 }\r
 \r
 bool\r
@@ -606,7 +610,7 @@ ImageFile::log (ImageFile& result) const
   \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArray vResult = result.getArray();\r
@@ -615,9 +619,10 @@ ImageFile::log (ImageFile& result) const
   for (unsigned int ix = 0; ix < m_nx; ix++) {\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
+        double dImag = 0;\r
         if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
+          dImag = vLHSImag[ix][iy];\r
+        std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
         std::complex<double> cResult = std::log (cLHS);\r
         vResult[ix][iy] = cResult.real();\r
         vResultImag[ix][iy] = cResult.imag();\r
@@ -637,10 +642,10 @@ ImageFile::exp (ImageFile& result) const
     sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
     return false;\r
   }\r
-    \r
+  \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArray vResult = result.getArray();\r
@@ -649,9 +654,10 @@ ImageFile::exp (ImageFile& result) const
   for (unsigned int ix = 0; ix < m_nx; ix++) {\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
+        double dImag = 0;\r
         if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
+          dImag = vLHSImag[ix][iy];\r
+        std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
         std::complex<double> cResult = std::exp (cLHS);\r
         vResult[ix][iy] = cResult.real();\r
         vResultImag[ix][iy] = cResult.imag();\r
@@ -671,13 +677,13 @@ ImageFile::scaleImage (ImageFile& result) const
   unsigned int ny = m_ny;\r
   unsigned int newNX = result.nx();\r
   unsigned int newNY = result.ny();\r
-\r
+  \r
   double dXScale = static_cast<double>(newNX) / static_cast<double>(nx);\r
   double dYScale = static_cast<double>(newNY) / static_cast<double>(ny);\r
-\r
+  \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vReal = getArray();\r
   ImageFileArrayConst vImag = getImaginaryArray();\r
   ImageFileArray vResult = result.getArray();\r
@@ -685,14 +691,32 @@ ImageFile::scaleImage (ImageFile& result) const
   \r
   for (unsigned int ix = 0; ix < newNX; ix++) {\r
     for (unsigned int iy = 0; iy < newNY; iy++) {\r
-      unsigned int scaleNX = static_cast<unsigned int> (ix / dXScale);\r
-      unsigned int scaleNY = static_cast<unsigned int> (iy / dYScale);\r
-      vResult[ix][iy] = vReal[scaleNX][scaleNY];\r
-      if (result.isComplex()) {\r
-        if (isComplex())\r
-          vResultImag[ix][iy] = vImag[scaleNX][scaleNY];\r
-        else\r
-        vResultImag[ix][iy] = 0;\r
+      double dXPos = ix / dXScale;\r
+      double dYPos = iy / dYScale;\r
+      unsigned int scaleNX = static_cast<unsigned int> (dXPos);\r
+      unsigned int scaleNY = static_cast<unsigned int> (dYPos);\r
+      double dXFrac = dXPos - scaleNX;\r
+      double dYFrac = dYPos - scaleNY;\r
+      if (scaleNX >= nx - 1 || scaleNY >= ny - 1) {\r
+        vResult[ix][iy] = vReal[scaleNX][scaleNY];\r
+        if (result.isComplex()) {\r
+          if (isComplex())\r
+            vResultImag[ix][iy] = vImag[scaleNX][scaleNY];\r
+          else\r
+            vResultImag[ix][iy] = 0;\r
+        }\r
+      } else {\r
+        vResult[ix][iy] = vReal[scaleNX][scaleNY] + \r
+          dXFrac * (vReal[scaleNX+1][scaleNY] - vReal[scaleNX][scaleNY]) + \r
+          dYFrac * (vReal[scaleNX][scaleNY+1] - vReal[scaleNX][scaleNY]);\r
+        if (result.isComplex()) {\r
+          if (isComplex())\r
+            vResultImag[ix][iy] = vImag[scaleNX][scaleNY] + \r
+            dXFrac * (vImag[scaleNX+1][scaleNY] - vImag[scaleNX][scaleNY]) + \r
+            dYFrac * (vImag[scaleNX][scaleNY+1] - vImag[scaleNX][scaleNY]);\r
+          else\r
+            vResultImag[ix][iy] = 0;\r
+        }\r
       }\r
     }\r
   }\r
@@ -708,17 +732,17 @@ ImageFile::fft (ImageFile& result) const
     sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
     return false;\r
   }\r
-\r
+  \r
   if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
     if (! result.convertRealToComplex ())\r
       return false;\r
   }\r
-\r
+  \r
   fftw_complex* in = new fftw_complex [m_nx * m_ny];\r
-\r
+  \r
   ImageFileArrayConst vReal = getArray();\r
   ImageFileArrayConst vImag = getImaginaryArray();\r
-\r
+  \r
   unsigned int ix, iy;\r
   unsigned int iArray = 0;\r
   for (ix = 0; ix < m_nx; ix++)\r
@@ -730,29 +754,29 @@ ImageFile::fft (ImageFile& result) const
         in[iArray].im = 0;\r
       iArray++;\r
     }\r
-\r
-  fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_FORWARD, FFTW_IN_PLACE);\r
-\r
-  fftwnd_one (plan, in, NULL);\r
-\r
-  ImageFileArray vRealResult = result.getArray();\r
-  ImageFileArray vImagResult = result.getImaginaryArray();\r
-  iArray = 0;\r
-  unsigned int iScale = m_nx * m_ny;\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      vRealResult[ix][iy] = in[iArray].re / iScale;\r
-      vImagResult[ix][iy] = in[iArray].im / iScale;\r
-      iArray++;\r
-    }\r
-\r
-  fftwnd_destroy_plan (plan);\r
-  delete in;\r
-\r
-\r
-  Fourier::shuffleFourierToNaturalOrder (result);\r
-\r
-  return true;\r
+    \r
+    fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_FORWARD, FFTW_IN_PLACE);\r
+    \r
+    fftwnd_one (plan, in, NULL);\r
+    \r
+    ImageFileArray vRealResult = result.getArray();\r
+    ImageFileArray vImagResult = result.getImaginaryArray();\r
+    iArray = 0;\r
+    unsigned int iScale = m_nx * m_ny;\r
+    for (ix = 0; ix < m_nx; ix++)\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        vRealResult[ix][iy] = in[iArray].re / iScale;\r
+        vImagResult[ix][iy] = in[iArray].im / iScale;\r
+        iArray++;\r
+      }\r
+      \r
+      fftwnd_destroy_plan (plan);\r
+      delete in;\r
+      \r
+      \r
+      Fourier::shuffleFourierToNaturalOrder (result);\r
+      \r
+      return true;\r
 }\r
 \r
 \r
@@ -763,12 +787,12 @@ ImageFile::ifft (ImageFile& result) const
     sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
     return false;\r
   }\r
-\r
+  \r
   if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
     if (! result.convertRealToComplex ())\r
       return false;\r
   }\r
-\r
+  \r
   ImageFileArrayConst vReal = getArray();\r
   ImageFileArrayConst vImag = getImaginaryArray();\r
   ImageFileArray vRealResult = result.getArray();\r
@@ -782,41 +806,41 @@ ImageFile::ifft (ImageFile& result) const
       else\r
         vImagResult[ix][iy] = 0;\r
     }\r
-\r
-  Fourier::shuffleNaturalToFourierOrder (result);\r
-\r
-  fftw_complex* in = new fftw_complex [m_nx * m_ny];\r
-\r
-  unsigned int iArray = 0;\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      in[iArray].re = vRealResult[ix][iy];\r
-      in[iArray].im = vImagResult[ix][iy];\r
-      iArray++;\r
-    }\r
-\r
-  fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_BACKWARD, FFTW_IN_PLACE);\r
-\r
-  fftwnd_one (plan, in, NULL);\r
-\r
-  iArray = 0;\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      vRealResult[ix][iy] = in[iArray].re;\r
-      vImagResult[ix][iy] = in[iArray].im;\r
-      iArray++;\r
-    }\r
-\r
-  fftwnd_destroy_plan (plan);\r
-\r
-  delete in;\r
-\r
-  return true;\r
+    \r
+    Fourier::shuffleNaturalToFourierOrder (result);\r
+    \r
+    fftw_complex* in = new fftw_complex [m_nx * m_ny];\r
+    \r
+    unsigned int iArray = 0;\r
+    for (ix = 0; ix < m_nx; ix++)\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        in[iArray].re = vRealResult[ix][iy];\r
+        in[iArray].im = vImagResult[ix][iy];\r
+        iArray++;\r
+      }\r
+      \r
+      fftwnd_plan plan = fftw2d_create_plan (m_nx, m_ny, FFTW_BACKWARD, FFTW_IN_PLACE);\r
+      \r
+      fftwnd_one (plan, in, NULL);\r
+      \r
+      iArray = 0;\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        for (iy = 0; iy < m_ny; iy++) {\r
+          vRealResult[ix][iy] = in[iArray].re;\r
+          vImagResult[ix][iy] = in[iArray].im;\r
+          iArray++;\r
+        }\r
+        \r
+        fftwnd_destroy_plan (plan);\r
+        \r
+        delete in;\r
+        \r
+        return true;\r
 }\r
 #endif // HAVE_FFTW\r
 \r
 \r
-  \r
+\r
 bool\r
 ImageFile::fourier (ImageFile& result) const\r
 {\r
@@ -828,70 +852,69 @@ ImageFile::fourier (ImageFile& result) const
   if (! result.isComplex())\r
     if (! result.convertRealToComplex ())\r
       return false;\r
-  \r
-  ImageFileArrayConst vLHS = getArray();\r
-  ImageFileArrayConst vLHSImag = getImaginaryArray();\r
-  ImageFileArray vRealResult = result.getArray();\r
-  ImageFileArray vImagResult = result.getImaginaryArray();\r
-  \r
-  unsigned int ix, iy;\r
-\r
-  // alloc output matrix\r
-  CTSimComplex** complexOut = new CTSimComplex* [m_nx];\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    complexOut[ix] = new CTSimComplex [m_ny];\r
-  \r
-  // fourier each x column\r
+    \r
+    ImageFileArrayConst vLHS = getArray();\r
+    ImageFileArrayConst vLHSImag = getImaginaryArray();\r
+    ImageFileArray vRealResult = result.getArray();\r
+    ImageFileArray vImagResult = result.getImaginaryArray();\r
+    \r
+    unsigned int ix, iy;\r
+    \r
+    // alloc output matrix\r
+    CTSimComplex** complexOut = new CTSimComplex* [m_nx];\r
+    for (ix = 0; ix < m_nx; ix++)\r
+      complexOut[ix] = new CTSimComplex [m_ny];\r
+    \r
+    // fourier each x column\r
 #if 1\r
-  CTSimComplex* pY = new CTSimComplex [m_ny];\r
-  for (ix = 0; ix < m_nx; ix++) {\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      pY[iy].real (vLHS[ix][iy]);\r
-      if (isComplex())\r
-        pY[iy].imag (vLHSImag[ix][iy]);\r
-      else\r
-        pY[iy].imag (0);\r
-    } \r
-    ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny,  ProcessSignal::FORWARD);\r
-  }\r
+    CTSimComplex* pY = new CTSimComplex [m_ny];\r
+    for (ix = 0; ix < m_nx; ix++) {\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        double dImag = 0;\r
+        if (isComplex())\r
+          dImag = vLHSImag[ix][iy];\r
+        pY[iy] = complex<double>(vLHS[ix][iy], dImag);\r
+      } \r
+      ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny,  ProcessSignal::FORWARD);\r
+    }\r
 #else\r
-  double* pY = new double [m_ny];\r
-  for (ix = 0; ix < m_nx; ix++) {\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      pY[iy] = vLHS[ix][iy];\r
-    } \r
-    ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny,  ProcessSignal::FORWARD);\r
-  }\r
+    double* pY = new double [m_ny];\r
+    for (ix = 0; ix < m_nx; ix++) {\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        pY[iy] = vLHS[ix][iy];\r
+      \r
+      ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny,  ProcessSignal::FORWARD);\r
+    }\r
 #endif\r
-  delete [] pY;\r
-  \r
-  // fourier each y row\r
-  CTSimComplex* pX = new CTSimComplex [m_nx];\r
-  CTSimComplex* complexOutRow = new CTSimComplex [m_nx];\r
-  for (iy = 0; iy < m_ny; iy++) {\r
-    for (ix = 0; ix < m_nx; ix++)\r
-      pX[ix] = complexOut[ix][iy];\r
-    ProcessSignal::finiteFourierTransform (pX, complexOutRow, m_nx, ProcessSignal::FORWARD);\r
-    for (ix = 0; ix < m_nx; ix++)\r
-      complexOut[ix][iy] = complexOutRow[ix];\r
-  }\r
-  delete [] pX;\r
-  delete [] complexOutRow;\r
-\r
-  for (ix = 0; ix < m_nx; ix++)\r
+    delete [] pY;\r
+    \r
+    // fourier each y row\r
+    CTSimComplex* pX = new CTSimComplex [m_nx];\r
+    CTSimComplex* complexOutRow = new CTSimComplex [m_nx];\r
     for (iy = 0; iy < m_ny; iy++) {\r
-      vRealResult[ix][iy] = complexOut[ix][iy].real();\r
-      vImagResult[ix][iy] = complexOut[ix][iy].imag();\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        pX[ix] = complexOut[ix][iy];\r
+      ProcessSignal::finiteFourierTransform (pX, complexOutRow, m_nx, ProcessSignal::FORWARD);\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        complexOut[ix][iy] = complexOutRow[ix];\r
     }\r
+    delete [] pX;\r
+    delete [] complexOutRow;\r
     \r
-  Fourier::shuffleFourierToNaturalOrder (result);\r
-\r
-  // delete complexOut matrix\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    delete [] complexOut[ix];\r
-  delete [] complexOut;\r
-    \r
-  return true;\r
+    for (ix = 0; ix < m_nx; ix++)\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        vRealResult[ix][iy] = complexOut[ix][iy].real();\r
+        vImagResult[ix][iy] = complexOut[ix][iy].imag();\r
+      }\r
+      \r
+      Fourier::shuffleFourierToNaturalOrder (result);\r
+      \r
+      // delete complexOut matrix\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        delete [] complexOut[ix];\r
+      delete [] complexOut;\r
+      \r
+      return true;\r
 }\r
 \r
 bool\r
@@ -917,7 +940,7 @@ ImageFile::inverseFourier (ImageFile& result) const
   CTSimComplex** complexOut = new CTSimComplex* [m_nx];\r
   for (ix = 0; ix < m_nx; ix++)\r
     complexOut[ix] = new CTSimComplex [m_ny];\r
-\r
+  \r
   // put input image into result\r
   for (ix = 0; ix < m_nx; ix++)\r
     for (iy = 0; iy < m_ny; iy++) {\r
@@ -927,45 +950,44 @@ ImageFile::inverseFourier (ImageFile& result) const
       else\r
         vImagResult[ix][iy] = 0;\r
     }\r
-\r
-  Fourier::shuffleNaturalToFourierOrder (result);\r
-\r
-  // ifourier each x column\r
-  CTSimComplex* pCol = new CTSimComplex [m_ny];\r
-  for (ix = 0; ix < m_nx; ix++) {\r
-    for (iy = 0; iy < m_ny; iy++) {\r
-      pCol[iy].real (vRealResult[ix][iy]);\r
-      pCol[iy].imag (vImagResult[ix][iy]);\r
+    \r
+    Fourier::shuffleNaturalToFourierOrder (result);\r
+    \r
+    // ifourier each x column\r
+    CTSimComplex* pCol = new CTSimComplex [m_ny];\r
+    for (ix = 0; ix < m_nx; ix++) {\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        pCol[iy] = std::complex<double> (vRealResult[ix][iy], vImagResult[ix][iy]);\r
+      }\r
+      ProcessSignal::finiteFourierTransform (pCol, complexOut[ix], m_ny,  ProcessSignal::BACKWARD);\r
     }\r
-    ProcessSignal::finiteFourierTransform (pCol, complexOut[ix], m_ny,  ProcessSignal::BACKWARD);\r
-  }\r
-  delete [] pCol;\r
-\r
-  // ifourier each y row\r
-  CTSimComplex* complexInRow = new CTSimComplex [m_nx];\r
-  CTSimComplex* complexOutRow = new CTSimComplex [m_nx];\r
-  for (iy = 0; iy < m_ny; iy++) {\r
-    for (ix = 0; ix < m_nx; ix++)\r
-      complexInRow[ix] = complexOut[ix][iy];\r
-    ProcessSignal::finiteFourierTransform (complexInRow, complexOutRow, m_nx, ProcessSignal::BACKWARD);\r
-    for (ix = 0; ix < m_nx; ix++)\r
-      complexOut[ix][iy] = complexOutRow[ix];\r
-  }\r
-  delete [] complexInRow;\r
-  delete [] complexOutRow;\r
-\r
-  for (ix = 0; ix < m_nx; ix++)\r
+    delete [] pCol;\r
+    \r
+    // ifourier each y row\r
+    CTSimComplex* complexInRow = new CTSimComplex [m_nx];\r
+    CTSimComplex* complexOutRow = new CTSimComplex [m_nx];\r
     for (iy = 0; iy < m_ny; iy++) {\r
-      vRealResult[ix][iy] = complexOut[ix][iy].real();\r
-      vImagResult[ix][iy] = complexOut[ix][iy].imag();\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        complexInRow[ix] = complexOut[ix][iy];\r
+      ProcessSignal::finiteFourierTransform (complexInRow, complexOutRow, m_nx, ProcessSignal::BACKWARD);\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        complexOut[ix][iy] = complexOutRow[ix];\r
     }\r
+    delete [] complexInRow;\r
+    delete [] complexOutRow;\r
     \r
-  // delete complexOut matrix\r
-  for (ix = 0; ix < m_nx; ix++)\r
-    delete [] complexOut[ix];\r
-  delete [] complexOut;\r
-    \r
-  return true;\r
+    for (ix = 0; ix < m_nx; ix++)\r
+      for (iy = 0; iy < m_ny; iy++) {\r
+        vRealResult[ix][iy] = complexOut[ix][iy].real();\r
+        vImagResult[ix][iy] = complexOut[ix][iy].imag();\r
+      }\r
+      \r
+      // delete complexOut matrix\r
+      for (ix = 0; ix < m_nx; ix++)\r
+        delete [] complexOut[ix];\r
+      delete [] complexOut;\r
+      \r
+      return true;\r
 }\r
 \r
 \r
@@ -980,7 +1002,7 @@ ImageFile::magnitude (ImageFile& result) const
   ImageFileArray vReal = getArray();\r
   ImageFileArray vImag = getImaginaryArray();\r
   ImageFileArray vRealResult = result.getArray();\r
-\r
+  \r
   for (unsigned int ix = 0; ix < m_nx; ix++)\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (isComplex()) \r
@@ -988,10 +1010,10 @@ ImageFile::magnitude (ImageFile& result) const
       else\r
         vRealResult[ix][iy] = vReal[ix][iy];\r
     }\r
-\r
-  if (result.isComplex())\r
-    result.convertComplexToReal();\r
-  \r
+    \r
+    if (result.isComplex())\r
+      result.convertComplexToReal();\r
+    \r
     return true;\r
 }\r
 \r
@@ -1006,7 +1028,7 @@ ImageFile::phase (ImageFile& result) const
   ImageFileArray vReal = getArray();\r
   ImageFileArray vImag = getImaginaryArray();\r
   ImageFileArray vRealResult = result.getArray();\r
-\r
+  \r
   for (unsigned int ix = 0; ix < m_nx; ix++)\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (isComplex())\r
@@ -1015,10 +1037,10 @@ ImageFile::phase (ImageFile& result) const
         vRealResult[ix][iy] = 0;\r
     }\r
     \r
-  if (result.isComplex())\r
-    result.convertComplexToReal();\r
-  \r
-  return true;\r
+    if (result.isComplex())\r
+      result.convertComplexToReal();\r
+    \r
+    return true;\r
 }\r
 \r
 bool\r
@@ -1031,7 +1053,7 @@ ImageFile::square (ImageFile& result) const
   \r
   if (isComplex() && ! result.isComplex())\r
     result.convertRealToComplex();\r
-\r
+  \r
   ImageFileArrayConst vLHS = getArray();\r
   ImageFileArrayConst vLHSImag = getImaginaryArray();\r
   ImageFileArray vResult = result.getArray();\r
@@ -1040,9 +1062,10 @@ ImageFile::square (ImageFile& result) const
   for (unsigned int ix = 0; ix < m_nx; ix++) {\r
     for (unsigned int iy = 0; iy < m_ny; iy++) {\r
       if (result.isComplex()) {\r
-        std::complex<double> cLHS (vLHS[ix][iy], 0);\r
+        double dImag = 0;\r
         if (isComplex())\r
-          cLHS.imag (vLHSImag[ix][iy]);\r
+          dImag = vLHSImag[ix][iy];\r
+        std::complex<double> cLHS (vLHS[ix][iy], dImag);\r
         std::complex<double> cResult = cLHS * cLHS;\r
         vResult[ix][iy] = cResult.real();\r
         vResultImag[ix][iy] = cResult.imag();\r
@@ -1059,24 +1082,24 @@ int
 ImageFile::convertFormatNameToID (const char* const formatName)\r
 {\r
   int formatID = FORMAT_INVALID;\r
-\r
+  \r
   for (int i = 0; i < s_iFormatCount; i++)\r
-      if (strcasecmp (formatName, s_aszFormatName[i]) == 0) {\r
-         formatID = i;\r
-         break;\r
-      }\r
-\r
-  return (formatID);\r
+    if (strcasecmp (formatName, s_aszFormatName[i]) == 0) {\r
+      formatID = i;\r
+      break;\r
+    }\r
+    \r
+    return (formatID);\r
 }\r
 \r
 const char*\r
 ImageFile::convertFormatIDToName (int formatID)\r
 {\r
   static const char *formatName = "";\r
-\r
+  \r
   if (formatID >= 0 && formatID < s_iFormatCount)\r
-      return (s_aszFormatName[formatID]);\r
-\r
+    return (s_aszFormatName[formatID]);\r
+  \r
   return (formatName);\r
 }\r
 \r
@@ -1084,10 +1107,10 @@ const char*
 ImageFile::convertFormatIDToTitle (const int formatID)\r
 {\r
   static const char *formatTitle = "";\r
-\r
+  \r
   if (formatID >= 0 && formatID < s_iFormatCount)\r
-      return (s_aszFormatTitle[formatID]);\r
-\r
+    return (s_aszFormatTitle[formatID]);\r
+  \r
   return (formatTitle);\r
 }\r
 \r
@@ -1099,7 +1122,7 @@ ImageFile::exportImage (const char* const pszFormat, const char* const pszFilena
     sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat);\r
     return false;\r
   }\r
-\r
+  \r
   if (iFormatID == FORMAT_PGM)\r
     return writeImagePGM (pszFilename, nxcell, nycell, densmin, densmax);\r
   else if (iFormatID == FORMAT_PGMASCII)\r
@@ -1108,7 +1131,7 @@ ImageFile::exportImage (const char* const pszFormat, const char* const pszFilena
     return writeImagePNG (pszFilename, 8, nxcell, nycell, densmin, densmax);\r
   else if (iFormatID == FORMAT_PNG16)\r
     return writeImagePNG (pszFilename, 16, nxcell, nycell, densmin, densmax);\r
-\r
+  \r
   sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat);\r
   return false;\r
 }\r
@@ -1147,7 +1170,7 @@ ImageFile::writeImagePGM (const char* const outfile, int nxcell, int nycell, dou
   \r
   delete rowp;
   fclose(fp);\r
-\r
+  \r
   return true;
 }
 
@@ -1186,7 +1209,7 @@ ImageFile::writeImagePGMASCII (const char* const outfile, int nxcell, int nycell
   \r
   delete rowp;
   fclose(fp);\r
-\r
+  \r
   return true;
 }
 
@@ -1256,7 +1279,7 @@ ImageFile::writeImagePNG (const char* const outfile, int bitdepth, int nxcell, i
   delete rowp;\r
   
   fclose(fp);\r
-\r
+  \r
   return true;
 }
 #endif
@@ -1303,9 +1326,9 @@ ImageFile::writeImageGIF (const char* const outfile, int nxcell, int nycell, dou
   gdImageGif(gif,out);
   fclose(out);
   gdImageDestroy(gif);\r
-\r
+  \r
   delete rowp;\r
-\r
+  \r
   return true;
 }
 #endif