X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=803347f2e76f071c8fd1ae6b110ac04a84b61994;hp=96577555ac68a27ea21503f3c6c6eeda23a48059;hb=ee0105d74fec9d6bfd236e22e9e1d315e46c568e;hpb=806adf54f5b8d061662696b3b498bfab3cd8b2e6 diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 9657755..803347f 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.16 2000/12/04 05:36:57 kevin Exp $ +** $Id: imagefile.cpp,v 1.17 2000/12/06 01:46:43 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 @@ -29,24 +29,24 @@ F32Image::F32Image (int nx, int ny) - : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32) + : Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32) { } -F32Image::F32Image (void)[ - : Array2dFile::Array2dFile() +F32Image::F32Image (void) + : Array2dFile() { setPixelFormat (Array2dFile::PIXEL_FLOAT32); setPixelSize (sizeof(kfloat32)); } F64Image::F64Image (int nx, int ny) - : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64) + : Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64) { } F64Image::F64Image (void) - : Array2dFile::Array2dFile () + : Array2dFile () { setPixelFormat (PIXEL_FLOAT64); setPixelSize (sizeof(kfloat64)); @@ -159,14 +159,14 @@ ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r, double absErrorSum = 0.; double sqDiffFromMeanSum = 0.; double absValueSum = 0.; - for (unsigned int ix = 0; ix < m_nx; ix++) { + for (unsigned int ix2 = 0; ix2 < m_nx; ix2++) { for (unsigned int iy = 0; iy < m_ny; iy++) { - double diff = v[ix][iy] - vComp[ix][iy]; + double diff = v[ix2][iy] - vComp[ix2][iy]; sqErrorSum += diff * diff; absErrorSum += fabs(diff); - double diffFromMean = v[ix][iy] - myMean; + double diffFromMean = v[ix2][iy] - myMean; sqDiffFromMeanSum += diffFromMean * diffFromMean; - absValueSum += fabs(v[ix][iy]); + absValueSum += fabs(v[ix2][iy]); } } @@ -176,10 +176,10 @@ ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r, int hx = m_nx / 2; int hy = m_ny / 2; double eMax = -1; - for (int ix = 0; ix < hx; ix++) { + for (int ix3 = 0; ix3 < hx; ix3++) { for (int iy = 0; iy < hy; iy++) { - double avgPixel = 0.25 * (v[2*ix][2*iy] + v[2*ix+1][2*iy] + v[2*ix][2*iy+1] + v[2*ix+1][2*iy+1]); - double avgPixelComp = 0.25 * (vComp[2*ix][2*iy] + vComp[2*ix+1][2*iy] + vComp[2*ix][2*iy+1] + vComp[2*ix+1][2*iy+1]); + double avgPixel = 0.25 * (v[2*ix3][2*iy] + v[2*ix3+1][2*iy] + v[2*ix3][2*iy+1] + v[2*ix3+1][2*iy+1]); + double avgPixelComp = 0.25 * (vComp[2*ix3][2*iy] + vComp[2*ix3+1][2*iy] + vComp[2*ix3][2*iy+1] + vComp[2*ix3+1][2*iy+1]); double error = fabs (avgPixel - avgPixelComp); if (error > eMax) eMax = error; @@ -252,9 +252,9 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou double spread = max - min; mode = 0; stddev = 0; - for (int ix = 0; ix < nx; ix++) { + for (int ix4 = 0; ix4 < nx; ix4++) { for (int iy = 0; iy < ny; iy++) { - int b = static_cast((((v[ix][iy] - min) / spread) * (nbin - 1)) + 0.5); + int b = static_cast((((v[ix4][iy] - min) / spread) * (nbin - 1)) + 0.5); hist[b]++; double diff = (v[ix][iy] - mean); stddev += diff * diff; @@ -274,12 +274,12 @@ ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou mode = (max_binindex * spread / (nbin - 1)) + min; int nPixels = nx * ny; - slist vecImage; - for (int ix = 0; ix < nx; ix++) + list vecImage; + for (int ix5 = 0; ix5 < nx; ix5++) for (int iy = 0; iy < ny; iy++) - vecImage.push_front (v[ix][iy]); + vecImage.push_front (v[ix5][iy]); vecImage.sort(); - slist::const_iterator iter = vecImage.begin(); + list::const_iterator iter = vecImage.begin(); for (int i = 0; i < (nPixels / 2) - 1; i++) iter++; // Advance iterator to (nPixels / 2) - 1; @@ -321,7 +321,7 @@ ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double de int ny = m_ny; ImageFileArray v = getArray(); - unsigned char rowp [nx * nxcell]; + unsigned char* rowp = new unsigned char [nx * nxcell]; if ((fp = fopen (outfile, "wb")) == NULL) return; @@ -344,7 +344,8 @@ ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double de fputc( rowp[ic], fp ); } } - + + delete rowp; fclose(fp); } @@ -356,7 +357,7 @@ ImageFile::writeImagePGMASCII (const char *outfile, int nxcell, int nycell, doub int ny = m_ny; ImageFileArray v = getArray(); - unsigned char rowp [nx * nxcell]; + unsigned char* rowp = new unsigned char [nx * nxcell]; if ((fp = fopen (outfile, "wb")) == NULL) return; @@ -380,7 +381,8 @@ ImageFile::writeImagePGMASCII (const char *outfile, int nxcell, int nycell, doub fprintf(fp, "\n"); } } - + + delete rowp; fclose(fp); }