1 /*****************************************************************************
5 ** Purpose: Manipulate a single image file
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: Aug 1984
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: if-1.cpp,v 1.9 2000/06/26 21:15:24 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 * if-1.c Filter a single IF file
34 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
36 static struct option my_options[] =
38 {"invert", 0, 0, O_INVERT},
39 {"verbose", 0, 0, O_VERBOSE},
43 {"sqrt", 0, 0, O_SQRT},
44 {"help", 0, 0, O_HELP},
45 {"version", 0, 0, O_VERSION},
50 if1_usage (const char *program)
52 cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << endl;
53 cout << "Generate a IF file from a IF file" << endl;
55 cout << " --invert Invert image" << endl;
56 cout << " --log Natural logrithm of image" << endl;
57 cout << " --exp Natural exponential of image" << endl;
58 cout << " --sqr Square of image" << endl;
59 cout << " --sqrt Square root of image" << endl;
60 cout << " --verbose Verbose modem" << endl;
61 cout << " --version Print version" << endl;
62 cout << " --help Print this help message" << endl;
66 if1_main (int argc, char *const argv[])
81 int c = getopt_long (argc, argv, "", my_options, NULL);
108 cout << "Version " << VERSION << endl;
110 cout << "Unknown version number" << endl;
123 if (optind + 2 != argc)
129 in_file = argv[optind];
130 out_file = argv[optind + 1];
135 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
138 im_in = new ImageFile ();
139 im_in->fileRead (in_file);
140 int nx = im_in->nx();
141 int ny = im_in->ny();
142 im_out = new ImageFile (nx, ny);
144 ImageFileArray vIn = im_in->getArray();
145 ImageFileArray vOut = im_out->getArray();
148 for (ix = 0; ix < nx; ix++)
149 for (iy = 0; iy < ny; iy++)
150 vOut[ix][iy] = - vIn[ix][iy];
151 histString = "Invert transformation";
154 for (ix = 0; ix < nx; ix++)
155 for (iy = 0; iy < ny; iy++)
156 vOut[ix][iy] = log (vIn[ix][iy]);
157 histString = "Log transformation";
160 for (ix = 0; ix < nx; ix++)
161 for (iy = 0; iy < ny; iy++)
162 vOut[ix][iy] = exp (vIn[ix][iy]);
163 histString = "Exp transformation";
166 for (ix = 0; ix < nx; ix++)
167 for (iy = 0; iy < ny; iy++)
168 vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
169 histString = "Sqr transformation";
172 for (ix = 0; ix < nx; ix++)
173 for (iy = 0; iy < ny; iy++)
174 vOut[ix][iy] = sqrt (vIn[ix][iy]);
175 histString = "Sqrt transformation";
178 im_out->labelsCopy (*im_in);
179 im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
180 im_out->fileWrite (out_file);
188 main (int argc, char *const argv[])
193 retval = if1_main(argc, argv);
194 } catch (exception e) {
195 cerr << "Exception: " << e.what() << endl;
197 cerr << "Unknown exception" << endl;