Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleConvertRAW.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 #include <Base/Image/ImageIO.hh>
27 #include <Base/Image/ImageConvert.hh>
28 
29 #include <Base/Debug/Error.hh>
30 #include <Base/Debug/DebugSimple.hh>
31 
32 // ----------------------
33 
34 using namespace std;
35 using namespace BIAS;
36 
37 /**
38  @example ExampleConvertRAW.cpp
39  @relates ImageConvert
40  @brief demonstrates reading of RAW4096 image format Reads a .raw RAW4096
41  image which contains a scorpion 1600x1200 Bayer raw pattern with 8 bpp
42  and writes it as a jpeg. This format is used by Mediendom project by
43  Jan Woetzel and Juergen Rienow 2005.
44  @author Jan Woetzel 05/2005
45 */
46 void usage(int /*argc*/, char** /*argv*/)
47 {
48  cout<<"usage: readRAW <img.raw> <out.jpg> <jpgQuality>"<<endl
49  <<"author: Jan Woetzel"<<endl;
50 }
51 
52 // main entry for console application
53 int main(int argc, char** argv){
54  if (argc==1) usage(argc, argv);
55 
56  cout<<"started ";
57  if (argc>0) cout<<argv[0];
58  cout<<endl;
59 
61 
62  string in("img.raw");
63  string out("img_out.jpg");
64  unsigned int quality=100;
65 
66  if (argc>1) in =argv[1];
67  if (argc>2) out=argv[2];
68  if (argc>3) quality=atoi(argv[3]);
69 
70  // work:
71  int result = 0;
72  result = BIAS::ImageIO::ImportRAWwithHeader(in, img);
73  if (result!=0) {
74  cout<<"could not load image "<<in<<endl;
75  return -2;
76  };
77 
78  /// to RGB convert 1 ch Bayer --> 3 channel RGB
80  BIAS::ImageConvert::ToRGB(img, imgRGB);
81 
82  // write result:
83  result = ImageIO::Save(out, imgRGB, BIAS::ImageIO::FF_jpg, false, quality,false,false);
84  if (result!=0)
85  cout<<"could not write image."<<endl;
86 
87 #ifdef BIAS_HAVE_OPENCV
88  imgRGB.Display("imgRGB",true, false, true, 6000);
89 #endif // BIAS_HAVE_OPENCV
90 
91  cout<<"done."<<endl;
92 }
93 
int Display(const std::string &DestWin, const bool &autoresize, const bool &moveToTopLeft, const bool &waitForKey, const unsigned int &delayMsec=DEFAULT_Display_delay, const float &scale=DEFAULT_32to8_scale, const bool &allowAlphaWindow=false) const
OpenCV onscreen popup display, very useful for fast debugging. (JW)
Definition: ImageBase.cpp:1414
static int ImportRAWwithHeader(const std::string &filename, BIAS::ImageBase &img)
Reads a proprietary .RAW format from disk A typical file consists of these blocks: ...
Definition: ImageIO.cpp:1791
static int ToRGB(const Image< StorageType > &source, Image< StorageType > &dest)
Create a RGB converted copy of source image in this.