Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleDeInterlace2.cpp

Example for deinterlacing interlaced images

Author
ischiller
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2003-2009 (see file CONTACT for details)
Multimediale Systeme der Informationsverarbeitung
Institut fuer Informatik
Christian-Albrechts-Universitaet Kiel
BIAS is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
BIAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with BIAS; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
@example ExampleDeInterlace2.cpp
@relates DeInterlace
@brief Example for deinterlacing interlaced images
@ingroup g_examples
@author ischiller
*/
#include <Filter/DeInterlace.hh>
#include <Filter/Median.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Utils/Param.hh>
using namespace BIAS;
using namespace std;
int ExtractNumbersFromRight(const std::string & inStr,
int & number, int& imgNum,
int & posL,
int & posR, int& posLImg, int& posRImg)
{
// parse from rigth numeric part of string:
number=0;
imgNum = 0;
posL=posR=0;
posLImg = posRImg = 0;
bool done=false;
bool numericStarted=false;
bool numericEnded=false;
bool numericImgStarted = false;
// bool numericImgEnded = false;
int exp10=0;
int exp10Img = 0;
int current = inStr.size()-1;
while (!done && current>=0){
const char c=inStr[current];
switch (c) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
{ // numeric: weight digit with current exp.
if(!numericImgStarted && !numericEnded){
if (!numericStarted){
numericStarted=true;
posR=current;
}
const int act =atoi(&c);
const int addAct = int(act*pow(10.0, exp10 ));
number += addAct;
// next expopnent
exp10++;
}
if(numericStarted && numericEnded){
if(!numericImgStarted){
numericImgStarted = true;
posRImg = current;
}
const int act = atoi(&c);
const int addAct = int(act*pow(10.0, exp10Img));
exp10Img++;
imgNum += addAct;
}
break;
}
default:
{ // not numeric
if (numericStarted && !numericImgStarted){
numericEnded=true;
posL=current+1;
done=false;
}
if(numericImgStarted){
// numericImgEnded=true;
posLImg = current+1;
done=true;
}
}
}; // switch
current--;
}// while
// found at least one digit?
if (!numericStarted) {
//BIASWARN("could not extract digit from "<<inStr);
return -1;
}
return 0;
}
int main(int argc, char *argv[]) {
// set parameters
deinterlace.SetUseEvenLines(true);
deinterlace.SetDownSamplingByTwo(true);
ImageBase ucim;
if (argc<4) {
cerr << argv[0] << "useEvenLines(bool) dodownsamplingbytwo(bool) src1 src2 ... \n";
return -2;
}
// loop through all images
for (int countImgs = 0; countImgs < (argc-3); countImgs++) {
if (ImageIO::Load(argv[countImgs + 3], ucim)!=0) {
BIASERR("error loading image "<<argv[countImgs + 3]);
return -1;
} else {
cerr << "read "<<argv[countImgs + 3]<<endl;
}
BIASERR("error converting image "<<argv[countImgs + 3]);
}
// cerr << "Size of inputImage " << ucim.GetWidth() << " " << ucim.GetHeight() << endl;
// cerr << "Size of FloatImage " << im.GetWidth() << " " << im.GetHeight() << endl;
// if (im.GetChannelCount() != 1) {
// if (ImageConvert::IP_ToGrey(im)!=0) {
// BIASERR("error converting image "<<argv[countImgs + 3]);
// }
// }
deinterlace.SetUseEvenLines( 0!=atoi(argv[2]) );
deinterlace.FilterColorImg(im, dst);
cout << "Done with deinterlacer" << endl;
int num, imgNum, posL, posR, posLImg, posRImg;
ExtractNumbersFromRight(argv[countImgs + 3], num, imgNum, posL, posR, posLImg, posRImg);
cout << "extracted num " << num << " imgNum " << imgNum << " posL " << posL << " posR " << posR << " posLImg " << posLImg << " posRImg " << posRImg << endl;
ostringstream name;
name << "deint-" << setw(4) << setfill('0') << num << ".png";
ImageIO::Save(name.str(), dst);
}
return 0;
}