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.6 2000/06/13 16:20:31 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 fprintf(stdout, "if1_usage: %s infile outfile [OPTIONS]\n", fileBasename(program));
53 fprintf(stdout, "Generate a IF file from a IF file\n");
54 fprintf(stdout, "\n");
55 fprintf(stdout, " --invert Invert image\n");
56 fprintf(stdout, " --log Natural logrithm of image\n");
57 fprintf(stdout, " --exp Natural exponential of image\n");
58 fprintf(stdout, " --sqr Square of image\n");
59 fprintf(stdout, " --sqrt Square root of image\n");
60 fprintf(stdout, " --verbose Verbose modem\n");
61 fprintf(stdout, " --version Print version\n");
62 fprintf(stdout, " --help Print this help message\n");
66 if1_main (int argc, char *const argv[])
81 int c = getopt_long (argc, argv, "", my_options, NULL);
108 fprintf(stdout, "Version %s\n", VERSION);
110 fprintf(stderr, "Unknown version number");
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 (in_file);
140 int nx = im_in->nx();
141 int ny = im_in->ny();
142 im_out = new ImageFile (out_file, nx, ny);
143 im_out->fileCreate ();
145 ImageFileArray vIn = im_in->getArray();
146 ImageFileArray vOut = im_out->getArray();
149 for (ix = 0; ix < nx; ix++)
150 for (iy = 0; iy < ny; iy++)
151 vOut[ix][iy] = - vIn[ix][iy];
152 histString = "Invert transformation";
155 for (ix = 0; ix < nx; ix++)
156 for (iy = 0; iy < ny; iy++)
157 vOut[ix][iy] = log (vIn[ix][iy]);
158 histString = "Log transformation";
161 for (ix = 0; ix < nx; ix++)
162 for (iy = 0; iy < ny; iy++)
163 vOut[ix][iy] = exp (vIn[ix][iy]);
164 histString = "Exp transformation";
167 for (ix = 0; ix < nx; ix++)
168 for (iy = 0; iy < ny; iy++)
169 vOut[ix][iy] = vIn[ix][iy] * vIn[ix][iy];
170 histString = "Sqr transformation";
173 for (ix = 0; ix < nx; ix++)
174 for (iy = 0; iy < ny; iy++)
175 vOut[ix][iy] = sqrt (vIn[ix][iy]);
176 histString = "Sqrt transformation";
179 im_out->arrayDataWrite ();
180 im_out->labelsCopy (*im_in);
181 im_out->labelAdd (Array2dFileLabel::L_HISTORY, histString.c_str());
182 im_out->fileClose ();
190 main (int argc, char *const argv[])
192 return (if1_main(argc, argv));