r311: image comparison functions
[ctsim.git] / libctsim / imagefile.cpp
index b86ff794ae9cd0242201c21e33184bca9c513e3f..a5e9bec75e34ea2442152be631e318c1a93b897f 100644 (file)
@@ -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
                }
     }
 }
+\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)
 {