Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleBilateral.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 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 /**
24  @example ExampleBilateral.cpp
25  @relates Bilateral
26  @brief Example Bilateral Filter
27  @ingroup g_examples
28  @author Ingo Schiller
29 */
30 #include "Filter/Bilateral.hh"
31 #include "Base/Image/ImageIO.hh"
32 #include <iostream>
33 
34 #include <Base/Debug/TimeMeasure.hh>
35 #include <Base/Image/ImageConvert.hh>
36 
37 #include <Base/Common/BIASpragma.hh>
38 
39 using namespace BIAS;
40 using namespace std;
41 
42 #define TYPE1 float
43 #define TYPE2 float
44 
45 
46 int main(int argc, char *argv[])
47 {
48  TimeMeasure timeri, timerf, timer7;
49  if(argc< 2){
50  cout<<"Usage:"<<endl;
51  cout<<argv[0]<<" Image [iterations] [filterSize] [sigmaGauss] [sigmaBilateral] [supportImage]\n";
52  return -1;
53  }
54 
55  Image<TYPE2> dst, fdiff;
56  ImageBase srcbase, suppbase;
57  double sigmaG=0.7, sigmaB=150.0;
58  int size=2;
59  int iterations = 1;
60  if (ImageIO::Load(argv[1], srcbase)!=0){
61  cout <<"Error loading "<<argv[1]<<endl;
62  exit(-1);
63  }
64 
65  if(argc > 2) iterations=atoi(argv[2]);
66  if(argc > 3) size=atoi(argv[3]);
67  if(argc > 4) sigmaG=atof(argv[4]);
68  if(argc > 5) sigmaB=atof(argv[5]);
69 
70  cout<<"Iterations:"<<iterations<<endl;
71  cout<<"Filter half win size:"<<size<<"x"<<size<<endl;
72  cout<<"Sigma Gauss:"<<sigmaG<<endl;
73  cout<<"Sigma Bilateral:"<<sigmaB<<endl;
74 
75  //load support image
76  if(argc > 6) {
77  if (ImageIO::Load(argv[6], suppbase)!=0){
78  cout <<"Error loading "<<argv[6]<<endl;
79  exit(-1);
80  }
81  }
82 
83 
84  if (srcbase.GetStorageType() == ImageBase::ST_float) {
85 
86  Image<float> srcf;
87  srcf = srcbase;
88  // input image is float, output is float !
89  Bilateral<float, TYPE2> theBilateral;
90 
91  // set parameters
92  theBilateral.SetSigma(sigmaG);
93  theBilateral.SetBilateralSigma(sigmaB);
94  theBilateral.SetSize(size,size);
95  theBilateral.SetIgnoreValue(0.0);
96 
97  cout<<"now filtering FL"<<flush;
98  if(!suppbase.IsEmpty()){
99  Image<float> suppf;
100  if(suppbase.GetStorageType() != ImageBase::ST_float){
102  }
103  else
104  suppf = suppbase;
105 
106  if(srcf.GetChannelCount() != suppf.GetChannelCount()){
108  }
109 
110  cout<<" with support!";
111  for(int i=0;i<iterations;i++){
112  theBilateral.Filter(srcf, suppf,dst);
113  srcf = dst;
114  }
115  }
116  else{
117  for(int i=0;i<iterations;i++){
118  theBilateral.Filter(srcf, dst);
119  srcf = dst;
120  }
121  }
122  cout<<endl;
123  ImageIO::Save("bilateral_fitered", dst);
124 
125  } else if(srcbase.GetStorageType() == ImageBase::ST_unsignedchar) {
126  Image<unsigned char> srcUC;
127  srcUC = srcbase;
128  // input image is UC, output is UC
130  Image<unsigned char> dstUC;
131  // set parameters
132  theBilateral.SetSize(size,size);
133  theBilateral.SetSigma(sigmaG);
134  theBilateral.SetBilateralSigma(sigmaB);
135  theBilateral.SetIgnoreValue(0.0);
136  cout<<"now filtering UC"<<flush;
137  if(!suppbase.IsEmpty()){
138  Image<unsigned char> suppUC;
139  suppUC = suppbase;
140  cout<<" with support!";
141  for(int i=0;i<iterations;i++){
142  theBilateral.Filter(srcUC, suppUC,dstUC);
143  }
144  }
145  else{
146  for(int i=0;i<iterations;i++){
147  theBilateral.Filter(srcUC, dstUC);
148  srcUC = dstUC;
149  }
150  }
151 
152  cout<<endl;
153  ImageIO::Save("bilateral_fitered", dstUC);
154  }
155 
156 
157 
158 
159  return 0;
160 }
void SetSize(int newsize, int secondsize=-1)
Definition: Bilateral.cpp:72
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
float image storage type
Definition: ImageBase.hh:118
void SetSigma(const double si)
Definition: Bilateral.hh:83
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
Bilateral filtering with given filter size (5x5 as standard)
Definition: Bilateral.cpp:115
static int ConvertST(const BIAS::ImageBase &source, BIAS::ImageBase &dest, ImageBase::EStorageType targetST)
Function to convert the storage type of images e.g.
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
Definition: ImageBase.hh:382
2D bilateral filter
Definition: Bilateral.hh:35
The image template class for specific storage types.
Definition: Image.hh:78
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
void SetIgnoreValue(InputStorageType ignore)
Definition: Bilateral.hh:87
void SetBilateralSigma(const double si)
Definition: Bilateral.hh:85
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
enum EStorageType GetStorageType() const
Definition: ImageBase.hh:414
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
static int IP_ToGrey(Image< StorageType > &img)
In place conversion to gray image.