** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: ifinfo.cpp,v 1.4 2000/06/08 16:43:10 kevin Exp $
+** $Id: ifinfo.cpp,v 1.12 2000/06/27 10:48:11 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
void
ifinfo_usage (const char *program)
{
- fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
- fprintf(stdout, "Imagefile information\n");
- fprintf(stdout, "\n");
- fprintf(stdout, " infile Name of input SDF file\n");
- fprintf(stdout, " --display Display image\n");
- fprintf(stdout, " --labels Print image labels (default)\n");
- fprintf(stdout, " --no-labels Do not print image labels\n");
- fprintf(stdout, " --stats Print image statistics (default)\n");
- fprintf(stdout, " --no-stats Do not print image statistics\n");
- fprintf(stdout, " --debug Debug mode\n");
- fprintf(stdout, " --verbose Verbose mode\n");
- fprintf(stdout, " --version Print version\n");
- fprintf(stdout, " --help Print this help message\n");
+ cout << "usage: " << fileBasename(program) << " image1 [image2] [OPTIONS]" << endl;
+ cout << "Imagefile information" << endl;
+ cout << endl;
+ cout << " infile Name of input IF file" << endl;
+ cout << " --display Display image" << endl;
+ cout << " --labels Print image labels (default)" << endl;
+ cout << " --no-labels Do not print image labels" << endl;
+ cout << " --stats Print image statistics (default)" << endl;
+ cout << " --no-stats Do not print image statistics" << endl;
+ cout << " --debug Debug mode" << endl;
+ cout << " --verbose Verbose mode" << endl;
+ cout << " --version Print version" << endl;
+ cout << " --help Print this help message" << endl;
}
int
ifinfo_main (int argc, char *const argv[])
{
- ImageFile *im;
- char *in_file;
+ ImageFile *im = NULL;
+ ImageFile* im2 = NULL;
+ string in_file;
+ string in2_file;
int opt_verbose = 0;
int opt_stats = 1;
int opt_labels = 1;
break;
case O_VERSION:
#ifdef VERSION
- fprintf(stdout, "Version %s\n", VERSION);
+ cout << "Version " << VERSION << endl;
#else
- fprintf(stderr, "Unknown version number");
+ cout << "Unknown version number" << endl;
#endif
- exit(0);
+ return (0);
case O_HELP:
case '?':
ifinfo_usage(argv[0]);
}
}
- if (optind + 1 != argc)
- {
- ifinfo_usage(argv[0]);
- return (1);
- }
+ if (optind + 2 == argc) {
+ in2_file = argv [optind+1];
+ } else if (optind + 1 != argc) {
+ ifinfo_usage (argv[0]);
+ return (1);
+ }
in_file = argv[optind];
- im = new ImageFile (in_file);
- if (! im->adf.fileRead ()) {
- sys_error (ERR_WARNING, "Unable to read file %s", in_file);
+ im = new ImageFile ();
+ if (! im->fileRead (in_file.c_str())) {
+ sys_error (ERR_WARNING, "Unable to read file %s", in_file.c_str());
return (1);
}
+ if (in2_file != "") {
+ im2 = new ImageFile();
+ if (! im2->fileRead (in2_file.c_str())) {
+ sys_error (ERR_WARNING, "Unable to read file %s", in2_file.c_str());
+ return (1);
+ }
+ }
+
+ if (opt_stats)
+ cout << "Image size: (" << im->nx() << "," << im->ny() << ")" << endl << endl;
+ if (im2)
+ cout << "Image 1: " << im->getFilename() << endl;
+
if (opt_labels)
- {
- int nlabels = im->adf.getNumLabels();
- int i;
+ im->printLabels (cout);
- for (i = 0; i < nlabels; i++)
- {
- Array2dFileLabel label;
- im->adf.labelRead (label, i);
-
- string str;
- label.getDateString (str);
-
- if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
- cout << "History: " << label.getLabelString() << endl;
- cout << " calc time = " << label.getCalcTime() << " secs" << endl;
- cout << " Timestamp = " << str << endl;
- } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
- cout << "Note: " << label.getLabelString() << endl;
- cout << " Timestamp = %s" << str << endl;
- }
- }
- }
+ if (opt_stats) {
+ im->printStatistics (cout);
- if (opt_stats)
- {
- double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
- double mode = 0, mean = 0, stddev = 0;
- double spread;
- int hist[256];
- int ibin, nbin = 256;
- int max_bin, max_binindex;
- double maxbin;
- int ix, iy;
-
- maxbin = nbin - 1;
- ImageFileArray v = im->getArray();
- int nx = im->nx();
- int ny = im->ny();
-
- for (ix = 0; ix < nx; ix++)
- {
- for (iy = 0; iy < ny; iy++)
- {
- if (v[ix][iy] > maxfound)
- maxfound = v[ix][iy];
- if (v[ix][iy] < minfound)
- minfound = v[ix][iy];
- mean += v[ix][iy];
- }
- }
- spread = maxfound - minfound;
- if (spread == 0)
- mode = minfound;
- else
- {
- for (ibin = 0; ibin < nbin; ibin++)
- hist[ibin] = 0;
- for (ix = 0; ix < nx; ix++)
- {
- for (iy = 0; iy < ny; iy++)
- {
- int b = (int) ((((v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
- hist[b]++;
- }
- }
- max_binindex = 0;
- max_bin = -1;
- for (ibin = 0; ibin < nbin; ibin++)
- {
- if (hist[ibin] > max_bin)
- {
- max_bin = hist[ibin];
- max_binindex = ibin;
- }
- }
- mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
- }
+ if (im2) {
+ cout << endl;
- mean /= nx * ny;
- for (ix = 0; ix < nx; ix++)
- {
- for (iy = 0; iy < ny; iy++)
- {
- double diff = (v[ix][iy] - mean);
- stddev += diff * diff;
- }
- }
- stddev = sqrt(stddev / (nx * ny));
- cout << "nx=" << nx << endl;
- cout << "nx=" << ny << endl;
- cout << "min=" << minfound << endl;
- cout << "max=" << maxfound << endl;
- cout << "mean=" << mean << endl;
- cout << "mode=" << mode << endl;
- cout << "stddef=" << stddev << endl;
+ cout << "Image 2: " << im2->getFilename() << endl;
+
+ if (opt_labels)
+ im2->printLabels(cout);
+
+ im2->printStatistics (cout);
+ cout << endl;
+
+ im->printComparativeStatistics (*im2, cout);
}
+ }
return (0);
}
int
main (int argc, char *const argv[])
{
- return (ifinfo_main(argc, argv));
+ int retval = 1;
+
+ try {
+ retval = ifinfo_main(argc, argv);
+ } catch (exception e) {
+ cerr << "Exception: " << e.what() << endl;
+ } catch (...) {
+ cerr << "Unknown exception" << endl;
+ }
+
+ return (retval);
}
#endif