projects
/
ctsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
r297: fix scaling by viewport for text sizes
[ctsim.git]
/
libctsim
/
imagefile.cpp
diff --git
a/libctsim/imagefile.cpp
b/libctsim/imagefile.cpp
index 96577555ac68a27ea21503f3c6c6eeda23a48059..3e97fb25c3db7315c25625e8a54ae373ab6299dd 100644
(file)
--- 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
**
** 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.
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
**
** 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)
\r
F32Image::F32Image (int nx, int ny)
\r
- : Array2dFile
::Array2dFile
(nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32)
\r
+ : Array2dFile (nx, ny, sizeof(kfloat32), Array2dFile::PIXEL_FLOAT32)
\r
{
\r
}
\r
\r
{
\r
}
\r
\r
-F32Image::F32Image (void)
[
\r
- : Array2dFile
::Array2dFile
()
\r
+F32Image::F32Image (void)
\r
+ : Array2dFile()
\r
{
\r
setPixelFormat (Array2dFile::PIXEL_FLOAT32);
\r
setPixelSize (sizeof(kfloat32));
\r
}
\r
\r
F64Image::F64Image (int nx, int ny)
\r
{
\r
setPixelFormat (Array2dFile::PIXEL_FLOAT32);
\r
setPixelSize (sizeof(kfloat32));
\r
}
\r
\r
F64Image::F64Image (int nx, int ny)
\r
- : Array2dFile
::Array2dFile
(nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64)
\r
+ : Array2dFile (nx, ny, sizeof(kfloat64), Array2dFile::PIXEL_FLOAT64)
\r
{
\r
}
\r
\r
F64Image::F64Image (void)
\r
{
\r
}
\r
\r
F64Image::F64Image (void)
\r
- : Array2dFile
::Array2dFile
()
\r
+ : Array2dFile ()
\r
{
\r
setPixelFormat (PIXEL_FLOAT64);
\r
setPixelSize (sizeof(kfloat64));
\r
{
\r
setPixelFormat (PIXEL_FLOAT64);
\r
setPixelSize (sizeof(kfloat64));
\r
@@
-159,14
+159,14
@@
ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r,
double absErrorSum = 0.;
double sqDiffFromMeanSum = 0.;
double absValueSum = 0.;
double absErrorSum = 0.;
double sqDiffFromMeanSum = 0.;
double absValueSum = 0.;
- for (unsigned int ix
= 0; ix < m_nx; ix
++) {
+ for (unsigned int ix
2 = 0; ix2 < m_nx; ix2
++) {
for (unsigned int iy = 0; iy < m_ny; iy++) {
for (unsigned int iy = 0; iy < m_ny; iy++) {
- double diff = v[ix
][iy] - vComp[ix
][iy];
+ double diff = v[ix
2][iy] - vComp[ix2
][iy];
sqErrorSum += diff * diff;
absErrorSum += fabs(diff);
sqErrorSum += diff * diff;
absErrorSum += fabs(diff);
- double diffFromMean = v[ix][iy] - myMean;
+ double diffFromMean = v[ix
2
][iy] - myMean;
sqDiffFromMeanSum += diffFromMean * diffFromMean;
sqDiffFromMeanSum += diffFromMean * diffFromMean;
- absValueSum += fabs(v[ix][iy]);
+ absValueSum += fabs(v[ix
2
][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;
int hx = m_nx / 2;
int hy = m_ny / 2;
double eMax = -1;
- for (int ix
= 0; ix < hx; ix
++) {
+ for (int ix
3 = 0; ix3 < hx; ix3
++) {
for (int iy = 0; iy < hy; iy++) {
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*ix
3][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*ix
3][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;
double error = fabs (avgPixel - avgPixelComp);
if (error > eMax)
eMax = error;
@@
-193,14
+193,14
@@
ImageFile::comparativeStatistics (const ImageFile& imComp, double& d, double& r,
bool
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)) {
{
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;
return true;
}
return false;
@@
-208,18
+208,18
@@
ImageFile::printComparativeStatistics (const ImageFile& imComp, ostream& os) con
void
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);
{
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;
}
}
@@
-252,11
+252,11
@@
ImageFile::statistics (double& min, double& max, double& mean, double& mode, dou
double spread = max - min;
mode = 0;
stddev = 0;
double spread = max - min;
mode = 0;
stddev = 0;
- for (int ix
= 0; ix < nx; ix
++) {
+ for (int ix
4 = 0; ix4 < nx; ix4
++) {
for (int iy = 0; iy < ny; iy++) {
for (int iy = 0; iy < ny; iy++) {
- int b = static_cast<int>((((v[ix][iy] - min) / spread) * (nbin - 1)) + 0.5);
+ int b = static_cast<int>((((v[ix
4
][iy] - min) / spread) * (nbin - 1)) + 0.5);
hist[b]++;
hist[b]++;
- double diff = (v[ix][iy] - mean);
+ double diff = (v[ix
4
][iy] - mean);
stddev += diff * diff;
}
}
stddev += diff * diff;
}
}
@@
-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;
mode = (max_binindex * spread / (nbin - 1)) + min;
int nPixels = nx * ny;
-
slist
<double> vecImage;
- for (int ix
= 0; ix < nx; ix
++)
+
std::vector
<double> vecImage;
+ for (int ix
5 = 0; ix5 < nx; ix5
++)
for (int iy = 0; iy < ny; iy++)
for (int iy = 0; iy < ny; iy++)
- vecImage.push_front (v[ix][iy]);
- vecImage.sort();
- slist<double>::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());
\r
+
\r
+ if (nPixels % 2) // Odd
+ median = vecImage[((nPixels - 1) / 2)];
\r
+ else // Even
+ median = (vecImage[(nPixels / 2) - 1] + vecImage[nPixels / 2]) / 2;
}
}
@@
-321,7
+317,7
@@
ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double de
int ny = m_ny;
ImageFileArray v = getArray();
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;
if ((fp = fopen (outfile, "wb")) == NULL)
return;
@@
-344,7
+340,8
@@
ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double de
fputc( rowp[ic], fp );
}
}
fputc( rowp[ic], fp );
}
}
-
+
\r
+ delete rowp;
fclose(fp);
}
fclose(fp);
}
@@
-356,7
+353,7
@@
ImageFile::writeImagePGMASCII (const char *outfile, int nxcell, int nycell, doub
int ny = m_ny;
ImageFileArray v = getArray();
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;
if ((fp = fopen (outfile, "wb")) == NULL)
return;
@@
-380,7
+377,8
@@
ImageFile::writeImagePGMASCII (const char *outfile, int nxcell, int nycell, doub
fprintf(fp, "\n");
}
}
fprintf(fp, "\n");
}
}
-
+
\r
+ delete rowp;
fclose(fp);
}
fclose(fp);
}
@@
-397,7
+395,7
@@
ImageFile::writeImagePNG (const char *outfile, int bitdepth, int nxcell, int nyc
int ny = m_ny;
ImageFileArray v = getArray();
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;
if ((fp = fopen (outfile, "wb")) == NULL)
return;
@@
-449,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);
png_write_end(png_ptr, info_ptr);
png_destroy_write_struct(&png_ptr, &info_ptr);
+ delete rowp;
\r
fclose(fp);
}
fclose(fp);
}