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.4 2000/12/16 07:28:25 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},
49 static const char* g_szIdStr = "$Id: if-1.cpp,v 1.4 2000/12/16 07:28:25 kevin Exp $";
52 if1_usage (const char *program)
54 std::cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << std::endl;
55 std::cout << "Generate a IF file from a IF file" << std::endl;
56 std::cout << std::endl;
57 std::cout << " --invert Invert image" << std::endl;
58 std::cout << " --log Natural logrithm of image" << std::endl;
59 std::cout << " --exp Natural exponential of image" << std::endl;
60 std::cout << " --sqr Square of image" << std::endl;
61 std::cout << " --sqrt Square root of image" << std::endl;
62 std::cout << " --verbose Verbose modem" << std::endl;
63 std::cout << " --version Print version" << std::endl;
64 std::cout << " --help Print this help message" << std::endl;
68 if1_main (int argc, char *const argv[])
83 int c = getopt_long (argc, argv, "", my_options, NULL);
110 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
112 std::cout << "Unknown version number" << std::endl;
125 if (optind + 2 != argc)
131 in_file = argv[optind];
132 out_file = argv[optind + 1];
135 std::string histString;
137 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
140 im_in = new ImageFile ();
141 im_in->fileRead (in_file);
142 int nx = im_in->nx();
143 int ny = im_in->ny();
144 im_out = new ImageFile (nx, ny);
146 ImageFileArray vIn = im_in->getArray();
147 ImageFileArray vOut = im_out->getArray();
150 for (ix = 0; ix < nx; ix++)
151 for (iy = 0; iy < ny; iy++)
152 vOut[ix][iy] = - vIn[ix][iy];
153 histString = "Invert transformation";
156 for (ix = 0; ix < nx; ix++)
157 for (iy = 0; iy < ny; iy++)
158 vOut[ix][iy] = log (vIn[ix][iy]);
159 histString = "Log transformation";
162 for (ix = 0; ix < nx; ix++)
163 for (iy = 0; iy < ny; iy++)
164 vOut[ix][iy] = exp (vIn[ix][iy]);
165 histString = "Exp transformation";
168 for (ix = 0; ix < nx; ix++)
169 for (iy = 0; iy < ny; iy++)
170 vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
171 histString = "Sqr transformation";
174 for (ix = 0; ix < nx; ix++)
175 for (iy = 0; iy < ny; iy++)
176 vOut[ix][iy] = sqrt (vIn[ix][iy]);
177 histString = "Sqrt transformation";
180 im_out->labelsCopy (*im_in);
181 im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
182 im_out->fileWrite (out_file);
190 main (int argc, char *const argv[])
195 retval = if1_main(argc, argv);
196 } catch (exception e) {
197 cerr << "Exception: " << e.what() << std::endl;
199 cerr << "Unknown exception" << std::endl;