Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleGradient.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 /**
27  @example ExampleGradient.cpp
28  @brief Example for gradient filtering images
29  @relates Gradient
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 
35 #include <Filter/FilterNTo2N.hh>
36 #include <Filter/GradientSobel3x3.hh>
37 #include <Filter/GradientGauss.hh>
38 #include <Filter/GradientGaussAsymmetric.hh>
39 #include <Base/Image/ImageIO.hh>
40 #include <Base/Image/ImageConvert.hh>
41 #include <Base/Debug/TimeMeasure.hh>
42 
43 #include <Base/Common/BIASpragma.hh>
44 
45 using namespace BIAS;
46 using namespace std;
47 
48 #define InputImageType unsigned char
49 #define OutputImageType float
50 
51 int main(int argc, char *argv[])
52 {
53  TimeMeasure Timer1;
54 
59 
60  // set parameters
61  ggauss.SetGradGaussSigma(1.0);
62  ggauss.SetGradGaussRatio(0.01);
63 
66  Image<OutputImageType> gx, gy, g;
67 
68  // if (argc-argind<1 || argind<1){
69 // cerr << argv[0] << " [parameter] <im1> <im2> [ <im3> ... ] \n";
70 // para.Usage(cerr);
71 // return -2;
72 // }
73 
74 
75  int gt = 1;
76  switch (gt){
77  case 0:
78  grad = &gsobel3x3;
79  cerr <<"Sobel3x3\n";
80  break;
81  case 1:
82  grad = &ggauss;
83  cerr <<"GradientGauss\n";
84  break;
85  case 2:
86  grad = &ggaussasymmetric;
87  cerr <<"GradientGaussAsymmetric\n";
88  break;
89  default:
90  BIASERR("unknown gradient type");
91  BIASABORT;
92  break;
93  }
94  grad->AddDebugLevel(D_GRADGAUSS_KERNEL);
95  grad->AddDebugLevel(D_CONV_KERNEL);
96  grad->AddDebugLevel(D_GRAD_DEB);
97 
98  grad->SetBorderHandling(FilterBase<InputImageType,
99  OutputImageType>::TBH_valid);
100  int argind = 1;
101  for (int i=argind; i<argc; i++){
102  if (ImageIO::Load(argv[i], im)!=0){
103  BIASERR("error loading image "<<argv[i]);
104  return -1;
105  } else {
106  cerr << "read "<<argv[i]<<endl;
107  }
108 
109 #if type != 1
110  // if (ImageConvert::ConvertST(ucim, im, ImageBase::ST_float)!=0){
111  // BIASERR("error converting image "<<argv[i]);
112  //}
113 #endif
114 
115  Timer1.Start();
116  gsobel3x3.Filter(im, gx, gy, g);
117  Timer1.Stop();
118 
119  ostringstream name;
120  name << "gradx-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
121  //ImageIO::Save(name.str(), gx);
122  ImageIO::Save(name.str(), gx);
123  name.str("");
124  name << "grady-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
125  //ImageIO::Save(name.str(), gy);
126  ImageIO::Save(name.str(), gy);
127  name.str("");
128  name << "grad-"<<setw(4)<<setfill('0')<<i-argind<<".mip";
129  //ImageIO::Save(name.str(), g);
130  ImageIO::Save(name.str(), g);
131  }
132 
133  Timer1.Print();
134 
135  return 0;
136 }
void Print(std::ostream &os=std::cout) const
gradient calculation with separated gauss masks
void AddDebugLevel(const long int lv)
Definition: Debug.hh:355
void SetGradGaussRatio(const double ratio)
void SetGradGaussSigma(const double sigma)
base class for simple n-&gt;2n filter implementations
Definition: FilterNTo2N.hh:44
virtual parent class for API definition of all (future) filters
Definition: FilterBase.hh:77
gradient calculation with sobel 3 by 3 masks
void SetBorderHandling(const int bh)
Definition: FilterBase.hh:127
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
gradient calculation with separated gauss masks
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
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &grad)
returns a 2 channel image containing gx and gy
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111