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

Example Bilateral Filter

Author
Ingo Schiller
/*
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 ExampleBilateral.cpp
@relates Bilateral
@brief Example Bilateral Filter
@ingroup g_examples
@author Ingo Schiller
*/
#include "Filter/Bilateral.hh"
#include "Base/Image/ImageIO.hh"
#include <iostream>
#include <Base/Debug/TimeMeasure.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Common/BIASpragma.hh>
using namespace BIAS;
using namespace std;
#define TYPE1 float
#define TYPE2 float
int main(int argc, char *argv[])
{
TimeMeasure timeri, timerf, timer7;
if(argc< 2){
cout<<"Usage:"<<endl;
cout<<argv[0]<<" Image [iterations] [filterSize] [sigmaGauss] [sigmaBilateral] [supportImage]\n";
return -1;
}
Image<TYPE2> dst, fdiff;
ImageBase srcbase, suppbase;
double sigmaG=0.7, sigmaB=150.0;
int size=2;
int iterations = 1;
if (ImageIO::Load(argv[1], srcbase)!=0){
cout <<"Error loading "<<argv[1]<<endl;
exit(-1);
}
if(argc > 2) iterations=atoi(argv[2]);
if(argc > 3) size=atoi(argv[3]);
if(argc > 4) sigmaG=atof(argv[4]);
if(argc > 5) sigmaB=atof(argv[5]);
cout<<"Iterations:"<<iterations<<endl;
cout<<"Filter half win size:"<<size<<"x"<<size<<endl;
cout<<"Sigma Gauss:"<<sigmaG<<endl;
cout<<"Sigma Bilateral:"<<sigmaB<<endl;
//load support image
if(argc > 6) {
if (ImageIO::Load(argv[6], suppbase)!=0){
cout <<"Error loading "<<argv[6]<<endl;
exit(-1);
}
}
if (srcbase.GetStorageType() == ImageBase::ST_float) {
srcf = srcbase;
// input image is float, output is float !
// set parameters
theBilateral.SetSigma(sigmaG);
theBilateral.SetBilateralSigma(sigmaB);
theBilateral.SetSize(size,size);
theBilateral.SetIgnoreValue(0.0);
cout<<"now filtering FL"<<flush;
if(!suppbase.IsEmpty()){
Image<float> suppf;
}
else
suppf = suppbase;
if(srcf.GetChannelCount() != suppf.GetChannelCount()){
}
cout<<" with support!";
for(int i=0;i<iterations;i++){
theBilateral.Filter(srcf, suppf,dst);
srcf = dst;
}
}
else{
for(int i=0;i<iterations;i++){
theBilateral.Filter(srcf, dst);
srcf = dst;
}
}
cout<<endl;
ImageIO::Save("bilateral_fitered", dst);
} else if(srcbase.GetStorageType() == ImageBase::ST_unsignedchar) {
srcUC = srcbase;
// input image is UC, output is UC
// set parameters
theBilateral.SetSize(size,size);
theBilateral.SetSigma(sigmaG);
theBilateral.SetBilateralSigma(sigmaB);
theBilateral.SetIgnoreValue(0.0);
cout<<"now filtering UC"<<flush;
if(!suppbase.IsEmpty()){
suppUC = suppbase;
cout<<" with support!";
for(int i=0;i<iterations;i++){
theBilateral.Filter(srcUC, suppUC,dstUC);
}
}
else{
for(int i=0;i<iterations;i++){
theBilateral.Filter(srcUC, dstUC);
srcUC = dstUC;
}
}
cout<<endl;
ImageIO::Save("bilateral_fitered", dstUC);
}
return 0;
}