X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=54f38a18550998ee53bfd6b0af12b55bfbeaa55e;hp=a5e9bec75e34ea2442152be631e318c1a93b897f;hb=5c6b29ab4885308cc3381af6e0a68f4804956d2e;hpb=c24c1c0721df40e77822ad2b9ec01a944012ff42 diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index a5e9bec..54f38a1 100644 --- a/libctsim/imagefile.cpp +++ b/libctsim/imagefile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: imagefile.cpp,v 1.24 2000/12/22 04:18:00 kevin Exp $ +** $Id: imagefile.cpp,v 1.25 2000/12/29 15:45:06 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 @@ -62,7 +62,7 @@ ImageFile::filterResponse (const char* const domainName, double bw, const char* for (int i = -hx; i <= hx; i++) { for (int j = -hy; j <= hy; j++) { - double r = sqrt (i * i + j * j); + double r = ::sqrt (i * i + j * j); v[i+hx][j+hy] = filter.response (r); } @@ -170,7 +170,7 @@ ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r, } } - d = sqrt (sqErrorSum / sqDiffFromMeanSum); + d = ::sqrt (sqErrorSum / sqDiffFromMeanSum); r = absErrorSum / absValueSum; int hx = m_nx / 2; @@ -364,6 +364,242 @@ ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const } +bool +ImageFile::invertPixelValues (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = - *in++; + } + + return true; +} + +bool +ImageFile::sqrt (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + if (*in < 0) + *out++ = -::sqrt(-*in++); + else + *out++ = ::sqrt(*in++); + } + + return true; +} + +bool +ImageFile::log (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + if (*in <= 0) + *out++ = 0; + else + *out++ = ::log(*in++); + } + + return true; +} + +bool +ImageFile::exp (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = ::exp (*in++); + } + + return true; +} + +bool +ImageFile::FFTMagnitude (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + int ix, iy; + double* pY = new double [m_ny]; + std::complex** complexOut = new std::complex* [m_nx]; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix] = new std::complex [m_ny]; + + for (ix = 0; ix < m_nx; ix++) { + for (iy = 0; iy < m_ny; iy++) + pY[iy] = vLHS[ix][iy]; + ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny, ProcessSignal::FORWARD); + } + delete pY; + + std::complex* pX = new std::complex [m_nx]; + std::complex* complexOutCol = new std::complex [m_nx]; + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + pX[ix] = complexOut[ix][iy]; + ProcessSignal::finiteFourierTransform (pX, complexOutCol, m_nx, ProcessSignal::FORWARD); + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutCol[ix]; + } + delete [] pX; + + for (ix = 0; ix < m_nx; ix++) + ProcessSignal::shuffleFourierToNaturalOrder (complexOut[ix], m_ny); + + + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + complexOutCol[ix] = complexOut[ix][iy]; + ProcessSignal::shuffleFourierToNaturalOrder (complexOutCol, m_nx);; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutCol[ix]; + + } + delete [] complexOutCol; + + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) + vResult[ix][iy] = std::abs (complexOut[ix][iy]); + + for (ix = 0; ix < m_nx; ix++) + delete [] complexOut[ix]; + + delete [] complexOut; + + return true; +} + +bool +ImageFile::FFTPhase (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + int ix, iy; + double* pY = new double [m_ny]; + std::complex** complexOut = new std::complex* [m_nx]; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix] = new std::complex [m_ny]; + + for (ix = 0; ix < m_nx; ix++) { + for (iy = 0; iy < m_ny; iy++) + pY[iy] = vLHS[ix][iy]; + ProcessSignal::finiteFourierTransform (pY, complexOut[ix], m_ny, ProcessSignal::FORWARD); + } + delete pY; + + std::complex* pX = new std::complex [m_nx]; + std::complex* complexOutCol = new std::complex [m_nx]; + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + pX[ix] = complexOut[ix][iy]; + ProcessSignal::finiteFourierTransform (pX, complexOutCol, m_nx, ProcessSignal::FORWARD); + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutCol[ix]; + } + delete [] pX; + + for (ix = 0; ix < m_nx; ix++) + ProcessSignal::shuffleFourierToNaturalOrder (complexOut[ix], m_ny); + + + for (iy = 0; iy < m_ny; iy++) { + for (ix = 0; ix < m_nx; ix++) + complexOutCol[ix] = complexOut[ix][iy]; + ProcessSignal::shuffleFourierToNaturalOrder (complexOutCol, m_nx);; + for (ix = 0; ix < m_nx; ix++) + complexOut[ix][iy] = complexOutCol[ix]; + + } + delete [] complexOutCol; + + for (ix = 0; ix < m_nx; ix++) + for (iy = 0; iy < m_ny; iy++) + vResult[ix][iy] = atan (complexOut[ix][iy].imag / complexOut[ix][iy].real); + + for (ix = 0; ix < m_nx; ix++) + delete [] complexOut[ix]; + + delete [] complexOut; + + return true; +} + +bool +ImageFile::square (ImageFile& result) const +{ + if (m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::invertPixelValues]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in = vLHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) { + *out++ = *in * *in; + in++; + } + } + + return true; +} + + void ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax) {