X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctsim%2Fimagefile.cpp;h=96577555ac68a27ea21503f3c6c6eeda23a48059;hp=1b1660dc0375653a4665d990612a11fc89e76140;hb=01ee1e0085970643368d65c38b09008927e24cd5;hpb=e4c1f7f8eb87558c3abf3bf1d20732361f425351 diff --git a/libctsim/imagefile.cpp b/libctsim/imagefile.cpp index 1b1660d..9657755 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.16 2000/12/04 05:36:57 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 @@ -28,6 +28,29 @@ #include "ct.h" +F32Image::F32Image (int nx, int ny) + : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32) + { + } + +F32Image::F32Image (void)[ + : Array2dFile::Array2dFile() + { + setPixelFormat (Array2dFile::PIXEL_FLOAT32); + setPixelSize (sizeof(kfloat32)); + } + +F64Image::F64Image (int nx, int ny) + : Array2dFile::Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64) + { + } + +F64Image::F64Image (void) + : Array2dFile::Array2dFile () + { + setPixelFormat (PIXEL_FLOAT64); + setPixelSize (sizeof(kfloat64)); + } void ImageFile::filterResponse (const char* const domainName, double bw, const char* const filterName, double filt_param) @@ -66,7 +89,7 @@ ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const Ima return 0; #if HAVE_G2_H - int pens [nx * ny * scale * scale ]; + int* pPens = new int [nx * ny * scale * scale ]; double view_scale = 255 / (pmax - pmin); int id_X11 = g2_open_X11 (nx * scale, ny * scale); @@ -76,21 +99,26 @@ ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const Ima grayscale[i] = g2_ink (id_X11, cval, cval, cval); } - for (int i= 0, iy = ny - 1; iy >= 0; iy--) { - for (int ix = 0; ix < nx; ix++) { - int cval = static_cast((v[ix][iy] - pmin) * view_scale); - if (cval < 0) - cval = 0; - else if (cval > 255) - cval = 255; - pens[i++] = grayscale[cval]; + for (int iy = ny - 1; iy >= 0; iy--) { + int iRowPos = ((ny - 1 - iy) * scale) * (nx * scale); + for (int ix = 0; ix < nx; ix++) { + int cval = static_cast((v[ix][iy] - pmin) * view_scale); + if (cval < 0) + cval = 0; + else if (cval > 255) + cval = 255; + for (int sy = 0; sy < scale; sy++) + for (int sx = 0; sx < scale; sx++) + pPens[iRowPos+(sy * nx * scale)+(sx + (ix * scale))] = grayscale[cval]; } } - g2_image (id_X11, 0., 0., nx, ny, pens); + g2_image (id_X11, 0., 0., nx * scale, ny * scale, pPens); + delete pPens; return (id_X11); - +#else + return 0; #endif } @@ -219,7 +247,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 +272,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; } @@ -299,7 +341,7 @@ ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double de } for (int ir = 0; ir < nycell; ir++) { for (int ic = 0; ic < nx * nxcell; ic++) - fprintf(fp, "%c ", rowp[ic]); + fputc( rowp[ic], fp ); } } @@ -315,8 +357,6 @@ ImageFile::writeImagePGMASCII (const char *outfile, int nxcell, int nycell, doub ImageFileArray v = getArray(); unsigned char rowp [nx * nxcell]; - if (rowp == NULL) - return; if ((fp = fopen (outfile, "wb")) == NULL) return;