r318: *** empty log message ***
[ctsim.git] / tools / if1.cpp
index dcd1dc1a3ac25eb0144d11a7ac7041610477aa86..9e4c1694f5a70746f853633402ab5ca14685911e 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: if1.cpp,v 1.2 2000/12/23 18:12:35 kevin Exp $
+**  $Id: if1.cpp,v 1.3 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
 **
 **  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
@@ -46,7 +46,7 @@ static struct option my_options[] =
   {0, 0, 0, 0}
 };
 
   {0, 0, 0, 0}
 };
 
-static const char* g_szIdStr = "$Id: if1.cpp,v 1.2 2000/12/23 18:12:35 kevin Exp $";
+static const char* g_szIdStr = "$Id: if1.cpp,v 1.3 2000/12/29 15:45:06 kevin Exp $";
 
 void 
 if1_usage (const char *program)
 
 void 
 if1_usage (const char *program)
@@ -67,8 +67,6 @@ if1_usage (const char *program)
 int 
 if1_main (int argc, char *const argv[])
 {
 int 
 if1_main (int argc, char *const argv[])
 {
-  ImageFile *im_in;
-  ImageFile *im_out;
   char *in_file;
   char *out_file;
   int opt_verbose = 0;
   char *in_file;
   char *out_file;
   int opt_verbose = 0;
@@ -131,61 +129,39 @@ if1_main (int argc, char *const argv[])
   in_file = argv[optind];
   out_file = argv[optind + 1];
 
   in_file = argv[optind];
   out_file = argv[optind + 1];
 
-
   std::string histString;
 
   if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
   std::string histString;
 
   if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
-    int ix, iy;
-
-    im_in = new ImageFile ();
-    im_in->fileRead (in_file);
-    int nx = im_in->nx();
-    int ny = im_in->ny();
-    im_out = new ImageFile (nx, ny);
-
-    ImageFileArray vIn = im_in->getArray();
-    ImageFileArray vOut = im_out->getArray();
-
-    if (opt_invert) {
-      for (ix = 0; ix < nx; ix++)
-        for (iy = 0; iy < ny; iy++)
-          vOut[ix][iy] = - vIn[ix][iy];
+    ImageFile im_in;
+    im_in.fileRead (in_file);
+    int nx = im_in.nx();
+    int ny = im_in.ny();
+    ImageFile im_out (nx, ny);
+
+    if (opt_invert) {\r
+      im_in.invertPixelValues (im_out);
       histString = "Invert transformation";
     }
       histString = "Invert transformation";
     }
-    if (opt_log) {
-      for (ix = 0; ix < nx; ix++)
-        for (iy = 0; iy < ny; iy++)\r
-          if (vIn[ix][iy] < 0)\r
-            vOut[ix][iy] = 0;
-          else\r
-            vOut[ix][iy] = log (vIn[ix][iy]);
+    if (opt_log) {\r
+      im_in.log (im_out);
       histString = "Logrithmic transformation";
     }
       histString = "Logrithmic transformation";
     }
-    if (opt_exp) {
-      for (ix = 0; ix < nx; ix++)
-        for (iy = 0; iy < ny; iy++)
-          vOut[ix][iy] = exp (vIn[ix][iy]);
+    if (opt_exp) {\r
+      im_in.exp (im_out);
       histString = "Exponential transformation";
     }
       histString = "Exponential transformation";
     }
-    if (opt_sqr) {
-      for (ix = 0; ix < nx; ix++)
-        for (iy = 0; iy < ny; iy++)
-          vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
+    if (opt_sqr) {\r
+      im_in.square (im_out);
       histString = "Square transformation";
     }
       histString = "Square transformation";
     }
-    if (opt_sqrt) {
-      for (ix = 0; ix < nx; ix++)
-        for (iy = 0; iy < ny; iy++)\r
-          if (vIn[ix][iy] < 0)
-              vOut[ix][iy] = sqrt (-vIn[ix][iy]);\r
-          else\r
-              vOut[ix][iy] = sqrt (vIn[ix][iy]);\r
+    if (opt_sqrt) {\r
+      im_in.sqrt (im_out);
       histString = "Square root transformation";
     }
 
       histString = "Square root transformation";
     }
 
-    im_out->labelsCopy (*im_in);
-    im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
-    im_out->fileWrite (out_file);
+    im_out.labelsCopy (im_in);
+    im_out.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
+    im_out.fileWrite (out_file);
   }
 
   return (0);
   }
 
   return (0);