Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleBinomial.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 /**
27  @example ExampleBinomial.cpp
28  @relates Binomial
29  @brief Example Binomial Filter
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include "Filter/Binomial.hh"
35 #include "Base/Image/ImageIO.hh"
36 #include <iostream>
37 
38 #include <Base/Debug/TimeMeasure.hh>
39 
40 using namespace BIAS;
41 using namespace std;
42 
43 #define TYPE2 unsigned char
44 
45 int main(int argc, char *argv[])
46 {
47  TimeMeasure timeri, timerf;
48 
49  if (argc<2) {
50  cout << "usage: "<<argv[0]<<" <image>\n";
51  //return -1;
52  return 0; // for dart test
53  }
54 
56  if (ImageIO::Load(argv[1], src)!=0){
57  cout <<"Error loading "<<argv[1]<<endl;
58  exit(-1);
59  }
60 
61  Image<TYPE2> dst, dst1, dst2, fdiff;
62 
63  // input image is unsigned char, output is float !
65 
66  // set params
67  theBinomial.SetHalfWinSize(1);
68 
69  theBinomial.AddDebugLevel(D_CONV_TYPES);
70  theBinomial.AddDebugLevel(D_WRITE_IMAGES);
71  theBinomial.AddDebugLevel(D_FILTERBASE_CALLSTACK);
72  theBinomial.AddDebugLevel(D_CONV_KERNEL);
73  theBinomial.AddDebugLevel(D_BINOMIAL_KERNEL);
74 
75  theBinomial.Filter(src, dst);
76  //ImageIO::Save( "auto_filtered", dst);
77  ImageIO::Save( "auto_filtered", dst);
78  dst.SetZero();
79  cout<<"now filtering in int"<<endl;
80  theBinomial.FilterInt(src, dst1);
81  //ImageIO::Save("int_filtered", dst1);
82  ImageIO::Save("int_filtered", dst1);
83 
84  cout<<"now filtering in float"<<endl;
85  theBinomial.FilterFloat(src, dst2);
86  //ImageIO::Save("float_fitered", dst2);
87  ImageIO::Save("float_fitered", dst2);
88 
89  bool WantCompare = true;
90  if (WantCompare) {
91  TYPE2 fmin, fmax;
92  fdiff.AbsDiff(dst1, dst2);
93  fdiff.GetMinMaxPixelValue(fmin, fmax);
94  cerr << "differences between "<<(double)fmin<<" and "<<(double)fmax<<endl;
95  }
96  bool WantTiming = true;
97  if (WantTiming) {
98  theBinomial.SetDebugLevel(0);
99  // warming up
100  for (int i=0; i<1; i++){
101  cout<<"now filtering in int"<<endl;
102  theBinomial.FilterInt(src, dst1);
103 
104  cout<<"now filtering in float"<<endl;
105  theBinomial.FilterFloat(src, dst2);
106  }
107  cout<<"Now comparing performance..."<<endl<<flush;
108  // go
109  for (int i=0; i<1; i++){
110  timeri.Start();
111  theBinomial.FilterInt(src, dst1);
112  timeri.Stop();
113 
114  timerf.Start();
115  theBinomial.FilterFloat(src, dst2);
116  timerf.Stop();
117  }
118 
119  cerr << "int took "<<endl;
120  timeri.Print();
121 
122  cerr << "float took "<<endl;
123  timerf.Print();
124  }
125  return 0;
126 }
void Print(std::ostream &os=std::cout) const
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
virtual int FilterFloat(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
no implementation, calls Filter
Definition: Binomial.cpp:101
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
virtual int FilterInt(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
no implementation, calls Filter
Definition: Binomial.cpp:94
void SetDebugLevel(const long int lv)
Definition: Debug.hh:318
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 kernel if params changed and calls convolution
Definition: Binomial.cpp:69
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
binomial low pass filter class
Definition: Binomial.hh:42
void SetHalfWinSize(int hws)
Definition: Binomial.hh:103
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
void SetZero()
zeroes the image
Definition: ImageBase.hh:83