Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleGauss.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2004
5  Johan Skoglund
6  skoglund@isy.liu.se
7  CVL/isy
8  university of Linkoeping
9  sweden
10 
11 BIAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU Lesser General Public License as published by
13 the Free Software Foundation; either version 2.1 of the License, or
14 (at your option) any later version.
15 
16 BIAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU Lesser General Public License for more details.
20 
21 You should have received a copy of the GNU Lesser General Public License
22 along with BIAS; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25 /**
26  @example ExampleGauss.cpp
27  @brief Example for gauss filtering images
28  @relates Gauss
29  @ingroup g_examples
30  @author MIP
31 */
32 
33 #include <iostream>
34 #include "Filter/Gauss.hh"
35 #include "Base/Image/ImageIO.hh"
36 #include <Base/Debug/TimeMeasure.hh>
37 #include <Base/Common/BIASpragma.hh>
38 
39 using namespace BIAS;
40 using namespace std;
41 
42 #define TYPE2 unsigned char
43 
44 
45 int main(int argc, char *argv[])
46 {
47  TimeMeasure timeri, timerf, timer7;
48 
50  if (ImageIO::Load(argv[1], src)!=0){
51  cout <<"Error loading "<<argv[1]<<endl;
52  exit(-1);
53  }
54 
55  Image<TYPE2> dst, dst1, dst2, fdiff;
56 
57  // input image is unsigned char, output is float !
59 
60  // set parameters
61  theGauss.SetSigma(0.7);
62  theGauss.SetRatio(0.01);
63  //theGauss.SetHalfWinSize(7,true);
64 
65  theGauss.AddDebugLevel(D_CONV_TYPES);
66  theGauss.AddDebugLevel(D_WRITE_IMAGES);
67  theGauss.AddDebugLevel(D_FILTERBASE_CALLSTACK);
68  theGauss.AddDebugLevel(D_CONV_KERNEL);
69 
70 
71  cout<<"now filtering in 7x7"<<endl;
72  theGauss.FilterFloat(src, dst2);
73  //ImageIO::Save("7x7_fitered", dst2);
74  ImageIO::Save("7x7_fitered", dst2);
75  cout<<"now filtering in int"<<endl;
76  theGauss.FilterInt(src, dst1);
77  //ImageIO::Save("int_filtered", dst1);
78  ImageIO::Save("int_filtered", dst1);
79 
80  cout<<"now filtering in float"<<endl;
81  theGauss.FilterFloat(src, dst2);
82  //ImageIO::Save("float_fitered", dst2);
83  ImageIO::Save("float_fitered", dst2);
84 
85 
86  theGauss.Filter(src, dst);
87  //ImageIO::Save( "auto_filtered", dst);
88  ImageIO::Save( "auto_filtered", dst);
89  dst.SetZero();
90 
91  bool WantCompare = true;
92  if (WantCompare) {
93  TYPE2 fmin, fmax;
94  fdiff.AbsDiff(dst1, dst2);
95  fdiff.GetMinMaxPixelValue(fmin, fmax);
96  cerr << "differences between "<<(double)fmin<<" and "<<(double)fmax<<endl;
97  }
98  bool WantTiming = true;
99  if (WantTiming) {
100  theGauss.SetDebugLevel(0);
101  // warming up
102  for (int i=0; i<10; i++){
103  cout<<"now filtering in int"<<endl;
104  theGauss.FilterInt(src, dst1);
105 
106  cout<<"now filtering in float"<<endl;
107  theGauss.FilterFloat(src, dst2);
108  }
109  cout<<"Now comparing performance..."<<endl<<flush;
110  // go
111  for (int i=0; i<100; i++){
112  timeri.Start();
113  theGauss.FilterInt(src, dst1);
114  timeri.Stop();
115 
116  timerf.Start();
117  theGauss.FilterFloat(src, dst2);
118  timerf.Stop();
119 
120  timer7.Start();
121  theGauss.Filter7x7Grey(src, dst2);
122  timer7.Stop();
123 
124  }
125 
126  cerr << "int took "<<endl;
127  timeri.Print();
128 
129  cerr << "float took "<<endl;
130  timerf.Print();
131 
132  cerr << "7x7 took "<<endl;
133  timer7.Print();
134 
135  }
136  return 0;
137 }
virtual int Filter7x7Grey(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
fast, approximate, direct implementation, ignoring wrap-arounds, roi is updated but ignored ...
Definition: Gauss.cpp:516
void Print(std::ostream &os=std::cout) const
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
void AbsDiff(const Image< StorageType > &im1, const Image< StorageType > &im2)
(*this) = | im1 - im2 | sets this as the absolute difference between two arg images ...
void GetMinMaxPixelValue(StorageType &min, StorageType &max, unsigned short int channel=0, unsigned int *mincoo=NULL, unsigned int *maxcoo=NULL) const
returns the minimal and maximal pixel value in channel only Finds minimum and maximum pixel value in ...
Definition: Image.cpp:802
smoothing with gaussian kernel
Definition: Gauss.hh:51
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
sets gauss kernel if params changed and calls convolution
Definition: Gauss.cpp:115
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
void SetSigma(const double si)
Definition: Gauss.hh:162
static int Save(const std::string &filename, const ImageBase &img, const enum TFileFormat FileFormat=FF_auto, const bool sync=BIAS_DEFAULT_SYNC, const int c_jpeg_quality=BIAS_DEFAULT_IMAGE_QUALITY, const bool forceNewID=BIAS_DEFAULT_FORCENEWID, const bool &writeMetaData=true)
Export image as file using extrnal libs.
Definition: ImageIO.cpp:725
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
sets gauss kernel if params changed and calls convolution or fast grey implementation if possible ...
Definition: Gauss.cpp:89
void SetRatio(const double ratio)
Definition: Gauss.hh:166
static int Load(const std::string &FileName, ImageBase &img)
first tries a call to Read MIP image and if that fails, tries to Import Image with all other availabl...
Definition: ImageIO.cpp:141
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
sets gauss kernel if params changed and calls convolution
Definition: Gauss.cpp:105
void SetZero()
zeroes the image
Definition: ImageBase.hh:83