Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDeInterlace2.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  @example ExampleDeInterlace2.cpp
26  @relates DeInterlace
27  @brief Example for deinterlacing interlaced images
28  @ingroup g_examples
29  @author ischiller
30 */
31 
32 #include <Filter/DeInterlace.hh>
33 #include <Filter/Median.hh>
34 #include <Base/Image/ImageIO.hh>
35 #include <Base/Image/ImageConvert.hh>
36 #include <Base/Debug/TimeMeasure.hh>
37 #include <Utils/Param.hh>
38 using namespace BIAS;
39 using namespace std;
40 
41 
42 int ExtractNumbersFromRight(const std::string & inStr,
43  int & number, int& imgNum,
44  int & posL,
45  int & posR, int& posLImg, int& posRImg)
46 {
47  // parse from rigth numeric part of string:
48  number=0;
49  imgNum = 0;
50  posL=posR=0;
51  posLImg = posRImg = 0;
52 
53  bool done=false;
54  bool numericStarted=false;
55  bool numericEnded=false;
56  bool numericImgStarted = false;
57 // bool numericImgEnded = false;
58  int exp10=0;
59  int exp10Img = 0;
60  int current = inStr.size()-1;
61  while (!done && current>=0){
62  const char c=inStr[current];
63  switch (c) {
64  case '0':
65  case '1':
66  case '2':
67  case '3':
68  case '4':
69  case '5':
70  case '6':
71  case '7':
72  case '8':
73  case '9':
74  { // numeric: weight digit with current exp.
75  if(!numericImgStarted && !numericEnded){
76  if (!numericStarted){
77  numericStarted=true;
78  posR=current;
79  }
80  const int act =atoi(&c);
81  const int addAct = int(act*pow(10.0, exp10 ));
82  number += addAct;
83  // next expopnent
84  exp10++;
85  }
86  if(numericStarted && numericEnded){
87  if(!numericImgStarted){
88  numericImgStarted = true;
89  posRImg = current;
90  }
91  const int act = atoi(&c);
92  const int addAct = int(act*pow(10.0, exp10Img));
93  exp10Img++;
94  imgNum += addAct;
95  }
96 
97  break;
98  }
99  default:
100  { // not numeric
101  if (numericStarted && !numericImgStarted){
102  numericEnded=true;
103  posL=current+1;
104  done=false;
105  }
106  if(numericImgStarted){
107  // numericImgEnded=true;
108  posLImg = current+1;
109  done=true;
110  }
111  }
112  }; // switch
113  current--;
114  }// while
115 
116  // found at least one digit?
117  if (!numericStarted) {
118  //BIASWARN("could not extract digit from "<<inStr);
119  return -1;
120  }
121 
122  return 0;
123 }
124 
125 
126 
127 int main(int argc, char *argv[]) {
128 
130 
131  // set parameters
132  deinterlace.SetUseEvenLines(true);
133  deinterlace.SetDeInterlaceType(BIAS_DI_121);
134  deinterlace.SetDownSamplingByTwo(true);
135 
136  ImageBase ucim;
139 
140  if (argc<4) {
141  cerr << argv[0] << "useEvenLines(bool) dodownsamplingbytwo(bool) src1 src2 ... \n";
142  return -2;
143  }
144 
145  // loop through all images
146  for (int countImgs = 0; countImgs < (argc-3); countImgs++) {
147  if (ImageIO::Load(argv[countImgs + 3], ucim)!=0) {
148  BIASERR("error loading image "<<argv[countImgs + 3]);
149  return -1;
150  } else {
151  cerr << "read "<<argv[countImgs + 3]<<endl;
152  }
153 
155  BIASERR("error converting image "<<argv[countImgs + 3]);
156  }
157 
158  // cerr << "Size of inputImage " << ucim.GetWidth() << " " << ucim.GetHeight() << endl;
159  // cerr << "Size of FloatImage " << im.GetWidth() << " " << im.GetHeight() << endl;
160 
161  // if (im.GetChannelCount() != 1) {
162  // if (ImageConvert::IP_ToGrey(im)!=0) {
163  // BIASERR("error converting image "<<argv[countImgs + 3]);
164  // }
165  // }
166 
167  deinterlace.SetUseEvenLines( 0!=atoi(argv[2]) );
168  deinterlace.SetDeInterlaceType(BIAS_DI_121);
169  deinterlace.FilterColorImg(im, dst);
170  cout << "Done with deinterlacer" << endl;
171 
172 
173  int num, imgNum, posL, posR, posLImg, posRImg;
174  ExtractNumbersFromRight(argv[countImgs + 3], num, imgNum, posL, posR, posLImg, posRImg);
175 
176  cout << "extracted num " << num << " imgNum " << imgNum << " posL " << posL << " posR " << posR << " posLImg " << posLImg << " posRImg " << posRImg << endl;
177 
178  ostringstream name;
179  name << "deint-" << setw(4) << setfill('0') << num << ".png";
180 
181  ImageIO::Save(name.str(), dst);
182  }
183 
184  return 0;
185 }
Deinterlacer filter for images.
Definition: DeInterlace.hh:57
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
void SetUseEvenLines(bool bEvenLines=true)
Set if the even or odd lines in the images should be used.
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 SetDownSamplingByTwo(bool bDoDownSamplingByTwo=true)
Set the downsampling factor while filter.
void SetDeInterlaceType(BIAS_DEINTERLACE_TYPE type)
Set the Type of deinterlacing e.g.
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
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
virtual int FilterColorImg(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
applies deinterlacing to each channel sperately