** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: imagefile.cpp,v 1.22 2000/12/20 20:08:48 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
if (v == NULL || nx == 0 || ny == 0)
return;
\r
- std::vector<double> vecImage (nx * ny);\r
+ std::vector<double> vecImage;\r
+ int iVec = 0;\r
+ vecImage.resize (nx * ny);\r
for (int ix = 0; ix < nx; ix++) {\r
for (int iy = 0; iy < ny; iy++)\r
- vecImage.push_back (v[ix][iy]);\r
+ vecImage[iVec++] = v[ix][iy];\r
}\r
\r
- vectorNumericStatistics (vecImage, min, max, mean, mode, median, stddev);\r
+ vectorNumericStatistics (vecImage, nx * ny, min, max, mean, mode, median, stddev);\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 (int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (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 (int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (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 (int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (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 (int ix = 0; ix < m_nx; ix++) {\r
+ ImageFileColumnConst in1 = vLHS[ix];\r
+ ImageFileColumnConst in2 = vRHS[ix];\r
+ ImageFileColumn out = vResult[ix];\r
+ for (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
void
ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax)
{