r182: *** empty log message ***
[ctsim.git] / libctsim / imagefile.cpp
index 3a1483dffd89a6a6b7a6e3f98c548fd9da3ab913..3f7c0beff717a84bafe3f588816dfc50d29bf0db 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: imagefile.cpp,v 1.8 2000/07/13 07:03:21 kevin Exp $
+**  $Id: imagefile.cpp,v 1.10 2000/08/22 16:49:56 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
@@ -59,7 +59,6 @@ ImageFile::display (void) const
 int 
 ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const ImageFileValue pmax) const
 {
-    int grayscale[256];
     int nx = m_nx;
     int ny = m_ny;
     ImageFileArrayConst v = getArray();
@@ -71,7 +70,7 @@ ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const Ima
 
     double view_scale = 255 / (pmax - pmin);
     int id_X11 = g2_open_X11 (nx * scale, ny * scale);
-
+    int grayscale[256];
     for (int i = 0; i < 256; i++) {
        double cval = i / 255.;
        grayscale[i] = g2_ink (id_X11, cval, cval, cval);
@@ -220,7 +219,7 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou
     }
     mean /= (nx * ny);
 
-    static const int nbin = 256;
+    static const int nbin = 1024;
     int hist[ nbin ] = {0};
     double spread = max - min;
     mode = 0;
@@ -245,8 +244,22 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou
     }
 
     mode = (max_binindex * spread / (nbin - 1)) + min;
-      
-    median = 0.;
+
+    int nPixels = nx * ny;
+    slist<double> vecImage;
+    for (int ix = 0; ix < nx; ix++)
+      for (int iy = 0; iy < ny; iy++)
+       vecImage.push_front (v[ix][iy]);
+    vecImage.sort();
+    slist<double>::const_iterator iter = vecImage.begin();
+    for (int i = 0; i < (nPixels / 2) - 1; i++)
+      iter++; // Advance iterator to (nPixels / 2) - 1;
+
+    if (nPixels % 2) {  // Odd
+      iter++;
+      median = *iter;
+    } else                // Even
+      median = (*iter++ + *iter) / 2;
 }