X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=3f7c0beff717a84bafe3f588816dfc50d29bf0db;hp=1b1660dc0375653a4665d990612a11fc89e76140;hb=a5139613f6b92aeb8db9daa87f021c78d17d82a5;hpb=2a39ee3b125e3e2e68bbba2ac15a65039456ff7e diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 1b1660d..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.9 2000/07/15 08:36:13 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 @@ -219,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; @@ -244,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; }