Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biasaddchannel.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 <Base/Common/LeakChecking.h>
26 
27 #include <Base/Image/ImageIO.hh>
28 #include "Base/Image/ImageConvert.hh"
29 #include "Utils/Param.hh"
30 #include <stdio.h>
31 #include <iostream>
32 
33 using namespace BIAS;
34 using namespace std;
35 
36 
37 
38 /**
39  * @file
40  * @ingroup g_tools
41  * @brief tool for combining images channel-wise, see biasaddchannel.cpp
42  * @author evers
43  */
44 int main(int argc, char *argv[]){
45  // Dart Testing
46  if (argc>=2) {
47  if (strcmp(argv[1],"-darttest") == 0){
48  std::cout<<"started dart test: "<<argv[0]<<std::endl;
49  return 0;
50  }
51  }
52  if (argc < 4) {
53  cout << "Usage: biasaddchannel <image 1> <image 2> <output image>" << endl;
54  return 0;
55  }
56 
57 
58  //bool *planar;
59  Param param;
60  //param = param.AddParamBool("planar","use planar instead of interleaved",false, 'p');
61  int next =1;
62  //next = param.ParseCommandLine(argc, argv);
63  //if (next<0) exit(1);
64  //param.DisableDestructorWarning();
65 
66  //if (argc<3){
67  // param.Usage();
68  // return -1;
69  //}
70 
71  ImageBase im1, im2, diff;
72  if (ImageIO::Load(argv[next], im1)!=0){
73  BIASERR("error loading "<<argv[next]);
74  return -1;
75  }
76  if (ImageIO::Load(argv[next+1], im2)!=0){
77  BIASERR("error loading "<<argv[next+1]);
78  return -1;
79  }
80 
81  if (im1.GetWidth() != im2.GetWidth() ||
82  im1.GetHeight() != im2.GetHeight()){
83  BIASERR("image sizes do not match");
84  return -2;
85  }
86 
87 
88 
89  string newfilename;
90  string fn1,fn2;
91  fn1 = argv[next];
92  fn2 = argv[next+1];
93  newfilename = argv[next+2];
94 
95  Image<float> fim1, fim2, fdiff;
96  Image<unsigned char> ucim1, ucim2, ucdiff;
97 
98 
99  switch (im1.GetStorageType()){
101  ucim1=im1;
102  ucim2=im2;
103  //fim1.SetInterleaved(!(*planar));
104  ucim1.AppendChannel(ucim1);
106  //if (ImageIO::Save(newfilename, ucim2)!=0){
107  if (ImageIO::Save(newfilename, ucim2)!=0){
108  cerr << "error writing diff.mip "<<endl;
109  }
110  break;
111  case ImageBase::ST_float:
112  fim1=im1;
113  fim2=im2;
114  //fim1.SetInterleaved(!(*planar));
116  fim1.AppendChannel(fim2);
117 
118 
119  //if (ImageIO::Save(newfilename, fim1)!=0){
120  if (ImageIO::Save(newfilename, fim1)!=0){
121  cerr << "error writing diff.mip "<<endl;
122  }
123 
124  break;
125  default:
126  cerr << "unknown storage type\n";
127  break;
128  }
129 
130  return 0;
131 }
gray values, 1 channel
Definition: ImageBase.hh:130
int AppendChannel(Image< StorageType > &img)
Definition: Image.cpp:1457
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
float image storage type
Definition: ImageBase.hh:118
unsigned int GetWidth() const
Definition: ImageBase.hh:312
unsigned int GetHeight() const
Definition: ImageBase.hh:319
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
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102