-\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
- if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\r
- ImageFileArrayConst vLHSImag = getImaginaryArray();\r
- ImageFileArrayConst vRHS = rRHS.getArray();\r
- ImageFileArrayConst vRHSImag = rRHS.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
- vResult[ix][iy] = vLHS[ix][iy] - vRHS[ix][iy];\r
- if (result.isComplex()) {\r
- vResultImag[ix][iy] = 0;\r
- if (isComplex())\r
- vResultImag[ix][iy] += vLHSImag[ix][iy];\r
- if (rRHS.isComplex())\r
- vResultImag[ix][iy] -= vRHSImag[ix][iy];\r
- }\r
- }\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
- if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\r
- ImageFileArrayConst vLHSImag = getImaginaryArray();\r
- ImageFileArrayConst vRHS = rRHS.getArray();\r
- ImageFileArrayConst vRHSImag = rRHS.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
- vResult[ix][iy] = vLHS[ix][iy] + vRHS[ix][iy];\r
- if (result.isComplex()) {\r
- vResultImag[ix][iy] = 0;\r
- if (isComplex())\r
- vResultImag[ix][iy] += vLHSImag[ix][iy];\r
- if (rRHS.isComplex())\r
- vResultImag[ix][iy] += vRHSImag[ix][iy];\r
- }\r
- }\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
- if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\r
- ImageFileArrayConst vLHSImag = getImaginaryArray();\r
- ImageFileArrayConst vRHS = rRHS.getArray();\r
- ImageFileArrayConst vRHSImag = rRHS.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> cRHS (vRHS[ix][iy], 0);\r
- if (rRHS.isComplex())\r
- cRHS.imag (vRHSImag[ix][iy]);\r
- std::complex<double> cResult = cLHS * cRHS;\r
- vResult[ix][iy] = cResult.real();\r
- vResultImag[ix][iy] = cResult.imag();\r
- } else\r
- vResult[ix][iy] = vLHS[ix][iy] * vRHS[ix][iy];\r
- }\r
- }\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
- if (isComplex() || rRHS.isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\r
- ImageFileArrayConst vLHSImag = getImaginaryArray();\r
- ImageFileArrayConst vRHS = rRHS.getArray();\r
- ImageFileArrayConst vRHSImag = rRHS.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> cRHS (vRHS[ix][iy], 0);\r
- if (rRHS.isComplex())\r
- cRHS.imag (vRHSImag[ix][iy]);\r
- std::complex<double> cResult = cLHS / cRHS;\r
- vResult[ix][iy] = cResult.real();\r
- vResultImag[ix][iy] = cResult.imag();\r
- } else {\r
- if (vRHS != 0)\r
- vResult[ix][iy] = vLHS[ix][iy] / vRHS[ix][iy];\r
- else\r
- vResult[ix][iy] = 0;\r
- }\r
- }\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
- \r
- bool bComplexOutput = result.isComplex();\r
- ImageFileArrayConst vLHS = getArray();\r
- if (! bComplexOutput) // check if should convert to complex output\r
- for (unsigned int ix = 0; ix < m_nx; ix++)\r
- for (unsigned int iy = 0; iy < m_ny; iy++)\r
- if (! bComplexOutput && vLHS[ix][iy] < 0) {\r
- result.convertRealToComplex();\r
- 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
-\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\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::log (cLHS);\r
- vResult[ix][iy] = cResult.real();\r
- vResultImag[ix][iy] = cResult.imag();\r
- } else\r
- vResult[ix][iy] = ::log (vLHS[ix][iy]);\r
- }\r
- }\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\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::exp (cLHS);\r
- vResult[ix][iy] = cResult.real();\r
- vResultImag[ix][iy] = cResult.imag();\r
- } else\r
- vResult[ix][iy] = ::exp (vLHS[ix][iy]);\r
- }\r
- }\r
- \r
- \r
- return true;\r
-}\r
-\r
-bool\r
-ImageFile::scaleImage (ImageFile& result) const\r
-{\r
- unsigned int nx = m_nx;\r
- unsigned int ny = m_ny;\r
- unsigned int newNX = result.nx();\r
- unsigned int newNY = result.ny();\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vReal = getArray();\r
- ImageFileArrayConst vImag = getImaginaryArray();\r
- ImageFileArray vResult = result.getArray();\r
- ImageFileArray vResultImag = result.getImaginaryArray();\r
- \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
- }\r
- }\r
- }\r
- \r
- return true;\r
-}\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.convertRealToComplex ())\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
- Fourier::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.convertRealToComplex ())\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
- 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
-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.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
-#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
- 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
- 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
-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.convertRealToComplex ())\r
- return false;\r
- }\r
- \r
- ImageFileArrayConst vLHSReal = getArray();\r
- ImageFileArrayConst vLHSImag = getImaginaryArray();\r
- ImageFileArray vRealResult = result.getArray();\r
- ImageFileArray vImagResult = result.getImaginaryArray();\r
- \r
- unsigned int ix, iy;\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 result\r
- for (ix = 0; ix < m_nx; ix++)\r
- for (iy = 0; iy < m_ny; iy++) {\r
- vRealResult[ix][iy] = vLHSReal[ix][iy];\r
- if (isComplex())\r
- vImagResult[ix][iy] = vLHSImag[ix][iy];\r
- 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
- 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
- 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
- ImageFileArray vRealResult = result.getArray();\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
- 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.convertComplexToReal();\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
- ImageFileArray vRealResult = result.getArray();\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
- 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.convertComplexToReal();\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
- if (isComplex() && ! result.isComplex())\r
- result.convertRealToComplex();\r
-\r
- ImageFileArrayConst vLHS = getArray();\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 = cLHS * cLHS;\r
- vResult[ix][iy] = cResult.real();\r
- vResultImag[ix][iy] = cResult.imag();\r
- } else\r
- vResult[ix][iy] = vLHS[ix][iy] * vLHS[ix][iy];\r
- }\r
- }\r
- \r
- \r
- return true;\r
-}\r
-\r
-int\r
-ImageFile::convertFormatNameToID (const char* const formatName)\r
-{\r
- int formatID = FORMAT_INVALID;\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
-}\r
-\r
-const char*\r
-ImageFile::convertFormatIDToName (int formatID)\r
-{\r
- static const char *formatName = "";\r
-\r
- if (formatID >= 0 && formatID < s_iFormatCount)\r
- return (s_aszFormatName[formatID]);\r
-\r
- return (formatName);\r
-}\r
-\r
-const char*\r
-ImageFile::convertFormatIDToTitle (const int formatID)\r
-{\r
- static const char *formatTitle = "";\r
-\r
- if (formatID >= 0 && formatID < s_iFormatCount)\r
- return (s_aszFormatTitle[formatID]);\r
-\r
- return (formatTitle);\r
-}\r
-\r
-bool\r
-ImageFile::exportImage (const char* const pszFormat, const char* const pszFilename, int nxcell, int nycell, double densmin, double densmax)\r
-{\r
- int iFormatID = convertFormatNameToID (pszFormat);\r
- if (iFormatID == FORMAT_INVALID) {\r
- sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat);\r
- return false;\r
- }\r
-\r
- if (iFormatID == FORMAT_PGM)\r
- return writeImagePGM (pszFilename, nxcell, nycell, densmin, densmax);\r
- else if (iFormatID == FORMAT_PGMASCII)\r
- return writeImagePGMASCII (pszFilename, nxcell, nycell, densmin, densmax);\r
- else if (iFormatID == FORMAT_PNG)\r
- 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
- sys_error (ERR_SEVERE, "Invalid format %s [ImageFile::exportImage]", pszFormat);\r
- return false;\r
-}\r
-\r