Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleRemoveSaltAndPepper.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 ExampleRemoveSaltAndPepper.cpp
28  @brief Example for median filtering images with 3x3
29  @relates Median
30  @ingroup g_examples
31  @author MIP
32 */
33 
34 #include "Filter/Median.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 
44 
45 int main(int argc, char *argv[])
46 {
47  TimeMeasure timeri, timerf;
48 
49  Image<float> src;
50  if (!(argc>1)){
51  BIASERR("no arg"); return -1;
52  };
53  BIASASSERT(argc>1);
54  if (ImageIO::Load(argv[1], src)!=0){
55  cout <<"Error loading "<<argv[1]<<endl;
56  exit(-1);
57  }
58 
59  Image<float> dest;
60 
61  Median<float, float> theMedian;
62  timeri.Start();
63  theMedian.FilterRemoveSaltAndPepper(src, dest);
64  timeri.Stop();
65  timeri.PrintRealTime();
66  ImageIO::Save( "saltandpepper_filtered", dest);
67  Image<float> orig,filtered,diff;
68  orig.GetChannel(src,0);
69  filtered.GetChannel(dest,0);
70  diff = orig-filtered;
71  ImageIO::Save( "saltandpepper_diff", diff);
72 
73  return 0;
74 }
int FilterRemoveSaltAndPepper(const Image< InputStorageType > &src, Image< OutputStorageType > &dst, const float &Threshold=3.0f) const
removes &quot;salt and pepper&quot; by replacing outliers (Threshold) with median of neighbourhood.
Definition: Median.cpp:831
int GetChannel(const ImageBase &source, const unsigned int channel)
copies one specific channel from source to Image can only be called from an planar image...
Definition: ImageBase.cpp:428
Implements a 2D median filter for images.
Definition: Median.hh:39
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 PrintRealTime(std::ostream &os=std::cout, const bool &verbose=true) const
print the real time (=wall time clok)
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