+\r
+bool\r
+ImageFile::convertRealToComplex ()\r
+{\r
+ if (dataType() != Array2dFile::DATA_TYPE_REAL)\r
+ return false;\r
+ \r
+ if (! reallocRealToComplex())\r
+ return false;\r
+ \r
+ ImageFileArray vImag = getImaginaryArray();\r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumn vCol = vImag[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *vCol++ = 0;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::convertComplexToReal ()\r
+{\r
+ if (dataType() != Array2dFile::DATA_TYPE_COMPLEX)\r
+ return false;\r
+ \r
+ ImageFileArray vReal = getArray();\r
+ ImageFileArray vImag = getImaginaryArray();\r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumn vRealCol = vReal[ix];\r
+ ImageFileColumn vImagCol = vImag[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+ CTSimComplex c (*vRealCol, *vImagCol);\r
+ *vRealCol++ = std::abs (c);\r
+ vImagCol++;\r
+ }\r
+ }\r
+ \r
+ return reallocComplexToReal();\r
+}\r
+\r
+bool\r
+ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const\r
+{\r
+ if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArrayConst vRHS = rRHS.getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *out++ = *in1++ - *in2++;\r
+ }\r
+ \r
+ return true;\r
+}\r
+
+bool\r
+ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const\r
+{\r
+ if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArrayConst vRHS = rRHS.getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *out++ = *in1++ + *in2++;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const\r
+{\r
+ if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArrayConst vRHS = rRHS.getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *out++ = *in1++ * *in2++;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const\r
+{\r
+ if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArrayConst vRHS = rRHS.getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+ if (*in2 != 0.)\r
+ *out++ = *in1++ / *in2++;\r
+ else\r
+ *out++ = 0;\r
+ }\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+\r
+bool\r
+ImageFile::invertPixelValues (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in = vLHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *out++ = - *in++;\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::sqrt (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in = vLHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ if (*in < 0)\r
+ *out++ = -::sqrt(-*in++);\r
+ else\r
+ *out++ = ::sqrt(*in++);\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::log (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in = vLHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ if (*in <= 0)\r
+ *out++ = 0;\r
+ else\r
+ *out++ = ::log(*in++);\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::exp (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in = vLHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++)\r
+ *out++ = ::exp (*in++);\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+namespace ProcessImage {\r
+\r
+void\r
+shuffleFourierToNaturalOrder (ImageFile& im)\r
+{\r
+ ImageFileArray vReal = im.getArray();\r
+ ImageFileArray vImag = im.getImaginaryArray();\r
+ unsigned int ix, iy;\r
+ unsigned int nx = im.nx();\r
+ unsigned int ny = im.ny();\r
+\r
+ // shuffle each column\r
+ for (ix = 0; ix < nx; ix++) {\r
+ ProcessSignal::shuffleFourierToNaturalOrder (vReal[ix], ny);\r
+ if (im.isComplex())\r
+ ProcessSignal::shuffleFourierToNaturalOrder (vImag[ix], ny);\r
+ }\r
+\r
+ // shuffle each row\r
+ float* pRow = new float [nx];\r
+ for (iy = 0; iy < ny; iy++) {\r
+ for (ix = 0; ix < nx; ix++)\r
+ pRow[ix] = vReal[ix][iy];\r
+ ProcessSignal::shuffleFourierToNaturalOrder (pRow, nx);\r
+ for (ix = 0; ix < nx; ix++)\r
+ vReal[ix][iy] = pRow[ix];\r
+ if (im.isComplex()) {\r
+ for (ix = 0; ix < nx; ix++)\r
+ pRow[ix] = vImag[ix][iy];\r
+ ProcessSignal::shuffleFourierToNaturalOrder (pRow, nx);;\r
+ for (ix = 0; ix < nx; ix++)\r
+ vImag[ix][iy] = pRow[ix];\r
+ }\r
+ }\r
+ delete pRow;\r
+}\r
+ \r
+void\r
+shuffleNaturalToFourierOrder (ImageFile& im)\r
+{\r
+ ImageFileArray vReal = im.getArray();\r
+ ImageFileArray vImag = im.getImaginaryArray();\r
+ unsigned int ix, iy;\r
+ unsigned int nx = im.nx();\r
+ unsigned int ny = im.ny();\r
+\r
+ // shuffle each x column\r
+ for (ix = 0; ix < nx; ix++) {\r
+ ProcessSignal::shuffleNaturalToFourierOrder (vReal[ix], ny);\r
+ if (im.isComplex())\r
+ ProcessSignal::shuffleNaturalToFourierOrder (vImag[ix], ny);\r
+ }\r
+\r
+ // shuffle each y row\r
+ float* pRow = new float [nx];\r
+ for (iy = 0; iy < ny; iy++) {\r
+ for (ix = 0; ix < nx; ix++)\r
+ pRow[ix] = vReal[ix][iy];\r
+ ProcessSignal::shuffleNaturalToFourierOrder (pRow, nx);\r
+ for (ix = 0; ix < nx; ix++)\r
+ vReal[ix][iy] = pRow[ix];\r
+ if (im.isComplex()) {\r
+ for (ix = 0; ix < nx; ix++)\r
+ pRow[ix] = vImag[ix][iy];\r
+ ProcessSignal::shuffleNaturalToFourierOrder (pRow, nx);\r
+ for (ix = 0; ix < nx; ix++)\r
+ vImag[ix][iy] = pRow[ix];\r
+ }\r
+ }\r
+ delete [] pRow;\r
+}\r
+\r
+ \r
+}; // namespace ProcessIamge\r
+\r
+#ifdef HAVE_FFTW\r
+bool\r
+ImageFile::fft (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+\r
+ if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
+ if (! result.reallocRealToComplex ())\r
+ return false;\r
+ }\r
+\r
+ fftw_complex* in = new fftw_complex [m_nx * m_ny];\r
+\r
+ ImageFileArrayConst vReal = getArray();\r
+ ImageFileArrayConst vImag = getImaginaryArray();\r
+\r
+ unsigned int ix, iy;\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 = vReal[ix][iy];\r
+ if (isComplex())\r
+ in[iArray].im = vImag[ix][iy];\r
+ else\r
+ 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
+ ProcessImage::shuffleFourierToNaturalOrder (result);\r
+\r
+ return true;\r
+}\r
+\r
+\r
+bool\r
+ImageFile::ifft (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+\r
+ if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
+ if (! result.reallocRealToComplex ())\r
+ return false;\r
+ }\r
+\r
+ ImageFileArrayConst vReal = getArray();\r
+ ImageFileArrayConst vImag = getImaginaryArray();\r
+ ImageFileArray vRealResult = result.getArray();\r
+ ImageFileArray vImagResult = result.getImaginaryArray();\r
+ unsigned int ix, iy;\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ for (iy = 0; iy < m_ny; iy++) {\r
+ vRealResult[ix][iy] = vReal[ix][iy];\r
+ if (isComplex()) \r
+ vImagResult[ix][iy] = vImag[ix][iy];\r
+ else\r
+ vImagResult[ix][iy] = 0;\r
+ }\r
+\r
+ ProcessImage::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
+bool\r
+ImageFile::fourier (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
+ if (! result.reallocRealToComplex ())\r
+ return false;\r
+ }\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
+#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
+#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
+ \r
+ // shuffle each column\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ ProcessSignal::shuffleFourierToNaturalOrder (complexOut[ix], m_ny);\r
+ \r
+ // shuffle each row\r
+ for (iy = 0; iy < m_ny; iy++) {\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ complexOutRow[ix] = complexOut[ix][iy];\r
+ ProcessSignal::shuffleFourierToNaturalOrder (complexOutRow, m_nx);;\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ complexOut[ix][iy] = complexOutRow[ix];\r
+ \r
+ }\r
+ delete [] complexOutRow;\r
+ \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
+ for (ix = 0; ix < m_nx; ix++)\r
+ delete [] complexOut[ix];\r
+ delete [] complexOut;\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::inverseFourier (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ if (result.dataType() == Array2dFile::DATA_TYPE_REAL) {\r
+ if (! result.reallocRealToComplex ())\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHSReal = getArray();\r
+ ImageFileArrayConst vLHSImag = getImaginaryArray();\r
+ \r
+ unsigned int ix, iy;\r
+\r
+ // alloc 2d complex 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
+ // put input image into complexOut\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ for (iy = 0; iy < m_ny; iy++) {\r
+ complexOut[ix][iy].real (vLHSReal[ix][iy]);\r
+ if (isComplex())\r
+ complexOut[ix][iy].imag (vLHSImag[ix][iy]);\r
+ else\r
+ complexOut[ix][iy].imag (0);\r
+ }\r
+\r
+ // shuffle each x column\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ ProcessSignal::shuffleNaturalToFourierOrder (complexOut[ix], m_ny);\r
+\r
+ // shuffle each y row\r
+ CTSimComplex* pComplexRow = new CTSimComplex [m_nx];\r
+ for (iy = 0; iy < m_ny; iy++) {\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ pComplexRow[ix] = complexOut[ix][iy];\r
+ ProcessSignal::shuffleNaturalToFourierOrder (pComplexRow, m_nx);\r
+ for (ix = 0; ix < m_nx; ix++)\r
+ complexOut[ix][iy] = pComplexRow[ix];\r
+ }\r
+ delete [] pComplexRow;\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] = complexOut[ix][iy];\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
+ ImageFileArray vRealResult = result.getArray();\r
+ ImageFileArray vImagResult = result.getImaginaryArray();\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
+bool\r
+ImageFile::magnitude (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArray vReal = getArray();\r
+ ImageFileArray vImag = getImaginaryArray();\r
+ \r
+ ImageFileArray vRealResult = result.getArray();\r
+ for (unsigned int ix = 0; ix < m_nx; ix++)\r
+ for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+ if (isComplex()) \r
+ vRealResult[ix][iy] = ::sqrt (vReal[ix][iy] * vReal[ix][iy] + vImag[ix][iy] * vImag[ix][iy]);\r
+ else\r
+ vRealResult[ix][iy] = vReal[ix][iy];\r
+ }\r
+\r
+ if (result.isComplex())\r
+ result.reallocComplexToReal();\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::phase (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArray vReal = getArray();\r
+ ImageFileArray vImag = getImaginaryArray();\r
+ \r
+ ImageFileArray vRealResult = result.getArray();\r
+ for (unsigned int ix = 0; ix < m_nx; ix++)\r
+ for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+ if (isComplex())\r
+ vRealResult[ix][iy] = ::atan2 (vImag[ix][iy], vReal[ix][iy]);\r
+ else\r
+ vRealResult[ix][iy] = 0;\r
+ }\r
+ \r
+ if (result.isComplex())\r
+ result.reallocComplexToReal();\r
+ \r
+ return true;\r
+}\r
+\r
+bool\r
+ImageFile::square (ImageFile& result) const\r
+{\r
+ if (m_nx != result.nx() || m_ny != result.ny()) {\r
+ sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]");\r
+ return false;\r
+ }\r
+ \r
+ ImageFileArrayConst vLHS = getArray();\r
+ ImageFileArray vResult = result.getArray();\r
+ \r
+ for (unsigned int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in = vLHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (unsigned int iy = 0; iy < m_ny; iy++) {\r
+ *out++ = *in * *in;\r
+ in++;\r
+ }\r
+ }\r
+ \r
+ return true;\r
+}\r
+\r
+\r