X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=3f7c0beff717a84bafe3f588816dfc50d29bf0db;hp=3a1483dffd89a6a6b7a6e3f98c548fd9da3ab913;hb=a5139613f6b92aeb8db9daa87f021c78d17d82a5;hpb=3fba6928127cd65870bdcd96c8114ad5894247ae diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 3a1483d..3f7c0be 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.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 vecImage; + for (int ix = 0; ix < nx; ix++) + for (int iy = 0; iy < ny; iy++) + vecImage.push_front (v[ix][iy]); + vecImage.sort(); + slist::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; }