** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: imagefile.cpp,v 1.7 2000/07/11 10:32:44 kevin Exp $
+** $Id: imagefile.cpp,v 1.9 2000/07/15 08:36:13 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
}
int
-ImageFile::display (void)
+ImageFile::display (void) const
{
double pmin, pmax;
- // getPixelValueRange (pmin, pmax);
+ getMinMax (pmin, pmax);
return (displayScaling (1, pmin, pmax));
}
int
-ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const ImageFileValue pmax)
+ImageFile::displayScaling (const int scale, const ImageFileValue pmin, const ImageFileValue pmax) const
{
- int grayscale[256];
int nx = m_nx;
int ny = m_ny;
- ImageFileArray v = getArray();
+ ImageFileArrayConst v = getArray();
+ if (v == NULL || nx == 0 || ny == 0)
+ return 0;
#if HAVE_G2_H
int pens [nx * ny * scale * scale ];
double view_scale = 255 / (pmax - pmin);
int id_X11 = g2_open_X11 (nx * scale, ny * scale);
-
+ int grayscale[256];
for (int i = 0; i < 256; i++) {
double cval = i / 255.;
grayscale[i] = g2_ink (id_X11, cval, cval, cval);
return false;
}
ImageFileArrayConst v = getArray();
+ if (v == NULL || m_nx == 0 || m_ny == 0)
+ return false;
+
ImageFileArrayConst vComp = imComp.getArray();
double myMean = 0.;
- for (int ix = 0; ix < m_nx; ix++) {
- for (int iy = 0; iy < m_ny; iy++) {
+ for (unsigned int ix = 0; ix < m_nx; ix++) {
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
myMean += v[ix][iy];
}
}
double absErrorSum = 0.;
double sqDiffFromMeanSum = 0.;
double absValueSum = 0.;
- for (int ix = 0; ix < m_nx; ix++) {
- for (int iy = 0; iy < m_ny; iy++) {
+ for (unsigned int ix = 0; ix < m_nx; ix++) {
+ for (unsigned int iy = 0; iy < m_ny; iy++) {
double diff = v[ix][iy] - vComp[ix][iy];
sqErrorSum += diff * diff;
absErrorSum += fabs(diff);
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;
+ return true;
}
+ return false;
}
int ny = m_ny;
ImageFileArrayConst v = getArray();
+ if (v == NULL || nx == 0 || ny == 0)
+ return;
+
mean = 0;
min = v[0][0];
max = v[0][0];
}
+void
+ImageFile::getMinMax (double& min, double& max) const
+{
+ int nx = m_nx;
+ int ny = m_ny;
+ ImageFileArrayConst v = getArray();
+
+ if (v == NULL || nx == 0 || ny == 0)
+ return;
+
+ min = v[0][0];
+ max = v[0][0];
+ for (int ix = 0; ix < nx; ix++) {
+ for (int iy = 0; iy < ny; iy++) {
+ if (v[ix][iy] > max)
+ max = v[ix][iy];
+ if (v[ix][iy] < min)
+ min = v[ix][iy];
+ }
+ }
+}
+
void
ImageFile::writeImagePGM (const char *outfile, int nxcell, int nycell, double densmin, double densmax)
{