Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
biassetprojection.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/BIASpragma.hh>
26 
27 #include <Base/Image/ImageIO.hh>
28 #include <Image/Camera.hh>
29 #include <stdio.h>
30 
31 using namespace BIAS;
32 using namespace std;
33 
34 /**
35  @file
36  @ingroup g_tools
37  @brief load image and projection given by the command line,
38  set projection in image and save image to disk, see biassetprojection.cpp
39  @author jkollmann
40  */
41 void usage() {
42  cout << "Usage: biassetprojection imagefile projectionfile [destfile]"
43  << endl;
44  cout << "This program opens the image file and the projection file" << endl
45  << "given by the command line, copies the projection into the image"
46  << endl
47  << "and saves the image to destfile. If no destfile is given,"
48  << endl << "the source image file is overwritten." << endl;
49 }
50 
51 int main(int argc, char* argv[]) {
52  if (argc < 3) {
53  usage();
54  return 0;
55  }
56 
57  // load image
59  Camera<float> imageFloat;
60  bool isFloat = false;
61 
62  ImageBase tmp;
63  if (ImageIO::Load(argv[1], tmp) != 0) {
64  BIASERR("Failed to load image: " << argv[1]);
65  return 1;
66  }
67 
68  if (tmp.GetStorageType() == ImageBase::ST_float) {
69  if (ImageIO::Load(argv[1], imageFloat) != 0) {
70  BIASERR("Failed to load image: " << argv[1]);
71  return 1;
72  }
73  isFloat = true;
74  } else {
76  if (ImageIO::Load(argv[1], image) != 0) {
77  BIASERR("Failed to load image: " << argv[1]);
78  return 1;
79  }
80  } else {
81  BIASERR("only float and unsigned char images supported");
82  BIASABORT;
83  }
84  }
85 
86  // load projection
87  Projection projection;
88 #ifdef BIAS_HAVE_XML2
89  if (projection.XMLRead(argv[2]) != 0) {
90  BIASERR("Failed to load projection: " << argv[2]);
91  return 1;
92  }
93 #endif //BIAS_HAVE_XML2
94  // set projection in image
95  if (isFloat) {
96  imageFloat.SetProj(projection);
97  imageFloat.UpdateMetaData();
98  } else {
99  image.SetProj(projection);
100  image.UpdateMetaData();
101  }
102 
103  // choose destination file
104  string destfile = argv[1];
105  if (argc >= 4) {
106  destfile = argv[3];
107  }
108 
109  if (isFloat) {
110  if (ImageIO::Save(destfile, imageFloat, ImageIO::FF_auto,
111  BIAS_DEFAULT_SYNC, BIAS_DEFAULT_IMAGE_QUALITY, false, true)
112  != 0) {
113  BIASERR("Failed to save image: " << destfile);
114  return 1;
115  }
116  } else {
117  // save file
118  if (ImageIO::Save(destfile, image, ImageIO::FF_auto, BIAS_DEFAULT_SYNC,
119  BIAS_DEFAULT_IMAGE_QUALITY, false, true) != 0) {
120  BIASERR("Failed to save image: " << destfile);
121  return 1;
122  }
123  }
124 
125  return 0;
126 }
int XMLRead(const std::string &Filename)
derived classes must implement the function XMLIn which is called by this function XMLRead to read ev...
Definition: XMLBase.cpp:78
float image storage type
Definition: ImageBase.hh:118
This class hides the underlying projection model, like projection matrix, spherical camera...
Definition: Projection.hh:70
int SetProj(const Projection &Proj)
Definition: Camera.hh:106
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
int UpdateMetaData()
copy P_ and co.
Definition: Camera.cpp:446
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