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

Example for gradient filtering images

Author
MIP
/*
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 ExampleGradient.cpp
@brief Example for gradient filtering images
@relates Gradient
@ingroup g_examples
@author MIP
*/
#include <Filter/FilterNTo2N.hh>
#include <Filter/GradientSobel3x3.hh>
#include <Filter/GradientGauss.hh>
#include <Filter/GradientGaussAsymmetric.hh>
#include <Base/Image/ImageIO.hh>
#include <Base/Image/ImageConvert.hh>
#include <Base/Debug/TimeMeasure.hh>
#include <Base/Common/BIASpragma.hh>
using namespace BIAS;
using namespace std;
#define InputImageType unsigned char
#define OutputImageType float
int main(int argc, char *argv[])
{
TimeMeasure Timer1;
// set parameters
ggauss.SetGradGaussSigma(1.0);
ggauss.SetGradGaussRatio(0.01);
// if (argc-argind<1 || argind<1){
// cerr << argv[0] << " [parameter] <im1> <im2> [ <im3> ... ] \n";
// para.Usage(cerr);
// return -2;
// }
int gt = 1;
switch (gt){
case 0:
grad = &gsobel3x3;
cerr <<"Sobel3x3\n";
break;
case 1:
grad = &ggauss;
cerr <<"GradientGauss\n";
break;
case 2:
grad = &ggaussasymmetric;
cerr <<"GradientGaussAsymmetric\n";
break;
default:
BIASERR("unknown gradient type");
BIASABORT;
break;
}
grad->AddDebugLevel(D_GRADGAUSS_KERNEL);
grad->AddDebugLevel(D_CONV_KERNEL);
grad->AddDebugLevel(D_GRAD_DEB);
grad->SetBorderHandling(FilterBase<InputImageType,
OutputImageType>::TBH_valid);
int argind = 1;
for (int i=argind; i<argc; i++){
if (ImageIO::Load(argv[i], im)!=0){
BIASERR("error loading image "<<argv[i]);
return -1;
} else {
cerr << "read "<<argv[i]<<endl;
}
#if type != 1
// if (ImageConvert::ConvertST(ucim, im, ImageBase::ST_float)!=0){
// BIASERR("error converting image "<<argv[i]);
//}
#endif
Timer1.Start();
gsobel3x3.Filter(im, gx, gy, g);
Timer1.Stop();
ostringstream name;
name << "gradx-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
//ImageIO::Save(name.str(), gx);
ImageIO::Save(name.str(), gx);
name.str("");
name << "grady-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
//ImageIO::Save(name.str(), gy);
ImageIO::Save(name.str(), gy);
name.str("");
name << "grad-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
//ImageIO::Save(name.str(), g);
ImageIO::Save(name.str(), g);
}
Timer1.Print();
return 0;
}