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: if1.cpp,v 1.4 2000/12/29 19:30: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 * if1.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: if1.cpp,v 1.4 2000/12/29 19:30:08 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 mode" << 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[])
81 int c = getopt_long (argc, argv, "", my_options, NULL);
108 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
110 std::cout << "Unknown version number" << std::endl;
123 if (optind + 2 != argc)
129 in_file = argv[optind];
130 out_file = argv[optind + 1];
132 std::string histString;
134 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
136 im_in.fileRead (in_file);
139 ImageFile im_out (nx, ny);
142 im_in.invertPixelValues (im_out);
143 histString = "Invert transformation";
147 histString = "Logrithmic transformation";
151 histString = "Exponential transformation";
154 im_in.square (im_out);
155 histString = "Square transformation";
159 histString = "Square root transformation";
162 im_out.labelsCopy (im_in);
163 im_out.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
164 im_out.fileWrite (out_file);
172 main (int argc, char *const argv[])
177 retval = if1_main(argc, argv);
178 } catch (exception e) {
179 std::cerr << "Exception: " << e.what() << std::endl;
181 std::cerr << "Unknown exception" << std::endl;