[go: up one dir, main page]

Menu

[r994]: / libmona / src / imageselect.cc  Maximize  Restore  History

Download this file

180 lines (128 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* -*- mona-c++ -*-
* Copyright (c) Leipzig, Madrid 2004 - 2008
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// $Id: imageselect.cc 938 2006-07-11 11:57:01Z write1 $
/*! \brief mona-imageselect -- select an image from a bundeled set
\par Description
mona-imageselect selects or excludes a single image from bundeled input images
\par Usage
<code>mona-imageselect --usage</code> (or <code>mona-imageselect --help</code>)
\param --in-image input file holding the image
\param --out-image the converted image
\param --number image to be seletced
\param --not erase image of given number from input
\param --verbose give some verbose information (field size, etc.)
\par Examples
-# Select image no 2 from a set of n images
\code
user> mona-imgageselect -i images.v -o image.v -n 2
\endcode
-# Remove image no 2 from a set of n images (result has n-1 images)
\code
user> mona-imgageselect -i images.v -o image.v -n 2 --not
\endcode
Note, the input format can be anything covered by the io plugins included in \a libmona.
\par Known bugs
None known yet.
\todo writing to stdout and verbosity level
\file imageselect.cc
\author G. Wollny, wollnyATcbs.mpg.de, 2004
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif
#include <string>
// MONA specific
#include <mona.hh>
static const char *revision = "$Revision: 938 $";
using namespace std;
using namespace mona;
int main(int argc, const char *argv[])
{
string in_filename;
string out_filename;
long number=0;
bool erase=false;
using namespace std;
using namespace mona;
try {
// initialize the plugin handler
C3DImageIOPluginHandler imageio;
popt::COptions opts;
opts.push_back(popt::option( in_filename, "in-image", 'i', "input images", "" ));
opts.push_back(popt::option( out_filename, "out-image", 'o', "output image", "-" ));
opts.push_back(popt::option( number, "number", 'n', "select image number (starting with 0)", "0" ));
opts.push_back(popt::option( erase, "not", 'e', "select all images except of the given number"));
vector<string> non_options;
popt::parse_options(argc, argv, opts, non_options);
if ( non_options.size() > 0 )
throw invalid_argument("unknown options");
if (in_filename.empty()) {
cvfatal() << argv[0] << " in-image required" << endl;
return 1;
}
CHistory::instance().append(argv[0], revision, opts);
auto_ptr<C3DImageList> images(imageio.load(in_filename));
C3DImageList::iterator i = images->begin();
if (erase) {
while( number-- ) ++i;
images->erase(i);
imageio.save(images->get_sourceformat(), *images, out_filename);
} else {
if (images.get()) {
if (images->size() > (unsigned long)number) {
C3DImageList out_list;
out_list.push_back( (*images)[number]);
imageio.save(images->get_sourceformat(), out_list, out_filename);
} else {
stringstream s;
s << " no image number " << number << " found!";
throw mona_runtime_error(s.str());
}
} else {
string not_found = ("unable to load image from ") + in_filename;
throw mona_runtime_error(not_found);
}
}
return EXIT_SUCCESS;
} // try
catch (const mona_runtime_error& e){
cerr << argv[0] << " error: " << e.what() << endl;
}
catch (const mona_fatal_error& e){
cerr << argv[0] << " fatal: " << e.what() << endl;
}
catch (const mona_exception& e){
cerr << argv[0] << " error: " << e.what() << endl;
}
catch (const invalid_argument &e){
cerr << argv[0] << " error: " << e.what() << endl;
}
catch (const exception& e){
cerr << argv[0] << " error: " << e.what() << endl;
}
catch (...){
cerr << argv[0] << " unknown exception" << endl;
}
return EXIT_FAILURE;
}
/*
*/