X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=a5e9bec75e34ea2442152be631e318c1a93b897f;hp=b86ff794ae9cd0242201c21e33184bca9c513e3f;hb=c551b53b39a7571cf52831f5e117be1cca95c420;hpb=f7d2b7144f32a7bd157b7689022e62944b82fcc1 diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index b86ff79..a5e9bec 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.23 2000/12/21 03:40:58 kevin Exp $ +** $Id: imagefile.cpp,v 1.24 2000/12/22 04:18:00 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 @@ -266,7 +266,104 @@ ImageFile::getMinMax (double& min, double& max) const } } } + +bool +ImageFile::subtractImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ - *in2++; + } + + return true; +} +bool +ImageFile::addImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ + *in2++; + } + + return true; +} + +bool +ImageFile::multiplyImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) + *out++ = *in1++ * *in2++; + } + + return true; +} + +bool +ImageFile::divideImages (const ImageFile& rRHS, ImageFile& result) const +{ + if (m_nx != rRHS.nx() || m_ny != rRHS.ny() || m_nx != result.nx() || m_ny != result.ny()) { + sys_error (ERR_WARNING, "Difference sizes of images [ImageFile::subtractImage]"); + return false; + } + + ImageFileArrayConst vLHS = getArray(); + ImageFileArrayConst vRHS = rRHS.getArray(); + ImageFileArray vResult = result.getArray(); + + for (int ix = 0; ix < m_nx; ix++) { + ImageFileColumnConst in1 = vLHS[ix]; + ImageFileColumnConst in2 = vRHS[ix]; + ImageFileColumn out = vResult[ix]; + for (int iy = 0; iy < m_ny; iy++) { + if (*in2 != 0.) + *out++ = *in1++ / *in2++; + else + *out++ = 0; + } + } + + return true; +} + + void ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax) {