X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=3e97fb25c3db7315c25625e8a54ae373ab6299dd;hb=133c98cb0d4721c9e3b552321b73f4869fba07d6;hp=851b4fdb6d953efb848259debe3e987cac3c7e84;hpb=9703ace3c451ce079967284bf191783736dbc77f;p=ctsim.git diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 851b4fd..3e97fb2 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.18 2000/12/16 02:31:00 kevin Exp $ +** $Id: imagefile.cpp,v 1.21 2000/12/17 19:08: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 @@ -193,14 +193,14 @@ ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r, bool -ImageFile::printComparativeStatistics (const ImageFile& imComp, ostream& os) const +ImageFile::printComparativeStatistics (const ImageFile& imComp, std::ostream& os) const { double d, r, e; if (comparativeStatistics (imComp, d, r, e)) { - os << " Normalized root mean squared distance (d): " << d << endl; - os << " Normalized mean absolute distance (r): " << r << endl; - os << "Worst case distance (2x2 pixel average) (e): " << e << endl; + os << " Normalized root mean squared distance (d): " << d << std::endl; + os << " Normalized mean absolute distance (r): " << r << std::endl; + os << "Worst case distance (2x2 pixel average) (e): " << e << std::endl; return true; } return false; @@ -208,18 +208,18 @@ ImageFile::printComparativeStatistics (const ImageFile& imComp, ostream& os) con void -ImageFile::printStatistics (ostream& os) const +ImageFile::printStatistics (std::ostream& os) const { double min, max, mean, mode, median, stddev; statistics (min, max, mean, mode, median, stddev); - os << " min: " << min << endl; - os << " max: " << max << endl; - os << " mean: " << mean << endl; - os << " mode: " << mode << endl; - os << "median: " << median << endl; - os << "stddev: " << stddev << endl; + os << " min: " << min << std::endl; + os << " max: " << max << std::endl; + os << " mean: " << mean << std::endl; + os << " mode: " << mode << std::endl; + os << "median: " << median << std::endl; + os << "stddev: " << stddev << std::endl; } @@ -274,20 +274,16 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou mode = (max_binindex * spread / (nbin - 1)) + min; int nPixels = nx * ny; - list vecImage; + std::vector vecImage; for (int ix5 = 0; ix5 < nx; ix5++) for (int iy = 0; iy < ny; iy++) - vecImage.push_front (v[ix5][iy]); - vecImage.sort(); - list::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; + vecImage.push_back (v[ix5][iy]); + std::sort(vecImage.begin(), vecImage.end()); + + if (nPixels % 2) // Odd + median = vecImage[((nPixels - 1) / 2)]; + else // Even + median = (vecImage[(nPixels / 2) - 1] + vecImage[nPixels / 2]) / 2; } @@ -399,7 +395,7 @@ ImageFile::writeImagePNG (const char *outfile, int bitdepth, int nxcell, int nyc int ny = m_ny; ImageFileArray v = getArray(); - unsigned char rowp [nx * nxcell * (bitdepth / 8)]; + unsigned char* rowp = new unsigned char [nx * nxcell * (bitdepth / 8)]; if ((fp = fopen (outfile, "wb")) == NULL) return; @@ -451,6 +447,7 @@ ImageFile::writeImagePNG (const char *outfile, int bitdepth, int nxcell, int nyc png_write_end(png_ptr, info_ptr); png_destroy_write_struct(&png_ptr, &info_ptr); + delete rowp; fclose(fp); }