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

Example Binomial Filter

Author
MIP
/*
This file is part of the BIAS library (Basic ImageAlgorithmS).
Copyright (C) 2004
Johan Skoglund
skoglund@isy.liu.se
CVL/isy
university of Linkoeping
sweden
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 ExampleBinomial.cpp
@relates Binomial
@brief Example Binomial Filter
@ingroup g_examples
@author MIP
*/
#include "Filter/Binomial.hh"
#include "Base/Image/ImageIO.hh"
#include <iostream>
#include <Base/Debug/TimeMeasure.hh>
using namespace BIAS;
using namespace std;
#define TYPE2 unsigned char
int main(int argc, char *argv[])
{
TimeMeasure timeri, timerf;
if (argc<2) {
cout << "usage: "<<argv[0]<<" <image>\n";
//return -1;
return 0; // for dart test
}
if (ImageIO::Load(argv[1], src)!=0){
cout <<"Error loading "<<argv[1]<<endl;
exit(-1);
}
Image<TYPE2> dst, dst1, dst2, fdiff;
// input image is unsigned char, output is float !
// set params
theBinomial.SetHalfWinSize(1);
theBinomial.AddDebugLevel(D_CONV_TYPES);
theBinomial.AddDebugLevel(D_WRITE_IMAGES);
theBinomial.AddDebugLevel(D_FILTERBASE_CALLSTACK);
theBinomial.AddDebugLevel(D_CONV_KERNEL);
theBinomial.AddDebugLevel(D_BINOMIAL_KERNEL);
theBinomial.Filter(src, dst);
//ImageIO::Save( "auto_filtered", dst);
ImageIO::Save( "auto_filtered", dst);
dst.SetZero();
cout<<"now filtering in int"<<endl;
theBinomial.FilterInt(src, dst1);
//ImageIO::Save("int_filtered", dst1);
ImageIO::Save("int_filtered", dst1);
cout<<"now filtering in float"<<endl;
theBinomial.FilterFloat(src, dst2);
//ImageIO::Save("float_fitered", dst2);
ImageIO::Save("float_fitered", dst2);
bool WantCompare = true;
if (WantCompare) {
TYPE2 fmin, fmax;
fdiff.AbsDiff(dst1, dst2);
fdiff.GetMinMaxPixelValue(fmin, fmax);
cerr << "differences between "<<(double)fmin<<" and "<<(double)fmax<<endl;
}
bool WantTiming = true;
if (WantTiming) {
theBinomial.SetDebugLevel(0);
// warming up
for (int i=0; i<1; i++){
cout<<"now filtering in int"<<endl;
theBinomial.FilterInt(src, dst1);
cout<<"now filtering in float"<<endl;
theBinomial.FilterFloat(src, dst2);
}
cout<<"Now comparing performance..."<<endl<<flush;
// go
for (int i=0; i<1; i++){
timeri.Start();
theBinomial.FilterInt(src, dst1);
timeri.Stop();
timerf.Start();
theBinomial.FilterFloat(src, dst2);
timerf.Stop();
}
cerr << "int took "<<endl;
timeri.Print();
cerr << "float took "<<endl;
timerf.Print();
}
return 0;
}