1 /*****************************************************************************
5 ** Purpose: Display information about an image file
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: April 2000
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: ifinfo.cpp,v 1.5 2000/06/09 11:03:08 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
29 * ifinfo.c Display info on sdf files
34 enum { O_LABELS, O_STATS, O_NO_STATS, O_NO_LABELS, O_VERBOSE, O_HELP, O_VERSION, O_DEBUG };
36 static struct option my_options[] =
38 {"labels", 0, 0, O_LABELS},
39 {"no-labels", 0, 0, O_NO_LABELS},
40 {"stats", 0, 0, O_STATS},
41 {"no-stats", 0, 0, O_NO_STATS},
42 {"debug", 0, 0, O_DEBUG},
43 {"verbose", 0, 0, O_VERBOSE},
44 {"help", 0, 0, O_HELP},
45 {"version", 0, 0, O_VERSION},
50 ifinfo_usage (const char *program)
52 fprintf(stdout, "usage: %s infile [OPTIONS]\n", kbasename(program));
53 fprintf(stdout, "Imagefile information\n");
54 fprintf(stdout, "\n");
55 fprintf(stdout, " infile Name of input SDF file\n");
56 fprintf(stdout, " --display Display image\n");
57 fprintf(stdout, " --labels Print image labels (default)\n");
58 fprintf(stdout, " --no-labels Do not print image labels\n");
59 fprintf(stdout, " --stats Print image statistics (default)\n");
60 fprintf(stdout, " --no-stats Do not print image statistics\n");
61 fprintf(stdout, " --debug Debug mode\n");
62 fprintf(stdout, " --verbose Verbose mode\n");
63 fprintf(stdout, " --version Print version\n");
64 fprintf(stdout, " --help Print this help message\n");
68 ifinfo_main (int argc, char *const argv[])
79 int c = getopt_long (argc, argv, "", my_options, NULL);
106 fprintf(stdout, "Version %s\n", VERSION);
108 fprintf(stderr, "Unknown version number");
113 ifinfo_usage(argv[0]);
116 ifinfo_usage(argv[0]);
121 if (optind + 1 != argc)
123 ifinfo_usage(argv[0]);
127 in_file = argv[optind];
129 im = new ImageFile (in_file);
130 if (! im->fileRead ()) {
131 sys_error (ERR_WARNING, "Unable to read file %s", in_file);
137 int nlabels = im->getNumLabels();
140 for (i = 0; i < nlabels; i++)
142 Array2dFileLabel label;
143 im->labelRead (label, i);
146 label.getDateString (str);
148 if (label.getLabelType() == Array2dFileLabel::L_HISTORY) {
149 cout << "History: " << label.getLabelString() << endl;
150 cout << " calc time = " << label.getCalcTime() << " secs" << endl;
151 cout << " Timestamp = " << str << endl;
152 } else if (label.getLabelType() == Array2dFileLabel::L_USER) {
153 cout << "Note: " << label.getLabelString() << endl;
154 cout << " Timestamp = %s" << str << endl;
161 double minfound = HUGE_VAL, maxfound = -HUGE_VAL;
162 double mode = 0, mean = 0, stddev = 0;
165 int ibin, nbin = 256;
166 int max_bin, max_binindex;
171 ImageFileArray v = im->getArray();
175 for (ix = 0; ix < nx; ix++)
177 for (iy = 0; iy < ny; iy++)
179 if (v[ix][iy] > maxfound)
180 maxfound = v[ix][iy];
181 if (v[ix][iy] < minfound)
182 minfound = v[ix][iy];
186 spread = maxfound - minfound;
191 for (ibin = 0; ibin < nbin; ibin++)
193 for (ix = 0; ix < nx; ix++)
195 for (iy = 0; iy < ny; iy++)
197 int b = (int) ((((v[ix][iy] - minfound) / spread) * (double) maxbin) + 0.5);
203 for (ibin = 0; ibin < nbin; ibin++)
205 if (hist[ibin] > max_bin)
207 max_bin = hist[ibin];
211 mode = (((double) max_binindex) * spread / ((double) maxbin)) + minfound;
215 for (ix = 0; ix < nx; ix++)
217 for (iy = 0; iy < ny; iy++)
219 double diff = (v[ix][iy] - mean);
220 stddev += diff * diff;
223 stddev = sqrt(stddev / (nx * ny));
224 cout << "nx=" << nx << endl;
225 cout << "nx=" << ny << endl;
226 cout << "min=" << minfound << endl;
227 cout << "max=" << maxfound << endl;
228 cout << "mean=" << mean << endl;
229 cout << "mode=" << mode << endl;
230 cout << "stddef=" << stddev << endl;
238 main (int argc, char *const argv[])
240 return (ifinfo_main(argc, argv));