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-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
27 * if1.c Filter a single IF file
32 enum {O_LOG, O_EXP, O_SQRT, O_SQR, O_INVERT, O_VERBOSE, O_HELP, O_VERSION};
34 static struct option my_options[] =
36 {"invert", 0, 0, O_INVERT},
37 {"verbose", 0, 0, O_VERBOSE},
41 {"sqrt", 0, 0, O_SQRT},
42 {"help", 0, 0, O_HELP},
43 {"version", 0, 0, O_VERSION},
47 static const char* g_szIdStr = "$Id$";
50 if1_usage (const char *program)
52 std::cout << "usage: " << fileBasename(program) << " infile outfile [OPTIONS]" << std::endl;
53 std::cout << "Generate a IF file from a IF file" << std::endl;
54 std::cout << std::endl;
55 std::cout << " --invert Invert image" << std::endl;
56 std::cout << " --log Natural logrithm of image" << std::endl;
57 std::cout << " --exp Natural exponential of image" << std::endl;
58 std::cout << " --sqr Square of image" << std::endl;
59 std::cout << " --sqrt Square root of image" << std::endl;
60 std::cout << " --verbose Verbose mode" << std::endl;
61 std::cout << " --version Print version" << std::endl;
62 std::cout << " --help Print this help message" << std::endl;
66 if1_main (int argc, char *const argv[])
79 int c = getopt_long (argc, argv, "", my_options, NULL);
106 std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
108 std::cout << "Unknown version number" << std::endl;
121 if (optind + 2 != argc)
127 in_file = argv[optind];
128 out_file = argv[optind + 1];
130 std::string histString;
132 if (opt_invert || opt_log || opt_exp || opt_sqr || opt_sqrt) {
134 im_in.fileRead (in_file);
137 ImageFile im_out (nx, ny);
140 im_in.invertPixelValues (im_out);
141 histString = "Invert transformation";
145 histString = "Logrithmic transformation";
149 histString = "Exponential transformation";
152 im_in.square (im_out);
153 histString = "Square transformation";
157 histString = "Square root transformation";
160 im_out.labelsCopy (im_in);
161 im_out.labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
162 im_out.fileWrite (out_file);
170 main (int argc, char *const argv[])
175 retval = if1_main(argc, argv);
176 } catch (exception e) {
177 std::cerr << "Exception: " << e.what() << std::endl;
179 std::cerr << "Unknown exception" << std::endl;