Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleConvertHDR.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 /**
26  @example ExampleConvertHDR.cpp
27  @relates ConvertHDR
28  @brief Example for usage of ConvertHDR class
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <Base/Image/Image.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Image/ConvertHDR.hh>
36 #include <Base/Common/FileHandling.hh>
37 #include <Base/Image/ImageConvert.hh>
38 
39 #include <iostream>
40 
41 using namespace BIAS;
42 using namespace std;
43 
44 int main(int argc, char *argv[])
45 {
46 
47  if (argc <2) {
48  cerr<< argv[0] <<" <ppmfile1> <ppmfile2> ... "<<endl;
49  exit(1);
50  }
51 
52 
53  ConvertHDR<float> convertF;
55  Image<float> inputImgF;
56  Image<float> imageF;
57 
58  Image<float> greyF;
59  Image<unsigned char> greyImg;
60  for(int i = 1; i < argc; i++){
61  imageF.SetZero();
62  cout << "argv[i] " << argv[i] << endl;
63  if ((ImageIO::ImportImage(argv[i], inputImgF)) != 0){
64  cerr << "error loading file " << argv[i] << endl;
65  exit (-1);
66  }
67 
68  ImageConvert::ToGrey(inputImgF, greyF);
69 
70  if(convertF.ToUnsignedCharGamma(inputImgF, dstF, 0.5, 65535)!=0){
71  BIASERR("could not convert ushort image to uchar");
72  return -1;
73  }
74 
75  if(convertF.ToUnsignedCharGamma(greyF, greyImg, 0.5, 65535)!=0){
76  BIASERR("could not convert ushort image to uchar");
77  return -1;
78  }
79 
80  string fileName = "gammaF" + FileHandling::LeadingZeroString(i, 4) + ".mip";
81  //ImageIO::Save(fileName, dstF);
82  ImageIO::Save(fileName, dstF);
83 
84  string fileNameGrey = "gammaGrey" + FileHandling::LeadingZeroString(i, 4) + ".mip";
85  //ImageIO::Save(fileNameGrey, greyImg);
86  ImageIO::Save(fileNameGrey, greyImg);
87 
88  }
89 
90 
91 
92 #ifdef BUILD_IMAGE_USHORT
97 
98  for(int i = 1; i < argc; i++){
99  image.SetZero();
100  cout << "argv[i] " << argv[i] << endl;
101  if ((ImageIO::ImportImage(argv[i], image)) != 0){
102  cerr << "error loading file " << argv[i] << endl;
103  exit (-1);
104  }
105 // image.ScaleShiftBetween(0, 65535);
106  if(converter.ToUnsignedCharGamma(image, dst, 0.5, 65535)!=0){
107  BIASERR("could not convert ushort image to uchar");
108  return -1;
109  }
110 
111  string fileName = "gammaUC" + FileHandling::LeadingZeroString(i, 4) + ".mip";
112  //ImageIO::Save(fileName, dst);
113  ImageIO::Save(fileName, dst);
114  }
115 
116 #endif
117  return 0;
118 }
119 
This class handles conversions of HDR images to for example unsigned char.
Definition: ConvertHDR.hh:47
static int ImportImage(const std::string &filename, ImageBase &result)
Try to load/import an image from a file using external libs.
Definition: ImageIO.cpp:378
int ToUnsignedCharGamma(BIAS::Image< StorageType > &src, BIAS::Image< unsigned char > &dst, float gamma, unsigned int currentMaxVal)
Conversion to unsigned char image, leaves min/max part intact.
Definition: ConvertHDR.cpp:119
static std::string LeadingZeroString(const int &n, const unsigned int &digits=DEFAULT_LEADING_ZEROS)
Create a string with leading zeroes from number.
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
void SetZero()
zeroes the image
Definition: ImageBase.hh:83
static int ToGrey(const ImageBase &source, ImageBase &dest)
wrapper for the templated function ToGrey