X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fifinfo.cpp;h=bf730ad7d902f1581ec5329d6f6caf3e7e0d2d4a;hp=c911aa5c80948c37d7535b6dddf0a95244e9076c;hb=2f3d6e2580db607105bb072b13e4aff453ae4495;hpb=207332eec9416d299766abb697312cfd27eb890e diff --git a/src/ifinfo.cpp b/src/ifinfo.cpp index c911aa5..bf730ad 100644 --- a/src/ifinfo.cpp +++ b/src/ifinfo.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ifinfo.cpp,v 1.9 2000/06/19 17:58:13 kevin Exp $ +** $Id: ifinfo.cpp,v 1.11 2000/06/26 21:15:24 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 @@ -49,7 +49,7 @@ static struct option my_options[] = void ifinfo_usage (const char *program) { - cout << "usage: " << fileBasename(program) << " infile [OPTIONS]" << endl; + cout << "usage: " << fileBasename(program) << " image1 [image2] [OPTIONS]" << endl; cout << "Imagefile information" << endl; cout << endl; cout << " infile Name of input IF file" << endl; @@ -67,8 +67,10 @@ ifinfo_usage (const char *program) 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; @@ -118,116 +120,53 @@ ifinfo_main (int argc, char *const argv[]) } } - 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->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 (opt_labels) - { - int nlabels = im->getNumLabels(); - int i; + im->printLabels (cout); - for (i = 0; i < nlabels; i++) - { - Array2dFileLabel label; - im->labelRead (label, i); - - if (label.getLabelType() == Array2dFileLabel::L_HISTORY) { - cout << "History: " << endl; - cout << " " << label.getLabelString() << endl; - cout << " calc time = " << label.getCalcTime() << " secs" << endl; - cout << " Timestamp = " << label.getDateString() << endl; - } else if (label.getLabelType() == Array2dFileLabel::L_USER) { - cout << "Note: " << label.getLabelString() << endl; - cout << " Timestamp = %s" << label.getDateString() << endl; - } - cout << endl; - } - } + if (opt_stats) { + if (im2) + cout << "Image 1" << endl; + + 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; + if (opt_labels) + im2->printLabels(cout); + + cout << "Image 2" << endl; + im2->printStatistics (cout); + cout << endl; + + im->printComparativeStatistics (*im2, cout); } + } return (0); }