Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Median.hh
1 /* This file is part of the BIAS library (Basic ImageAlgorithmS).
2 
3  Copyright (C) 2003, 2004 (see file CONTACTS for details)
4  Multimediale Systeme der Informationsverarbeitung
5  Institut fuer Informatik
6  Christian-Albrechts-Universitaet Kiel
7 
8  BIAS is free software; you can redistribute it and/or modify
9  it under the terms of the GNU Lesser General Public License as published by
10  the Free Software Foundation; either version 2.1 of the License, or
11  (at your option) any later version.
12 
13  BIAS is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License
19  along with BIAS; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
21 #ifndef __Median_hh__
22 #define __Median_hh__
23 
24 #include <Base/Image/Image.hh>
25 #include <Filter/FilterNToN.hh>
26 #include <utility>
27 #ifdef _OPENMP
28 #include <omp.h>
29 #endif
30 
31 namespace BIAS
32 {
33 
34  /** @class Median
35  @ingroup g_filter
36  @brief Implements a 2D median filter for images.
37  */
38  template<class InputStorageType, class OutputStorageType>
39  class BIASFilter_EXPORT Median
40  : public FilterNToN<InputStorageType, OutputStorageType>
41  {
42  public:
43 
44  Median();
45 
47 
48  virtual
49  ~Median();
50 
51  virtual int
52  Filter(const Image<InputStorageType>& src, Image<OutputStorageType>& dst);
53 
54  virtual int
55  FilterInt(const Image<InputStorageType>& src,
57 
58  virtual int
59  FilterFloat(const Image<InputStorageType>& src,
61 
63  Clone() const
64  {
66  }
67 
68  /** @brief */
69  int
70  FilterIgnoreZero5x5(const Image<InputStorageType>& src, Image<
71  OutputStorageType>& dst) const;
72 
73  /** @brief fill spurious gaps in depth maps
74  compute 5x5 median at zero points, thereby ignoring zero values
75  @param Threshold all values<=threshold are rewritten,
76  all values>threshold are used for median sorting */
77  int
78  FilterOnlyZeroIgnoreZero5x5(const Image<InputStorageType>& src, Image<
79  OutputStorageType>& dst, const float& Threshold = 0.0f) const;
80 
81  /** @brief fill spurious gaps in depth maps
82  compute 3x3 median at zero points, thereby ignoring zero values
83  @param Threshold all values<=threshold are rewritten, all
84  values>threshold are used for median sorting */
85  int
86  FilterOnlyZeroIgnoreZero3x3(const Image<InputStorageType>& src, Image<
87  OutputStorageType>& dst, const float& Threshold = 0.0f) const;
88 
89  /** @brief filters using only values above threshold as input */
90  int
91  FilterIgnore3x3(const Image<InputStorageType>& src, Image<
92  OutputStorageType>& dst, const float& threshold) const;
93 
94  /** @brief Specialized median filter for images with invalid values.
95 
96  Only positions containing an invalid value (i.e. a value < threshold)
97  are touched by the filter. They are set to the median of all
98  neighboring pixels, which are not invalid themselves, iff a minimium
99  number of min_support_pixels are found. Otherwise the invalid value
100  is preserved.
101  @author woelk 06/2008 (c) www.vision-n.de */
102  int
103  FilterOnlyBelowIgnoreBelow3x3(const Image<InputStorageType>& src, Image<
104  OutputStorageType>& dst, const float &threshold,
105  const unsigned &min_support = 1) const;
106 
107  /** @brief removes "salt and pepper" by replacing outliers (Threshold)
108  with median of neighbourhood. For two channels: assume second channel
109  is covariance, do not filter but copy corresponding value from median */
110  int
111  FilterRemoveSaltAndPepper(const Image<InputStorageType>& src, Image<
112  OutputStorageType>& dst, const float &Threshold = 3.0f) const;
113 
114  int
115  FilterColorImg(const Image<InputStorageType>& src, Image<
116  OutputStorageType>& dst);
117 
118  int
119  FilterColorImgVec(const Image<InputStorageType>& src, Image<
120  OutputStorageType>& dst, unsigned int px, unsigned int py,
121  const Image<unsigned char>* ignorePixels = NULL);
122 
123  int
124  FilterColorImgVec(const Image<InputStorageType>& src, Image<
125  OutputStorageType>& dst,
126  const Image<unsigned char>* ignorePixels = NULL);
127 
128  int FilterParallel(Image<InputStorageType>& source,
129  Image<OutputStorageType>& dest, unsigned int numberOfThreads);
130 
131  int
132  Filter3x3x3Grey(std::vector<Image<InputStorageType> >& srcs, Image<
133  OutputStorageType>& dst);
134 
135  int
136  Filter3x3x3Color(std::vector<Image<InputStorageType> >& srcs, Image<
137  OutputStorageType>& dst);
138 
139  inline void
140  SetSize(int newsize, int secondsize = -1)
141  {
142  _MedianSize = newsize;
143  if (secondsize != -1)
144  _secondSize = secondsize;
145  else
146  _secondSize = _MedianSize;
147  }
148 
149  // all data below this threshold will be ignored
150  void
151  SetMinValue(float min)
152  {
153  _MinValue = min;
154  }
155 
156  protected:
157 
158  /// half win size of median, 1 means 3x3
160 
161  /// Use this variable for non-quadratic filter sizes e.g. 3x1
163  float _MinValue;
164 
165  virtual void GetBordersValid_(int &border_x, int &border_y) const;
166 
167  };
168 
169 }
170 
171 #endif // __Median_hh__
int _secondSize
Use this variable for non-quadratic filter sizes e.g. 3x1.
Definition: Median.hh:162
void SetMinValue(float min)
Definition: Median.hh:151
virtual FilterNToN< InputStorageType, OutputStorageType > * Clone() const
Definition: Median.hh:63
Implements a 2D median filter for images.
Definition: Median.hh:39
float _MinValue
Definition: Median.hh:163
base class for simple n-&gt;n filter implementations
Definition: FilterNToN.hh:43
void SetSize(int newsize, int secondsize=-1)
Definition: Median.hh:140
int _MedianSize
half win size of median, 1 means 3x3
Definition: Median.hh:159