Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biasextractchannel.cpp
1 /*
2  This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23  */
24 
25 #include <Image/Camera.hh>
26 #include <Base/Image/ImageBase.hh>
27 #include <Base/Image/ImageIO.hh>
28 #include <Base/Image/ImageConvert.hh>
29 #include <Base/Image/ImageAttributes.hh>
30 #include <Geometry/PMatrix.hh>
31 #include <bias_config.h>
32 #include <stdio.h>
33 #include <fstream>
34 #include <Utils/Param.hh>
35 
36 #ifdef WIN32
37 # include "Base/Common/getopt_W32.h"
38 #else //not WIN32
39 # include <getopt.h>
40 #endif //WIN32
41 using namespace BIAS;
42 using namespace std;
43 
44 /**
45  @file
46  @ingroup g_tools
47  @brief New one channel image from selected channel of a multichannel image, see biasextractchannel.cpp
48  @author djung
49  */
50 int main(int argc, char *argv[]) {
51  // pic.SetDebugLevel(D_CAM_IO);
52  Param param;
53  bool *help = param.AddParamBool("help", "display help", false, 'h');
54  int *channel = param.AddParamInt("channel", "channel to extract", 0, 0, INT_MAX, 'c');
55 
56  int fup = param.ParseCommandLine(argc, argv);
57 
58  if (*help || fup + 1 >= argc) {
59  cout << "Usage: " << argv[0] << " [options] infile outfile\n";
60  param.Usage();
61  return 0;
62  }
63  string ifile = argv[fup];
64  string ofile = argv[fup + 1];
65 
66  // after getopt() all recognized options are before non-options
67  ifile = argv[argc - 2];
68  ofile = argv[argc - 1];
69 
70  ImageBase pic;
71 
72  if (ImageIO::Load(ifile, pic) < 0) {
73  BIASERR("could not load " <<ifile);
74  exit(1);
75  }
76  if (*channel >= (int)(pic.GetChannelCount())) {
77  BIASERR("image "<<ifile<<" has only "<<pic.GetChannelCount()<<" channels"<<endl);
78  exit(1);
79  }
80  ImageConvert::GetChannel(pic, *channel, true);
81  ImageIO::Save(ofile, pic);
82  return 0;
83 }
84 
bool * AddParamBool(const std::string &name, const std::string &help, bool deflt=false, char cmdshort=0, int Group=GRP_NOSHOW)
Definition: Param.cpp:305
int ParseCommandLine(int &argc, char *argv[])
scan command line arguments for valid parameters
Definition: Param.cpp:1028
static int GetChannel(const Image< StorageType > &source, Image< StorageType > &dest, const unsigned int channel)
Create a new image dest by cropping one of the source images channels.
void Usage(std::ostream &os=std::cout)
print Help-Information to stdout
Definition: Param.cpp:176
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
This class Param provides generic support for parameters.
Definition: Param.hh:231
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
int * AddParamInt(const std::string &name, const std::string &help, int deflt=0, int min=std::numeric_limits< int >::min(), int max=std::numeric_limits< int >::max(), char cmdshort=0, int Group=GRP_NOSHOW)
For all adding routines:
Definition: Param.cpp:276
This is the base class for images in BIAS.
Definition: ImageBase.hh:102