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

Example for using Convolution Filter

Author
fkellner, 11/2008
/*
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 ExampleConvolution.cpp
@relates Convolution
@brief Example for using Convolution Filter
@ingroup g_examples
@author fkellner, 11/2008
*/
// must be first:
//#include <Base/Common/LeakChecking.h>
#include <iostream>
#include "Filter/Convolution.hh"
#include <Base/Common/BIASpragma.hh>
using namespace BIAS;
using namespace std;
int main(int argc, char *argv[])
{
src.Init(10,10);
dst.Init(10,10);
unsigned char *srcdata=src.GetImageData();
unsigned char *dstdata=dst.GetImageData();
for(int x=0;x<100;x++)
{
srcdata[x]=0;
dstdata[x]=0;
}
srcdata[10*5+5]=100;
srcdata[0]=100;
kern.newsize(3,3);
kern[0][0]=1;
kern[0][1]=2;
kern[0][2]=1;
kern[1][0]=2;
kern[1][1]=4;
kern[1][2]=2;
kern[2][0]=1;
kern[2][1]=2;
kern[2][2]=1;
khor.newsize(3);
kver.newsize(3);
khor[0]=1;
khor[1]=2;
khor[2]=1;
kver[0]=1;
kver[1]=2;
kver[2]=1;
fm.Init(kern,1);
conv.SetKernel(fm);
conv.FilterInt(src,dst);
cout <<"dst matrix:\n";
for(int y=0;y<10;y++)
{
for(int x=0;x<10;x++)
cout <<(int)dstdata[y*10+x]<<" ";
cout <<endl;
}
fm.Init(khor,kver,1,0);
conv.SetKernel(fm);
conv.FilterInt(src,dst);
cout <<"dst sep:\n";
for(int y=0;y<10;y++)
{
for(int x=0;x<10;x++)
cout <<(int)dstdata[y*10+x]<<" ";
cout <<endl;
}
conv.SetKernel(fm);
conv.FilterFloat(src,dst);
cout <<"dst matrix float:\n";
for(int y=0;y<10;y++)
{
for(int x=0;x<10;x++)
cout <<(int)dstdata[y*10+x]<<" ";
cout <<endl;
}
conv.SetKernel(fm);
conv.FilterFloat(src,dst);
cout <<"dst sep float:\n";
for(int y=0;y<10;y++)
{
for(int x=0;x<10;x++)
cout <<(int)dstdata[y*10+x]<<" ";
cout <<endl;
}
return 0;
}